. 22.2
okapproacheficsquare
it " ' (. 22.5); ,
lpatt roomgt2 |
L- (. . 22.5)
depth - N legal checkmove rookmove nomove kingdiagf irst |
(room)
depth = N
,
,
S]
V
rs
. 22.5. L : ) (, , , ); , ; ) L-
( ), ( ). . , ( ) . , . newroomsmaller, , (. . 22.4). , " " (show[ Pos)) 22.6.
22.6. " " % " "
i Side..Wx: Wy..RK: Ry..Bx: By..Depth
II. Prolog
Side - , ['W - Wx, Wy - X Y Rx, Ry - X Y , By - X Y Depth -
, ''
}
%
side (Side.._, Side). % Side - ,
wk(_.,KK.._, WK).
wr(__.WR.._, WR). t
(._. ^. _. ,. _, ), %
depthf _.._.._.._..Depth, Depth). %
resetdeptht S..W..R....D, S..W..R.... ). %
%
- |
% % |
n(N, N1)
|
|
(HI is + 1; HI 15 - 1|,
in(N1). in[N):-
% , % , % , i , |
N > , N < 9. diagngb(X: Y, XI: Yl):-
n(X, XI), n(Y, YD. verngb(X: Y, X: Yl):-
n(Y, Yl). borngb(X: Y, XI: Y):-
n{ X, XI). ngb(S, SI):-
diagngbl S, SI);
horngb(S, SI);
verngbl S, SI). end_of_game(Pos>:-
mate[ Pos).
%
% move! MoveConstr, Pos, Move, HewPos):
%
move(depth < Max, Pos, Hove, Posl):-depth! Pos, D), D < Max,!.
move (depth D, Pos, Move, Posl):-depth{ Pos, D>,!.
move(kingdiagfirst, W..W..R..B..D, W-Wl, b..Wl..R..B..Dl):-Dl is D + 1,
ngb[ W, Wl), % ngb
not ngb{ Wl, S), %
Wl \== R. %
roove(rookmove, W..W..RK: Ry..B..D, Rx Dl is D + 1, coord! I),
(R = Rx: I; R = I: R.y), R \~~ Rx: Ry, not inway(Rx: Ry, W, R).
: Ry-R, b..W..R..B..Dl):-
t 1 %
i
: - |
move[ cbeckmove, Pos, R-Rx: Ry, Posl) wr(Pos, R), bk[ Pos, Bx: By),
% Ry, Posl). |
(Rx - ; Ry = By), move(rookreove, Pos, R-R
22.
rookmovej, |
B-Bl, w.-W..K,,B1.,D1) |
move(legal, w..P, M, PI):-(MC - kingdiagfirst; MC = movef MC, w..P, M, PI}.
move! legal, b..W..R.. B..D, Dl is D + 1, ngbl B, Bl), not check(w.,W..R..B1..D1)
: -
legalmove[ Pos, Move, Posl):-move! legal, , Move, Posl}.
check(_.-W..Rx:Ry..Bx:By.._): - ngb(W, Bx: By!;
(Rx - Bh; Ry = By], Rx: Ry \== Bx: By, not inwayl Rx: Ry, W, Bx: By).
inwayt S, SI, SI):-!.
% %
inwayt XI |
! |
, 2: Y, : Y)
ordered! X1E X2, )
: -
inwayl X: Y 1, X: Y2, X: Y3): -ordered! Yl, Y2, Y3).
ordered! N1, N2, N3):-N1 < N2, N2 < ; N3 < N2, N2 < HI.
coord(l). coord(21 coord(5). coord(6) % true[ Pos). themtomovel b.._). |
coord(3). coord it). coord(7). coord[8).
,
mate(Pos): -
side[ Pos, b),
_). |
check (Pos),
not legalmovef Pos, stalemate! Posl:-
side[ Pos, b),
not check(Pos),
_, _) -RootPos) |
: - |
not legalmove[ Pos, newroomsmallerf Pos,
room(Pos, Room},
room! RootPos, RootRoom),
: - |
Room < RootRoom. rookexposed [ Side..W..R..B.. _
distf W, R, Dl),
dist(B, R, D2), [Side = w,!, Dl > D2 + 1
Side = b,!, Dl > D2).
-
okapproachedcsguaref Pos, RootPos} okcsguaremdist(Pos, Dl), okcsguaremdist(RootPos, D2), Dl < D2.
okcsguaremdistl Pos, Mdist)
WK
i |
- |
wk[ Pos, WK), (Pos, CS), manhdistf W<, CS, Mdist). rookdivides(_.-WK: Hy..Rx
Ry..Bx: By..)
II. Prolog
% L- : - |
orcteredt Vx, Rx, Bx),!;
ordered! Wy, Ry, By). lpatt(_..W..R..B.._):-
manhdist(W, B, 2),
roanhdistlR, B, 3). Okorndle(_..W..R.._, _..Wl. -Rl.._)
|
|
dist(W, R, DJ,
dist[ wi, Rl, Dl),
D -< Dl. roomgt2 (Pos): -room(Pos, Room], Roam > 2.
our_king_edge(_..X: Y.._):- %
(X -l,!; X = 8, \ / Y - 1,!; Y = 8). their_king_edge[_..W..R..X: Y.._):- %
[- 1,!;= 8,!; Y - 1,!; Y = ).
kings_close(}:- *"
wk[ Pos, WK), bk(Pos, BK),
dist [ WK, BK, D),
% i * % |
D < 4. rooklost(_..W..B..B.._). rooklost(b..N.-R.,B._):-
ngb(, ),
not ngb(w, R). dist (X: Y, XI: 1 D):-
absdiff(X, XI, Dx),
absdifft Y, Yl, Dy),
max(Dx, Dy, D). absdiff [ A, B, D):-
A > B,!, D is A - B;
D is - A, max[ , , ):-
A > = ,!, M = A;
K = .
manhdist(X: Y, XI: Yl, D>: - %
absdifft X, XI, Dx),
absdifft Y, Yl, Dy],
D is Dx + Dy.
room! Pos, Room):- % ,
wr(POS, Rx: Ry),
bk(Pos, Bx: By), (Bx < Rx, SideX is Rx - 1; Bx > Rx, SideX is - Rx), (By < Ry, SideY is Ry - 1; By > Ry, SideY is 8 - Ry),
Room is SideX SideY,!
Room is 64. %
cs(_..W..Rx: Ry..Bx: .._, : ):- t " "
[ Bx < Rx,!, is Rx - 1; is Rx + 1),
[ < Ry,!, is Ry - 1; is Ry + 1).
%
show! Pos]:-nl,
coord! Y), nl, coord(X),
writepiece(X: , ), fail.
show(Pos):-
side(Pos, S), depth(Pos, D),
nl, write ('Side= '), write (S),
write! 'Depths '), write (D), nl. writepiece(Sguare, Pos):-
wk(Pos, Sguare),!, write! '');
22.
wr (Eos, Square),!, write('R'); bk(Pos, Square),!, write(' '); write! '. ') showmovet Move}:-nl, write I Move), nl.
, , , . 22.4. (. . 22.4), ( , , ). - , "", "", "" .., - 1, 2, 3 .. ( - , w - ), - ( - , R - ). , " 7" : , "" 7.
,.. 7 d5 7 5 7 WR 7 HR 6 WK 5 7 WK 8 WK 7 7 W R 8 "WB 6
. , , , , , , " "? [13] , , , 22.5, .
, , , , ? , . , ( ) 16 . , , , 50. , 50 : , " ", 50 ; .
|
|
, " ", AL0 ( ) .
AND/OR. AND/OR.
II. Prolog
,
.
.
.
-. -- , , -- .
-- : , , .
. , , . Advice Language, .
: --, Advice Language " '7.
:
, ;
;
, ;
, ;
--;
, , ;
;
Advice Language;
, , , .