%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% parallelknightthrough
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(white)
role(black)
base(cell(B,X,Y,R)) :- board(B) & file(X) & rank(Y) & role(R)
base(played(B)) :- board(B)
base(step(1))
base(step(N)) :- succ(M,N)
base(control(R)) :- role(R)
action(move(B,X1,Y1,X2,Y2)) :- board(B) & knightmove(X1,Y1,X2,Y2)
action(tick)
board(a)
board(b)
board(c)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(cell(a,a,1,white))
init(cell(a,b,1,white))
init(cell(a,c,1,white))
init(cell(a,a,2,white))
init(cell(a,b,2,white))
init(cell(a,c,2,white))
init(cell(a,a,7,black))
init(cell(a,b,7,black))
init(cell(a,c,7,black))
init(cell(a,a,8,black))
init(cell(a,b,8,black))
init(cell(a,c,8,black))
init(cell(b,a,1,white))
init(cell(b,b,1,white))
init(cell(b,c,1,white))
init(cell(b,a,2,white))
init(cell(b,b,2,white))
init(cell(b,c,2,white))
init(cell(b,a,7,black))
init(cell(b,b,7,black))
init(cell(b,c,7,black))
init(cell(b,a,8,black))
init(cell(b,b,8,black))
init(cell(b,c,8,black))
init(cell(c,a,1,white))
init(cell(c,b,1,white))
init(cell(c,c,1,white))
init(cell(c,a,2,white))
init(cell(c,b,2,white))
init(cell(c,c,2,white))
init(cell(c,a,7,black))
init(cell(c,b,7,black))
init(cell(c,c,7,black))
init(cell(c,a,8,black))
init(cell(c,b,8,black))
init(cell(c,c,8,black))
init(step(1))
init(control(white))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(move(B,X1,Y1,X2,Y2)) :-
control(white) &
cell(B,X1,Y1,white) &
~played(B) &
whiteknightmove(X1,Y1,X2,Y2) &
~cell(B,X2,Y2,white)
legal(move(B,X1,Y1,X2,Y2)) :-
control(black) &
cell(B,X1,Y1,black) &
~played(B) &
blackknightmove(X1,Y1,X2,Y2) &
~cell(B,X2,Y2,black)
legal(tick)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
move(B,X1,Y1,X2,Y2) :: cell(B,X1,Y1,R) ==> ~cell(B,X1,Y1,R) & cell(B,X2,Y2,R)
move(B,X1,Y1,X2,Y2) :: cell(B,X2,Y2,R) ==> ~cell(B,X2,Y2,R)
move(B,X1,Y1,X2,Y2) :: played(B)
tick :: ~played(a) & ~played(b) & ~played(c)
tick :: step(M) & succ(M,N) ==> ~step(M) & step(N)
tick :: control(white) ==> ~control(white) & control(black)
tick :: control(black) ==> ~control(black) & control(white)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(white,100) :- cell(a,X,8,white)
goal(black,100) :- cell(c,X,1,black)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- cell(a,X,8,white)
terminal :- cell(c,X,1,black)
terminal :- step(21)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Views
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
whiteknightmove(X1,Y1,X2,Y2) :- skipfile(X1,X2) & nextrank(Y1,Y2)
whiteknightmove(X1,Y1,X2,Y2) :- skipfile(X2,X1) & nextrank(Y1,Y2)
whiteknightmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & skiprank(Y1,Y2)
whiteknightmove(X1,Y1,X2,Y2) :- nextfile(X2,X1) & skiprank(Y1,Y2)
blackknightmove(X1,Y1,X2,Y2) :- skipfile(X1,X2) & nextrank(Y2,Y1)
blackknightmove(X1,Y1,X2,Y2) :- skipfile(X2,X1) & nextrank(Y2,Y1)
blackknightmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & skiprank(Y2,Y1)
blackknightmove(X1,Y1,X2,Y2) :- nextfile(X2,X1) & skiprank(Y2,Y1)
knightmove(X1,Y1,X2,Y2) :- whiteknightmove(X1,Y1,X2,Y2)
knightmove(X1,Y1,X2,Y2) :- blackknightmove(X1,Y1,X2,Y2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Facts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
file(a)
file(b)
file(c)
rank(1)
rank(2)
rank(3)
rank(4)
rank(5)
rank(6)
rank(7)
rank(8)
nextrank(1,2)
nextrank(2,3)
nextrank(3,4)
nextrank(4,5)
nextrank(5,6)
nextrank(6,7)
nextrank(7,8)
nextfile(a,b)
nextfile(b,c)
skiprank(1,3)
skiprank(2,4)
skiprank(3,5)
skiprank(4,6)
skiprank(5,7)
skiprank(6,8)
skipfile(a,c)
succ(1,2)
succ(2,3)
succ(3,4)
succ(4,5)
succ(5,6)
succ(6,7)
succ(7,8)
succ(8,9)
succ(9,10)
succ(10,11)
succ(11,12)
succ(12,13)
succ(13,14)
succ(14,15)
succ(15,16)
succ(16,17)
succ(17,18)
succ(18,19)
succ(19,20)
succ(20,21)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%