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

evmhod:-pl(kletka(pole(X,Y),I)),myprint,cursor(15,10),writef("   "),

        cursor(16,10),writef("   "),

        cursor(15,10),writef("Computer turn"),

        cursor(16,10),readint(_),hod_think.

evmhod:-myprint,cursor(15,10),writef("   "),

        cursor(16,10),writef("   "),

        cursor(15,10),writef("Computer turn"),

        cursor(16,10),readint(_),hod_rand.

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

% мой ход

hod_my(X,Y):-kl(kletka(pole(X,Y),0)),

            retract(kl(kletka(pole(X,Y),_)),pole),   % промах

            assert(kl(kletka(pole(X,Y),5)),pole).

hod_my(X,Y):-kl(kletka(pole(X,Y),-1)),XA=X-1,XB=X+1,

            YA=Y-1,YB=Y+1,         % убийство однопалубного

            change(X,Y,6),change(X,YA,5),change(X,YB,5),

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

            change(XB,Y,5),change(XB,YA,5),change(XB,YB,5),myhod.

hod_my(X,Y):-kl(kletka(pole(X,Y),-2)),change(X,Y,2),kill(X,Y,2),myhod. % ранен

hod_my(X,Y):-kl(kletka(pole(X,Y),-3)),change(X,Y,3),kill(X,Y,3),myhod.

hod_my(X,Y):-kl(kletka(pole(X,Y),-4)),change(X,Y,4),kill(X,Y,4),myhod.

% в клетке с той же координатой x ранение - корабль убит 

kill(X,Y,2):-kl(kletka(pole(X,YY),2)),min(Y,YY,Z),max(Y,YY,ZZ),Y<>YY,

             XA=X+1,XB=X-1,YA=ZZ+1,YB=Z-1,

             change(X,Y,7),change(XA,Y,5),change(XB,Y,5),

             change(X,YY,7),change(XA,YY,5),change(XB,YY,5),

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

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

% в клетке с той же координатой y ранение - корабль убит 

kill(X,Y,2):-kl(kletka(pole(XX,Y),2)),min(X,XX,Z),max(X,XX,ZZ),X<>XX,

             XA=ZZ+1,XB=Z-1,YA=Y+1,YB=Y-1,

             change(X,Y,7),change(X,YA,5),change(X,YB,5),

             change(XX,Y,7),change(XX,YA,5),change(XX,YB,5),

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

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

% в клетке с той же координатой x ранение - корабль убит 

kill(X,Y,3):-kl(kletka(pole(X,YY),3)),kl(kletka(pole(X,YYY),3)),

             Y<>YY,Y<>YYY,YY<>YYY,

             min(Y,YY,B),min(B,YYY,Z),max(Y,YY,BB),max(BB,YYY,ZZ),

             XA=X+1,XB=X-1,YA=ZZ+1,YB=Z-1,

             change(X,Y,8),change(XA,Y,5),change(XB,Y,5),

             change(X,YY,8),change(XA,YY,5),change(XB,YY,5),

             change(X,YYY,8),change(XA,YYY,5),change(XB,YYY,5),

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

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

% в клетке с той же координатой y ранение - корабль убит 

kill(X,Y,3):-kl(kletka(pole(XX,Y),3)),kl(kletka(pole(XXX,Y),3)),

             X<>XX,X<>XXX,XX<>XXX,

             min(X,XX,B),min(B,XXX,Z),max(X,XX,BB),max(BB,XXX,ZZ),

             XA=ZZ+1,XB=Z-1,YA=Y+1,YB=Y-1,

             change(X,Y,8),change(X,YA,5),change(X,YB,5),

             change(XX,Y,8),change(XX,YA,5),change(XX,YB,5),

             change(XXX,Y,8),change(XXX,YA,5),change(XXX,YB,5),

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

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

% в клетке с той же координатой x ранение - корабль убит 

kill(X,Y,4):-kl(kletka(pole(X,YY),4)),kl(kletka(pole(X,YYY),4)),

             kl(kletka(pole(X,YYYY),4)),

             Y<>YY,Y<>YYY,Y<>YYYY,YY<>YYY,YY<>YYYY,YYY<>YYYY,

             min(Y,YY,B),min(B,YYY,C),min(C,YYYY,Z),

             max(Y,YY,BB),max(BB,YYY,CC),max(CC,YYYY,ZZ),

             XA=X+1,XB=X-1,YA=ZZ+1,YB=Z-1,

             change(X,Y,9),change(XA,Y,5),change(XB,Y,5),

             change(X,YY,9),change(XA,YY,5),change(XB,YY,5),

             change(X,YYY,9),change(XA,YYY,5),change(XB,YYY,5),

             change(X,YYYY,9),change(XA,YYYY,5),change(XB,YYYY,5),

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

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