%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% parallelhunter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(left)
role(right)
base(cell(R,M,N,P)) :- role(R) & row(M) & col(N) & piece(P)
base(captures(R,M)) :- role(R) & scoremap(M,N)
base(played(R)) :- role(R)
base(step(N)) :- succ(M,N)
base(control(left))
base(control(right))
action(move(R,M1,N1,M2,N2)) :- role(R) & row(M1) & col(N1) & knightmove(M1,N1,M2,N2)
action(tick)
row(1)
row(2)
row(3)
row(4)
row(5)
col(1)
col(2)
col(3)
piece(knight)
piece(pawn)
piece(blank)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(cell(left,1,1,knight))
init(cell(left,1,2,pawn))
init(cell(left,1,3,pawn))
init(cell(left,2,1,pawn))
init(cell(left,2,2,pawn))
init(cell(left,2,3,pawn))
init(cell(left,3,1,pawn))
init(cell(left,3,2,pawn))
init(cell(left,3,3,pawn))
init(cell(left,4,1,pawn))
init(cell(left,4,2,pawn))
init(cell(left,4,3,pawn))
init(cell(left,5,1,pawn))
init(cell(left,5,2,pawn))
init(cell(left,5,3,pawn))
init(cell(right,1,1,knight))
init(cell(right,1,2,pawn))
init(cell(right,1,3,pawn))
init(cell(right,2,1,pawn))
init(cell(right,2,2,pawn))
init(cell(right,2,3,pawn))
init(cell(right,3,1,pawn))
init(cell(right,3,2,pawn))
init(cell(right,3,3,pawn))
init(cell(right,4,1,pawn))
init(cell(right,4,2,pawn))
init(cell(right,4,3,pawn))
init(cell(right,5,1,pawn))
init(cell(right,5,2,pawn))
init(cell(right,5,3,pawn))
init(captures(left,0))
init(captures(right,0))
init(step(1))
init(control(left))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(move(R,M1,N1,M2,N2)) :-
control(R) & ~played(R) &
cell(R,M1,N1,knight) &
knightmove(M1,N1,M2,N2)
legal(tick)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
move(R,M1,N1,M2,N2) :: ~cell(R,M2,N2,blank) & ~cell(R,M2,N2,pawn) & cell(R,M2,N2,knight)
move(R,M1,N1,M2,N2) :: ~cell(R,M1,N1,knight) & cell(R,M1,N1,blank)
move(R,M1,N1,M2,N2) ::
cell(R,M2,N2,pawn) & captures(R,Old) & succ(Old,New)
==> ~captures(R,Old) & captures(R,New)
move(R,M1,N1,M2,N2) :: played(R)
tick :: ~played(left) & ~played(right)
tick :: step(M) & succ(M,N) ==> ~step(M) & step(N)
tick :: control(left) ==> ~control(left) & control(right)
tick :: control(right) ==> ~control(right) & control(left)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(R,Goal) :- captures(R,Count) & scoremap(Count,Goal)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- step(33)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Views
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
knightmove(M1,N1,M2,N2) :- add1row(M1,M2) & add2col(N1,N2)
knightmove(M1,N1,M2,N2) :- add1row(M1,M2) & add2col(N2,N1)
knightmove(M1,N1,M2,N2) :- add1row(M2,M1) & add2col(N1,N2)
knightmove(M1,N1,M2,N2) :- add1row(M2,M1) & add2col(N2,N1)
knightmove(M1,N1,M2,N2) :- add2row(M1,M2) & add1col(N1,N2)
knightmove(M1,N1,M2,N2) :- add2row(M1,M2) & add1col(N2,N1)
knightmove(M1,N1,M2,N2) :- add2row(M2,M1) & add1col(N1,N2)
knightmove(M1,N1,M2,N2) :- add2row(M2,M1) & add1col(N2,N1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Facts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
succ(0,1)
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)
succ(21,22)
succ(22,23)
succ(23,24)
succ(24,25)
succ(25,26)
succ(26,27)
succ(27,28)
succ(28,29)
succ(29,30)
succ(30,31)
succ(31,32)
succ(31,33)
add1row(1,2)
add1row(2,3)
add1row(3,4)
add1row(4,5)
add2row(1,3)
add2row(2,4)
add2row(3,5)
add1col(1,2)
add1col(2,3)
add2col(1,3)
scoremap(0,0)
scoremap(1,1)
scoremap(2,3)
scoremap(3,7)
scoremap(4,11)
scoremap(5,16)
scoremap(6,22)
scoremap(7,29)
scoremap(8,37)
scoremap(9,45)
scoremap(10,54)
scoremap(11,64)
scoremap(12,75)
scoremap(13,87)
scoremap(14,100)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%