%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% alquerque
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(red)
role(black)
base(cell(M,N,Mark)) :- index(M) & index(N) & mark(Mark)
base(score(Role,0)) :- role(Role)
base(score(Role,N)) :- role(Role) & incr(M,N)
base(control(Role)) :- role(Role)
base(step(1)) :- true
base(step(N)) :- succ(M,N)
base(control(red))
base(control(black))
action(move(U,V,X,Y)) :- doublet(U,V,X,Y)
action(jump(U,V,W,X,Y,Z)) :- triplet(U,V,W,X,Y,Z)
action(kerchunk)
index(1)
index(2)
index(3)
index(4)
index(5)
mark(black)
mark(red)
mark(blank)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(cell(1,1,black))
init(cell(1,2,black))
init(cell(1,3,black))
init(cell(1,4,black))
init(cell(1,5,black))
init(cell(2,1,black))
init(cell(2,2,black))
init(cell(2,3,black))
init(cell(2,4,black))
init(cell(2,5,black))
init(cell(3,1,blank))
init(cell(3,2,blank))
init(cell(3,3,blank))
init(cell(3,4,blank))
init(cell(3,5,blank))
init(cell(4,1,red))
init(cell(4,2,red))
init(cell(4,3,red))
init(cell(4,4,red))
init(cell(4,5,red))
init(cell(5,1,red))
init(cell(5,2,red))
init(cell(5,3,red))
init(cell(5,4,red))
init(cell(5,5,red))
init(score(red,0))
init(score(black,0))
init(control(red))
init(step(1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(Move) :- goodmove(Move)
goodmove(move(U,V,X,Y)) :-
control(Role) &
cell(U,V,Role) &
doublet(U,V,X,Y) &
cell(X,Y,blank)
goodmove(jump(U,V,W,X,Y,Z)) :-
control(red) &
cell(U,V,red) &
triplet(U,V,W,X,Y,Z) &
cell(W,X,black) &
cell(Y,Z,blank)
goodmove(jump(U,V,W,X,Y,Z)) :-
control(black) &
cell(U,V,black) &
triplet(U,V,W,X,Y,Z) &
cell(W,X,red) &
cell(Y,Z,blank)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
move(U,V,X,Y) :: cell(U,V,Role) ==> ~cell(U,V,Role) & cell(U,V,blank)
move(U,V,X,Y) :: cell(U,V,Role) ==> ~cell(X,Y,blank) & cell(X,Y,Role)
move(U,V,X,Y) :: kerchunk
jump(U,V,W,X,Y,Z) :: cell(U,V,Role) ==> ~cell(U,V,Role) & cell(U,V,blank)
jump(U,V,W,X,Y,Z) :: cell(W,X,Role) ==> ~cell(W,X,Role) & cell(W,X,blank)
jump(U,V,W,X,Y,Z) :: cell(U,V,Role) ==> ~cell(Y,Z,blank) & cell(Y,Z,Role)
jump(U,V,W,X,Y,Z) :: control(Role) & score(Role,M) & incr(M,N)
==> ~score(Role,M) & score(Role,N)
jump(U,V,W,X,Y,Z) :: kerchunk
kerchunk :: control(black) ==> ~control(black) & control(red)
kerchunk :: control(red) ==> ~control(red) & control(black)
kerchunk :: step(M) & succ(M,N) ==> ~step(M) & step(N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(Role,N) :- score(Role,N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- score(Role,100)
terminal :- ~legalmove
terminal :- step(30)
legalmove :- goodmove(Move)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Views
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
doublet(U,V,X,Y) :- horizontal(U,V,X,Y)
doublet(U,V,X,Y) :- horizontal(X,Y,U,V)
doublet(U,V,X,Y) :- vertical(U,V,X,Y)
doublet(U,V,X,Y) :- vertical(X,Y,U,V)
doublet(U,V,X,Y) :- slash(U,V,X,Y)
doublet(U,V,X,Y) :- slash(X,Y,U,V)
doublet(U,V,X,Y) :- backslash(U,V,X,Y)
doublet(U,V,X,Y) :- backslash(X,Y,U,V)
triplet(U,V,W,X,Y,Z) :- horizontal(U,V,W,X) & horizontal(W,X,Y,Z)
triplet(U,V,W,X,Y,Z) :- horizontal(Y,Z,W,X) & horizontal(W,X,U,V)
triplet(U,V,W,X,Y,Z) :- vertical(U,V,W,X) & vertical(W,X,Y,Z)
triplet(U,V,W,X,Y,Z) :- vertical(Y,Z,W,X) & vertical(W,X,U,V)
triplet(U,V,W,X,Y,Z) :- slash(U,V,W,X) & slash(W,X,Y,Z)
triplet(U,V,W,X,Y,Z) :- slash(Y,Z,W,X) & slash(W,X,U,V)
triplet(U,V,W,X,Y,Z) :- backslash(U,V,W,X) & backslash(W,X,Y,Z)
triplet(U,V,W,X,Y,Z) :- backslash(Y,Z,W,X) & backslash(W,X,U,V)
horizontal(U,V,X,V) :- nex(U,X) & index(V)
vertical(U,V,U,Y) :- nex(V,Y) & index(U)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Facts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
slash(3,1,2,2)
slash(2,2,1,3)
slash(5,1,4,2)
slash(4,2,3,3)
slash(3,3,2,4)
slash(2,4,1,5)
slash(5,3,4,4)
slash(4,4,3,5)
backslash(3,1,4,2)
backslash(4,2,5,3)
backslash(1,1,2,2)
backslash(2,2,3,3)
backslash(3,3,4,4)
backslash(4,4,5,5)
backslash(1,3,2,4)
backslash(2,4,3,5)
nex(1,2)
nex(2,3)
nex(3,4)
nex(4,5)
incr(0,10)
incr(10,20)
incr(20,30)
incr(30,40)
incr(40,50)
incr(50,60)
incr(60,70)
incr(70,80)
incr(80,90)
incr(90,100)
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)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%