%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% kono
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% 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(step(1))
base(step(N)) :- succ(M,N)
base(control(Role)) :- role(Role)
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)
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(2,1,black))
init(cell(2,2,black))
init(cell(2,3,black))
init(cell(2,4,black))
init(cell(3,1,red))
init(cell(3,2,red))
init(cell(3,3,red))
init(cell(3,4,red))
init(cell(4,1,red))
init(cell(4,2,red))
init(cell(4,3,red))
init(cell(4,4,red))
init(score(red,0))
init(score(black,0))
init(step(1))
init(control(red))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(move(U,V,X,Y)) :- control(R) & cell(U,V,R) & doublet(U,V,X,Y) & cell(X,Y,blank)
legal(jump(U,V,W,X,Y,Z)) :- control(red) & cell(U,V,red) & triplet(U,V,W,X,Y,Z) & cell(W,X,red) & cell(Y,Z,black)
legal(jump(U,V,W,X,Y,Z)) :- control(black) & cell(U,V,black) & triplet(U,V,W,X,Y,Z) & cell(W,X,black) & cell(Y,Z,red)
legal(kerchunk)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
move(U,V,X,Y) :: cell(U,V,R) ==> ~cell(U,V,R) & cell(U,V,blank)
move(U,V,X,Y) :: cell(U,V,R) ==> ~cell(X,Y,blank) & cell(X,Y,R)
move(U,V,X,Y) :: kerchunk
jump(U,V,W,X,Y,Z) :: cell(U,V,R) ==> ~cell(U,V,R) & cell(U,V,blank)
jump(U,V,W,X,Y,Z) :: cell(U,V,R) & cell(Y,Z,S) ==> ~cell(Y,Z,S) & cell(Y,Z,R)
jump(U,V,W,X,Y,Z) :: cell(U,V,R) & score(R,M) & incr(M,N) ==> ~score(R,M) & score(R,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(R,N) :- score(R,N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- score(R,100)
terminal :- step(30)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% 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) :- nextspot(U,X) & index(V)
vertical(U,V,U,Y) :- nextspot(V,Y) & index(U)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Facts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
index(1)
index(2)
index(3)
index(4)
nextspot(1,2)
nextspot(2,3)
nextspot(3,4)
incr(0,12)
incr(12,25)
incr(25,37)
incr(37,50)
incr(50,62)
incr(62,75)
incr(75,87)
incr(87,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)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%