role(white)
role(black)
base(location(X,Y,Piece)) :- file(X) & rank(Y) & owns(Piece,Role)
base(capturecount(Role,N)) :- role(Role) & scoremap(N,S)
base(control(Role)) :- role(Role)
base(step(1))
base(step(N)) :- pp(M,N)
input(Role,move(U,V,X,Y)) :- role(Role) & horizontal(U,V,X,Y)
input(Role,move(U,V,X,Y)) :- role(Role) & horizontal(X,Y,U,V)
input(Role,move(U,V,X,Y)) :- role(Role) & vertical(U,V,X,Y)
input(Role,move(U,V,X,Y)) :- role(Role) & vertical(X,Y,U,V)
input(Role,move(U,V,X,Y)) :- role(Role) & northeast(U,V,X,Y)
input(Role,move(U,V,X,Y)) :- role(Role) & northeast(X,Y,U,V)
input(Role,move(U,V,X,Y)) :- role(Role) & southeast(U,V,X,Y)
input(Role,move(U,V,X,Y)) :- role(Role) & southeast(X,Y,U,V)
input(Role,move(U,V,X,Y)) :- role(Role) & knightmove(U,V,X,Y)
input(white,move(X,2,X,4)) :- file(X)
input(black,move(X,7,X,5)) :- file(X)
input(Role,noop) :- role(Role)
init(location(a,7,blackpawn))
init(location(b,7,blackpawn))
init(location(c,7,blackpawn))
init(location(d,7,blackpawn))
init(location(e,7,blackpawn))
init(location(f,7,blackpawn))
init(location(g,7,blackpawn))
init(location(h,7,blackpawn))
init(location(a,8,blackrook))
init(location(b,8,blackknight))
init(location(c,8,blackbishop))
init(location(d,8,blackqueen))
init(location(e,8,blackking))
init(location(f,8,blackbishop))
init(location(g,8,blackknight))
init(location(h,8,blackrook))
init(location(a,1,whiterook))
init(location(b,1,whiteknight))
init(location(c,1,whitebishop))
init(location(d,1,whitequeen))
init(location(e,1,whiteking))
init(location(f,1,whitebishop))
init(location(g,1,whiteknight))
init(location(h,1,whiterook))
init(location(a,2,whitepawn))
init(location(b,2,whitepawn))
init(location(c,2,whitepawn))
init(location(d,2,whitepawn))
init(location(e,2,whitepawn))
init(location(f,2,whitepawn))
init(location(g,2,whitepawn))
init(location(h,2,whitepawn))
init(capturecount(white,0))
init(capturecount(black,0))
init(control(white))
init(step(1))
legal(Player,move(X1,Y1,X2,Y2)) :- true(control(Player)) & true(location(X1,Y1,Piece)) & owns(Piece,Player) & validmove(Piece,X1,Y1,X2,Y2) & ~celloccupiedby(X2,Y2,Player)
legal(white,noop) :- true(control(black))
legal(black,noop) :- true(control(white))
next(location(X2,Y2,Piece)) :- does(Player,move(X1,Y1,X2,Y2)) & true(location(X1,Y1,Piece)) & ~type(Piece,pawn)
next(location(X2,Y2,Piece)) :- does(white,move(X1,Y1,X2,Y2)) & true(location(X1,Y1,Piece)) & type(Piece,pawn) & distinct(Y2,8)
next(location(X2,8,whitequeen)) :- does(white,move(X1,Y1,X2,8)) & true(location(X1,Y1,Piece)) & type(Piece,pawn)
next(location(X2,Y2,Piece)) :- does(black,move(X1,Y1,X2,Y2)) & true(location(X1,Y1,Piece)) & type(Piece,pawn) & distinct(Y2,1)
next(location(X2,1,blackqueen)) :- does(black,move(X1,Y1,X2,1)) & true(location(X1,Y1,Piece)) & type(Piece,pawn)
next(location(X,Y,Piece)) :- does(Player,move(X1,Y1,X2,Y2)) & true(location(X,Y,Piece)) & distinct(f(X,Y),f(X1,Y1)) & distinct(f(X,Y),f(X2,Y2))
next(capturecount(Player,Count2)) :- does(Player,move(X1,Y1,X2,Y2)) & celloccupied(X2,Y2) & true(capturecount(Player,Count1)) & countplus(Count1,Count2)
next(capturecount(Player,Count)) :- does(Player,move(X1,Y1,X2,Y2)) & ~celloccupied(X2,Y2) & true(capturecount(Player,Count))
next(capturecount(Player,Count)) :- true(capturecount(Player,Count)) & ~true(control(Player))
next(control(white)) :- true(control(black))
next(control(black)) :- true(control(white))
next(step(Tpp)) :- true(step(T)) & pp(T,Tpp)
goal(Player,Goal) :- true(capturecount(Player,Count)) & scoremap(Count,Goal)
terminal :- role(Player) & ~haspiece(Player)
terminal :- role(Player) & ~haslegalmove(Player)
terminal :- true(step(40))
horizontal(X1,Y,X2,Y) :- nextfile(X1,X2) & rank(Y)
horizontal(X1,Y,X3,Y) :- nextfile(X1,X2) & horizontal(X2,Y,X3,Y)
vertical(X,Y1,X,Y2) :- nextrank(Y1,Y2) & file(X)
vertical(X,Y1,X,Y3) :- nextrank(Y1,Y2) & vertical(X,Y2,X,Y3)
northeast(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y1,Y2)
northeast(X1,Y1,X3,Y3) :- nextfile(X1,X2) & nextrank(Y1,Y2) & northeast(X2,Y2,X3,Y3)
southeast(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y2,Y1)
southeast(X1,Y1,X3,Y3) :- nextfile(X1,X2) & nextrank(Y2,Y1) & southeast(X2,Y2,X3,Y3)
validmove(whitepawn,X1,Y1,X2,Y2) :- whitepawnmove(X1,Y1,X2,Y2)
validmove(blackpawn,X1,Y1,X2,Y2) :- blackpawnmove(X1,Y1,X2,Y2)
validmove(Piece,X1,Y1,X2,Y2) :- type(Piece,rook) & rookmove(X1,Y1,X2,Y2)
validmove(Piece,X1,Y1,X2,Y2) :- type(Piece,knight) & knightmove(X1,Y1,X2,Y2)
validmove(Piece,X1,Y1,X2,Y2) :- type(Piece,bishop) & bishopmove(X1,Y1,X2,Y2)
validmove(Piece,X1,Y1,X2,Y2) :- type(Piece,queen) & queenmove(X1,Y1,X2,Y2)
validmove(Piece,X1,Y1,X2,Y2) :- type(Piece,king) & kingmove(X1,Y1,X2,Y2)
whitepawnmove(X,2,X,4) :- cellempty(X,3) & cellempty(X,4)
whitepawnmove(X,Y1,X,Y2) :- nextrank(Y1,Y2) & cellempty(X,Y2)
whitepawnmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y1,Y2) & celloccupiedby(X2,Y2,black)
whitepawnmove(X1,Y1,X2,Y2) :- nextfile(X2,X1) & nextrank(Y1,Y2) & celloccupiedby(X2,Y2,black)
blackpawnmove(X,7,X,5) :- cellempty(X,6) & cellempty(X,5)
blackpawnmove(X,Y1,X,Y2) :- nextrank(Y2,Y1) & cellempty(X,Y2)
blackpawnmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y2,Y1) & celloccupiedby(X2,Y2,white)
blackpawnmove(X1,Y1,X2,Y2) :- nextfile(X2,X1) & nextrank(Y2,Y1) & celloccupiedby(X2,Y2,white)
rookmove(X1,Y1,X2,Y2) :- horizontalmove(X1,Y1,X2,Y2)
rookmove(X1,Y1,X2,Y2) :- horizontalmove(X2,Y2,X1,Y1)
rookmove(X1,Y1,X2,Y2) :- verticalmove(X1,Y1,X2,Y2)
rookmove(X1,Y1,X2,Y2) :- verticalmove(X2,Y2,X1,Y1)
knightmove(X1,Y1,X2,Y2) :- skipfile(X1,X2) & nextrank(Y1,Y2)
knightmove(X1,Y1,X2,Y2) :- skipfile(X1,X2) & nextrank(Y2,Y1)
knightmove(X1,Y1,X2,Y2) :- skipfile(X2,X1) & nextrank(Y1,Y2)
knightmove(X1,Y1,X2,Y2) :- skipfile(X2,X1) & nextrank(Y2,Y1)
knightmove(X1,Y1,X2,Y2) :- skiprank(Y1,Y2) & nextfile(X1,X2)
knightmove(X1,Y1,X2,Y2) :- skiprank(Y1,Y2) & nextfile(X2,X1)
knightmove(X1,Y1,X2,Y2) :- skiprank(Y2,Y1) & nextfile(X1,X2)
knightmove(X1,Y1,X2,Y2) :- skiprank(Y2,Y1) & nextfile(X2,X1)
bishopmove(X1,Y1,X2,Y2) :- northeastmove(X1,Y1,X2,Y2)
bishopmove(X1,Y1,X2,Y2) :- northeastmove(X2,Y2,X1,Y1)
bishopmove(X1,Y1,X2,Y2) :- southeastmove(X1,Y1,X2,Y2)
bishopmove(X1,Y1,X2,Y2) :- southeastmove(X2,Y2,X1,Y1)
queenmove(X1,Y1,X2,Y2) :- rookmove(X1,Y1,X2,Y2)
queenmove(X1,Y1,X2,Y2) :- bishopmove(X1,Y1,X2,Y2)
kingmove(X1,Y,X2,Y) :- nextfile(X1,X2) & rank(Y)
kingmove(X1,Y,X2,Y) :- nextfile(X2,X1) & rank(Y)
kingmove(X,Y1,X,Y2) :- nextrank(Y1,Y2) & file(X)
kingmove(X,Y1,X,Y2) :- nextrank(Y2,Y1) & file(X)
kingmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y1,Y2)
kingmove(X1,Y1,X2,Y2) :- nextfile(X2,X1) & nextrank(Y1,Y2)
kingmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y2,Y1)
kingmove(X1,Y1,X2,Y2) :- nextfile(X2,X1) & nextrank(Y2,Y1)
horizontalmove(X1,Y,X2,Y) :- nextfile(X1,X2) & rank(Y)
horizontalmove(X1,Y,X3,Y) :- nextfile(X1,X2) & cellempty(X2,Y) & horizontalmove(X2,Y,X3,Y)
verticalmove(X,Y1,X,Y2) :- nextrank(Y1,Y2) & file(X)
verticalmove(X,Y1,X,Y3) :- nextrank(Y1,Y2) & cellempty(X,Y2) & verticalmove(X,Y2,X,Y3)
northeastmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y1,Y2)
northeastmove(X1,Y1,X3,Y3) :- nextfile(X1,X2) & nextrank(Y1,Y2) & cellempty(X2,Y2) & northeastmove(X2,Y2,X3,Y3)
southeastmove(X1,Y1,X2,Y2) :- nextfile(X1,X2) & nextrank(Y2,Y1)
southeastmove(X1,Y1,X3,Y3) :- nextfile(X1,X2) & nextrank(Y2,Y1) & cellempty(X2,Y2) & southeastmove(X2,Y2,X3,Y3)
haslegalmove(Player) :- true(location(X1,Y1,Piece)) & owns(Piece,Player) & validmove(Piece,X1,Y1,X2,Y2) & ~celloccupiedby(X2,Y2,Player)
haspiece(Player) :- true(location(X,Y,Piece)) & owns(Piece,Player)
celloccupied(X,Y) :- true(location(X,Y,Piece))
celloccupiedby(X,Y,Player) :- true(location(X,Y,Piece)) & owns(Piece,Player)
cellempty(X,Y) :- file(X) & rank(Y) & ~celloccupied(X,Y)
file(a)
file(b)
file(c)
file(d)
file(e)
file(f)
file(g)
file(h)
rank(1)
rank(2)
rank(3)
rank(4)
rank(5)
rank(6)
rank(7)
rank(8)
nextrank(1,2)
nextrank(2,3)
nextrank(3,4)
nextrank(4,5)
nextrank(5,6)
nextrank(6,7)
nextrank(7,8)
nextfile(a,b)
nextfile(b,c)
nextfile(c,d)
nextfile(d,e)
nextfile(e,f)
nextfile(f,g)
nextfile(g,h)
skiprank(1,3)
skiprank(2,4)
skiprank(3,5)
skiprank(4,6)
skiprank(5,7)
skiprank(6,8)
skipfile(a,c)
skipfile(b,d)
skipfile(c,e)
skipfile(d,f)
skipfile(e,g)
skipfile(f,h)
countplus(0,1)
countplus(1,2)
countplus(2,3)
countplus(3,4)
countplus(4,5)
countplus(5,6)
countplus(6,7)
countplus(7,8)
countplus(8,9)
countplus(9,10)
countplus(10,11)
countplus(11,12)
countplus(12,13)
countplus(13,14)
countplus(14,15)
countplus(15,16)
pp(1,2)
pp(2,3)
pp(3,4)
pp(4,5)
pp(5,6)
pp(6,7)
pp(7,8)
pp(8,9)
pp(9,10)
pp(10,11)
pp(11,12)
pp(12,13)
pp(13,14)
pp(14,15)
pp(15,16)
pp(16,17)
pp(17,18)
pp(18,19)
pp(19,20)
pp(20,21)
pp(21,22)
pp(22,23)
pp(23,24)
pp(24,25)
pp(25,26)
pp(26,27)
pp(27,28)
pp(28,29)
pp(29,30)
pp(30,31)
pp(31,32)
pp(32,33)
pp(33,34)
pp(34,35)
pp(35,36)
pp(36,37)
pp(37,38)
pp(38,39)
pp(39,40)
pp(40,41)
pp(41,42)
pp(42,43)
pp(43,44)
pp(44,45)
pp(45,46)
pp(46,47)
pp(47,48)
pp(48,49)
pp(49,50)
pp(50,51)
pp(51,52)
pp(52,53)
pp(53,54)
pp(54,55)
pp(55,56)
pp(56,57)
pp(57,58)
pp(58,59)
pp(59,60)
scoremap(0,0)
scoremap(1,6)
scoremap(2,12)
scoremap(3,18)
scoremap(4,24)
scoremap(5,30)
scoremap(6,36)
scoremap(7,42)
scoremap(8,48)
scoremap(9,54)
scoremap(10,60)
scoremap(11,66)
scoremap(12,72)
scoremap(13,79)
scoremap(14,86)
scoremap(15,93)
scoremap(16,100)
owns(whitepawn,white)
owns(whiterook,white)
owns(whiteknight,white)
owns(whitebishop,white)
owns(whitequeen,white)
owns(whiteking,white)
owns(blackpawn,black)
owns(blackrook,black)
owns(blackknight,black)
owns(blackbishop,black)
owns(blackqueen,black)
owns(blackking,black)
type(whitepawn,pawn)
type(whiterook,rook)
type(whiteknight,knight)
type(whitebishop,bishop)
type(whitequeen,queen)
type(whiteking,king)
type(blackpawn,pawn)
type(blackrook,rook)
type(blackknight,knight)
type(blackbishop,bishop)
type(blackqueen,queen)
type(blackking,king)
