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

             XX=X+1,XXX=X+2,XXXX=X+3,YA=Y+1,YB=Y-1,XA=X-1,XB=X+4,

             change(X,Y,-4),change(X,YA,0),change(X,YB,0),

             change(XX,Y,-4),change(XX,YA,0),change(XX,YB,0),

             change(XXX,Y,-4),change(XXX,YA,0),change(XXX,YB,0),

             change(XXXX,Y,-4),change(XXXX,YA,0),change(XXXX,YB,0),

             change(XA,Y,0),change(XA,YA,0),change(XA,YB,0),

             change(XB,Y,0),change(XB,YA,0),change(XB,YB,0).

add_four(1):-random(10,X),random(7,Y),

             YY=Y+1,YYY=Y+2,YYYY=Y+3,XA=X+1,XB=X-1,YA=Y-1,YB=Y+4,

             change(X,Y,-4),change(XA,Y,0),change(XB,Y,0),

             change(X,YY,-4),change(XA,YY,0),change(XB,YY,0),

             change(X,YYY,-4),change(XA,YYY,0),change(XB,YYY,0),

             change(X,YYYY,-4),change(XA,YYYY,0),change(XB,YYYY,0),

             change(X,YA,0),change(XA,YA,0),change(XB,YA,0),

             change(X,YB,0),change(XA,YB,0),change(XB,YB,0).

firstrand(X,Y,1,0,X,Y):-kl(kletka(pole(X,Y),10)),!.

firstrand(X,Y,1,0,XA,YA):-random(10,XB),random(10,YB),firstrand(XB,YB,1,0,XA,YA).

firstrand(X,Y,2,0,X,Y):-XX=X+1,kl(kletka(pole(X,Y),10)),kl(kletka(pole(XX,Y),10)),!.

firstrand(X,Y,2,0,XA,YA):-random(9,XB),random(10,YB),firstrand(XB,YB,2,0,XA,YA).

firstrand(X,Y,2,1,X,Y):-YY=Y+1,kl(kletka(pole(X,Y),10)),kl(kletka(pole(X,YY),10)),!.

firstrand(X,Y,2,1,XA,YA):-random(10,XB),random(9,YB),

                         firstrand(XB,YB,2,1,XA,YA).

firstrand(X,Y,3,0,X,Y):-XX=X+1,XXX=X+2,kl(kletka(pole(X,Y),10)),

                      kl(kletka(pole(XX,Y),10)),kl(kletka(pole(XXX,Y),10)),!.

firstrand(X,Y,3,0,XA,YA):-random(8,XB),random(10,YB),

                         firstrand(XB,YB,3,0,XA,YA).

firstrand(X,Y,3,1,X,Y):-YY=Y+1,YYY=Y+2,kl(kletka(pole(X,Y),10)),

                      kl(kletka(pole(X,YY),10)),kl(kletka(pole(XXX,Y),10)),!.

firstrand(X,Y,3,1,XA,YA):-random(10,XB),random(8,YB),

                         firstrand(XB,YB,3,1,XA,YA).

change(-1,_,_).

change(10,_,_).

change(_,-1,_).

change(_,10,_).

change(X,Y,I):-retract(kl(kletka(pole(X,Y),_)),pole),assert(kl(kletka(pole(X,Y),I)),pole).

% заполняем пустые клетки

add_empty1(10):-!.

add_empty1(Y):-add_empty2(0,Y),YY=Y+1,add_empty1(YY).

add_empty2(10,_):-!.

add_empty2(X,Y):-add_nil,XX=X+1,add_empty2(XX,Y).

add_nil:-retract(kl(kletka(pole(X,Y),10)),pole),assert(kl(kletka(pole(X,Y),0)),pole).

add_nil.

% какой символ выводить????

sim(X,'*'):-X<=0.

sim(5,'-').

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

% вывод поля противника на экран

print:-kl(kletka(pole(X,Y),I)),XX=X+3,YY=2*Y+6,cursor(XX,YY),sim(I,C),write(C),fail.

print.

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

% заполнение нашего поля

mybuild(0):-mybuild_empty1(15),

         myadd_one(0,15),myadd_one(0,17),myadd_one(0,19),myadd_one(0,21),

         myadd_two(2,15,1),myadd_two(2,18,1),myadd_two(2,21,1),

         myadd_three(4,15,0),myadd_three(4,17,0),

         myadd_four(4,19,0).

mybuild(1):-axis,mybuild_empty1(15),myprint,cursor(14,10),writef("4:"),

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

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

           cursor(15,14),readint(XA),cursor(16,14),readint(YA),

           cursor(17,14),readint(NA),

           YYA=YA+15,myadd_four(XA,YYA,NA),myprint,

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

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

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

           cursor(15,14),readint(XB),cursor(16,14),readint(YB),

           cursor(17,14),readint(NB),

           YYB=YB+15,myadd_three(XB,YYB,NB),myprint,

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

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

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

           cursor(15,14),readint(XC),cursor(16,14), readint(YC),