%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% chinook
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(red)
role(blue)
base(cell(F,R,red)) :- isaodd(F,R)
base(cell(F,R,blue)) :- isaeven(F,R)
base(cell(F,R),b) :- isaodd(F,R)
base(cell(F,R),b) :- isaeven(F,R)
base(score(W,0)) :- role(W)
base(score(W,N)) :- role(W) & scoreplus(M,N)
base(control(W)) :- role(W)
base(step(1))
base(step(N)) :- succ(M,N)
action(move(U,V,X,Y)) :- isaodd(U,V) & forward(U,V,X,Y)
action(move(X,Y,U,V)) :- isaeven(U,V) & forward(U,V,X,Y)
action(jump(U,V,C,D,X,Y)) :- isaodd(U,V) & jumpable(U,V,C,D,X,Y)
action(jump(X,Y,C,D,U,V)) :- isaeven(U,V) & jumpable(X,Y,C,D,U,V)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(cell(a,1,red))
init(cell(a,2,b))
init(cell(a,3,red))
init(cell(a,4,b))
init(cell(a,5,b))
init(cell(a,6,blue))
init(cell(a,7,b))
init(cell(a,8,blue))
init(cell(b,1,b))
init(cell(b,2,red))
init(cell(b,3,b))
init(cell(b,4,b))
init(cell(b,5,b))
init(cell(b,6,b))
init(cell(b,7,blue))
init(cell(b,8,b))
init(cell(c,1,red))
init(cell(c,2,b))
init(cell(c,3,red))
init(cell(c,4,b))
init(cell(c,5,b))
init(cell(c,6,blue))
init(cell(c,7,b))
init(cell(c,8,blue))
init(cell(d,1,b))
init(cell(d,2,red))
init(cell(d,3,b))
init(cell(d,4,b))
init(cell(d,5,b))
init(cell(d,6,b))
init(cell(d,7,blue))
init(cell(d,8,b))
init(score(red,0))
init(score(blue,0))
init(control(red))
init(step(1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(move(U,V,X,Y)) :-
control(red) &
cell(U,V,red) &
forward(U,V,X,Y) &
cell(X,Y,b)
legal(move(X,Y,U,V)) :-
control(blue) &
cell(X,Y,blue) &
forward(U,V,X,Y) &
cell(U,V,b)
legal(jump(U,V,C,D,X,Y)) :-
control(red) &
cell(U,V,red) &
jumpable(U,V,C,D,X,Y) &
cell(C,D,red) &
cell(X,Y,b)
legal(jump(X,Y,C,D,U,V)) :-
control(blue) &
cell(X,Y,blue) &
jumpable(U,V,C,D,X,Y) &
cell(C,D,blue) &
cell(U,V,b)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
move(U,V,X,Y) :: control(W) ==>
~cell(U,V,W) & ~cell(X,Y,b) & cell(U,V,b) & cell(X,Y,W) & kerchunk & update(W,U,V,X,Y)
jump(U,V,C,D,X,Y) :: control(W) ==>
~cell(U,V,W) & ~cell(X,Y,b) & cell(U,V,b) & cell(X,Y,W) & kerchunk & update(W,U,V,X,Y)
update(W,U,V,X,Y) ::
~home(W,U,V) & home(W,X,Y) & score(W,M) & scoreplus(M,N)
==> ~score(W,M) & score(W,N)
update(W,U,V,X,Y) ::
home(W,U,V) & ~home(W,X,Y) & score(W,N) & scoreplus(M,N)
==> ~score(W,N) & score(W,M)
kerchunk :: step(M) & succ(M,N) ==> ~step(M) & step(N)
kerchunk :: control(red) ==> ~control(red) & control(blue)
kerchunk :: control(blue) ==> ~control(blue) & control(red)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(red,Score) :- oddscore(red,Score)
goal(blue,Score) :- evenscore(blue,Score)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- score(Player,100)
terminal :- step(41)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Views
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
forward(U,V,X,Y) :- nextrank(V,Y) & nextfile(U,X)
forward(U,V,X,Y) :- nextrank(V,Y) & nextfile(X,U)
jumpable(U,V,C,D,X,Y) :- nextrank(V,D) & nextrank(D,Y) & nextfile(U,C) & nextfile(C,X)
jumpable(U,V,C,D,X,Y) :- nextrank(V,D) & nextrank(D,Y) & nextfile(X,C) & nextfile(C,U)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Facts
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nextrank(1,2)
nextrank(2,3)
nextrank(3,4)
nextrank(4,5)
nextrank(5,6)
nextrank(6,7)
nextrank(7,8)
nextrank(8,1)
nextfile(a,b)
nextfile(b,c)
nextfile(c,d)
nextfile(d,a)
isaodd(a,1)
isaeven(a,2)
isaodd(a,3)
isaeven(a,4)
isaodd(a,5)
isaeven(a,6)
isaodd(a,7)
isaeven(a,8)
isaeven(b,1)
isaodd(b,2)
isaeven(b,3)
isaodd(b,4)
isaeven(b,5)
isaodd(b,6)
isaeven(b,7)
isaodd(b,8)
isaodd(c,1)
isaeven(c,2)
isaodd(c,3)
isaeven(c,4)
isaodd(c,5)
isaeven(c,6)
isaodd(c,7)
isaeven(c,8)
isaeven(d,1)
isaodd(d,2)
isaeven(d,3)
isaodd(d,4)
isaeven(d,5)
isaodd(d,6)
isaeven(d,7)
isaodd(d,8)
home(red,a,7)
home(red,b,6)
home(red,b,8)
home(red,c,7)
home(red,d,6)
home(red,d,8)
home(blue,a,2)
home(blue,b,1)
home(blue,b,3)
home(blue,c,2)
home(blue,d,1)
home(blue,d,3)
scoreplus(0,16)
scoreplus(16,32)
scoreplus(32,48)
scoreplus(48,64)
scoreplus(64,80)
scoreplus(80,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)
succ(30,31)
succ(31,32)
succ(32,33)
succ(33,34)
succ(34,35)
succ(35,36)
succ(36,37)
succ(37,38)
succ(38,39)
succ(39,40)
succ(40,41)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%