role(red)
role(blue)
base(cell(X,Y,Color)) :- index(X) & index(Y) & role(Color)
base(control(Player)) :- role(Player)
input(Player,move(X,Y)) :- role(Player) & index(X) & index(Y)
input(Player,noop) :- role(Player)
init(cell(3,3,blue))
init(cell(3,4,red))
init(cell(4,3,red))
init(cell(4,4,blue))
init(control(red))
legal(Color,move(X,Y)) :- true(control(Color)) & playable(Color,X,Y)
legal(Color,noop) :- true(control(Color)) & ~playercanmove(Color)
legal(Color,noop) :- true(control(Other)) & opponent(Color,Other)
playercanmove(Color) :- playable(Color,X,Y)
playable(Color,X,Y) :- empty(X,Y) & opponent(Color,Other) & nextcellindir(X,Y,Dir,X2,Y2) & captureindir(Other,X2,Y2,Color,Dir)
captureindir(Other,X1,Y1,Color,Dir) :- true(cell(X1,Y1,Other)) & nextcellindir(X1,Y1,Dir,X2,Y2) & true(cell(X2,Y2,Color))
captureindir(Other,X1,Y1,Color,Dir) :- true(cell(X1,Y1,Other)) & nextcellindir(X1,Y1,Dir,X2,Y2) & captureindir(Other,X2,Y2,Color,Dir)
nextcellindir(X1,Y1,Dir,X2,Y2) :- dir(Dir,Xdelta,Ydelta) & add(X1,Xdelta,X2) & add(Y1,Ydelta,Y2)
next(cell(X,Y,Color)) :- does(Color,move(X,Y))
next(cell(X,Y,Color)) :- does(Color,move(U,V)) & affectedcell(Color,U,V,X,Y)
next(cell(X,Y,Color)) :- does(Color,move(U,V)) & true(cell(X,Y,Color))
next(cell(X,Y,Other)) :- does(Color,move(U,V)) & opponent(Color,Other) & true(cell(X,Y,Other)) & ~affectedcell(Color,U,V,X,Y)
next(cell(X,Y,Color)) :- does(red,noop) & does(blue,noop) & true(cell(X,Y,Color))
next(control(Other)) :- true(control(Color)) & opponent(Color,Other)
affectedcell(Color,U,V,X2,Y2) :- affecteddir(Color,U,V,Dir) & opponent(Color,Other) & nextcellindir(U,V,Dir,X1,Y1) & affectedcellindir(Other,X1,Y1,Dir,X2,Y2)
affecteddir(Color,U,V,Dir) :- nextcellindir(U,V,Dir,X,Y) & captureindir(Other,X,Y,Color,Dir)
affectedcellindir(Other,X1,Y1,Dir,X1,Y1) :- true(cell(X1,Y1,Other))
affectedcellindir(Other,X1,Y1,Dir,X3,Y3) :- true(cell(X1,Y1,Other)) & nextcellindir(X1,Y1,Dir,X2,Y2) & affectedcellindir(Other,X2,Y2,Dir,X3,Y3)
goal(Player,100) :- winner(Player)
goal(Player,0) :- winner(Opponent) & opponent(Player,Opponent)
goal(Player,50) :- role(Player) & ~winner(blue) & ~winner(red)
terminal :- ~playercanmove(blue) & ~playercanmove(red)
empty(X,Y) :- index(X) & index(Y) & ~occupied(X,Y)
occupied(X,Y) :- true(cell(X,Y,Anycolor))
winner(blue) :- totalcount(blue,Bluecount) & totalcount(red,Redcount) & lessthan(Redcount,Bluecount)
winner(red) :- totalcount(blue,Bluecount) & totalcount(red,Redcount) & lessthan(Bluecount,Redcount)
totalcount(Color,N6) :- addrow(Color,1,0,N1) & addrow(Color,2,N1,N2) & addrow(Color,3,N2,N3) & addrow(Color,4,N3,N4) & addrow(Color,5,N4,N5) & addrow(Color,6,N5,N6)
addrow(Color,Y,M,N6) :- addcell(Color,1,Y,M,N1) & addcell(Color,2,Y,N1,N2) & addcell(Color,3,Y,N2,N3) & addcell(Color,4,Y,N3,N4) & addcell(Color,5,Y,N4,N5) & addcell(Color,6,Y,N5,N6)
addcell(Color,X,Y,M,N) :- true(cell(X,Y,Color)) & succ(M,N)
addcell(Color,X,Y,N,N) :- index(X) & index(Y) & role(Color) & ~true(cell(X,Y,Color)) & succ(N,M)
lessthan(X,Y) :- succ(X,Y)
lessthan(X,Z) :- succ(X,Y) & lessthan(Y,Z)
opponent(blue,red)
opponent(red,blue)
oppdir(nw,se)
oppdir(ne,sw)
oppdir(se,nw)
oppdir(sw,ne)
oppdir(n,s)
oppdir(e,w)
oppdir(s,n)
oppdir(w,e)
dir(n,0,p1)
dir(s,0,n1)
dir(e,p1,0)
dir(w,n1,0)
dir(nw,n1,p1)
dir(ne,p1,p1)
dir(se,p1,n1)
dir(sw,n1,n1)
add(1,p1,2)
add(2,p1,3)
add(3,p1,4)
add(4,p1,5)
add(5,p1,6)
add(1,0,1)
add(2,0,2)
add(3,0,3)
add(4,0,4)
add(5,0,5)
add(6,0,6)
add(6,n1,5)
add(5,n1,4)
add(4,n1,3)
add(3,n1,2)
add(2,n1,1)
index(1)
index(2)
index(3)
index(4)
index(5)
index(6)
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(32,33)
succ(33,34)
succ(34,35)
succ(35,36)
succ(36,37)
