Разработка программы для игры в морской бой с игровым полем 10х10 позиций, страница 6

           cursor(17,14),readint(NC),        

           YYC=YC+15,myadd_three(XC,YYC,NC),myprint,

           cursor(14,10),writef("2:"),

           cursor(15,10),writef("X=    "),cursor(16,10),

           writef("Y=    "),cursor(17,10),writef("Vertical/Horizontal(0/1)=   "),

           cursor(15,14),readint(XD),cursor(16,14),

           readint(YD),cursor(17,14),readint(ND),

           YYD=YD+15,myadd_two(XD,YYD,ND),myprint,

           cursor(14,10),writef("2:"),

           cursor(15,10),writef("X=    "),cursor(16,10),

           writef("Y=    "),cursor(17,10),writef("Vertical/Horizontal(0/1)=   "),

           cursor(15,14),readint(XE),cursor(16,14),

           readint(YE),cursor(17,14),readint(NE),

           YYE=YE+15,myadd_two(XE,YYE,NE),myprint,mybuild1.

mybuild1:- cursor(14,10),writef("2:"), cursor(15,10),writef("X=    "),

           cursor(16,10),writef("Y=    "),cursor(17,10),

writef("Vertical/Horizontal(0/1)=   "), cursor(15,14),readint(XF),cursor(16,14),

           readint(YF),cursor(17,14),readint(NF),

           YYF=YF+15,myadd_two(XF,YYF,NF),myprint,

           cursor(17,10),writef("            "),

           cursor(14,10),writef("1:"),

           cursor(15,10),writef("X=    "),cursor(16,10),writef("Y=    "),

           cursor(15,14),readint(XG),cursor(16,14),readint(YG),

           YYG=YG+15,myadd_one(XG,YYG),myprint,

           cursor(17,10),writef("            "),

           cursor(14,10),writef("1:"),

           cursor(15,10),writef("X=    "),cursor(16,10),writef("Y=    "),

           cursor(15,14),readint(XH),cursor(16,14),readint(YH),

           YYH=YH+15,myadd_one(XH,YYH),myprint,

           cursor(17,10),writef("            "),

           cursor(14,10),writef("1:"),

           cursor(15,10),writef("X=    "),cursor(16,10),writef("Y=    "),

           cursor(15,14),readint(XI),cursor(16,14),readint(YI),

           YYI=YI+15,myadd_one(XI,YYI),myprint,

           cursor(17,10),writef("            "),

           cursor(14,10),writef("1:"),

           cursor(15,10),writef("X=    "),cursor(16,10),writef("Y=    "),

           cursor(15,14),readint(XJ),cursor(16,14),readint(YJ),

           YYJ=YJ+15,myadd_one(XJ,YYJ),myprint,cursor(14,10),

           writef("              ").

% заполнение пустого поля

mybuild_empty1(25):-!.

mybuild_empty1(Y):-mybuild_empty2(0,Y),YY=Y+1,mybuild_empty1(YY).

mybuild_empty2(10,_):-!.

mybuild_empty2(X,Y):-assert(mykl(kletka(pole(X,Y),0)),mypole),XX=X+1,mybuild_empty2(XX,Y).

% добавление нашего корабля (1 - горизонтальный, 0 - вертикальный)

myadd_one(X,Y):-mychange1([X],[Y],-1).

myadd_two(X,Y,0):-XX=X+1,mychange1([X,XX],[Y],-2).

myadd_two(X,Y,1):-YY=Y+1,mychange1([X],[Y,YY],-2).

myadd_three(X,Y,0):-XX=X+1,XXX=X+2,mychange1([X,XX,XXX],[Y],-3).

myadd_three(X,Y,1):-YY=Y+1,YYY=Y+2,mychange1([X],[Y,YY,YYY],-3).

myadd_four(X,Y,0):-XX=X+1,XXX=X+2,XXXX=X+3,mychange1([X,XX,XXX,XXXX],[Y],-4).

myadd_four(X,Y,1):-YY=Y+1,YYY=Y+2,YYYY=Y+3,mychange1([X],[Y,YY,YYY,YYYY],-4).

% добавление кораблей - списками

mychange1([],_,_):-!.

mychange1(_,[],_):-!.

mychange1([X],[Y|YY],I):-retract(mykl(kletka(pole(X,Y),_)),mypole),

                         assert(mykl(kletka(pole(X,Y),I)),

                         mypole),mychange1([X],YY,I).

mychange1([X|XX],[Y],I):-retract(mykl(kletka(pole(X,Y),_)),mypole),

                         assert(mykl(kletka(pole(X,Y),I)),mypole),

                         mychange1(XX,[Y],I).

% вывод нашего поля на экран

myprint:-mykl(kletka(pole(X,Y),I)),XX=X+3,YY=2*Y+2,cursor(XX,YY),

         mysim(I,C),write(C),fail.

myprint.

mysim(0,'*').

mysim(X,'0'):-X<0.

mysim(5,'-').

mysim(X,'X'):-X>0,X<>5.

%----------------------------------------------------------------------