role(white)
role(black)
base(location(X,Y,Piece)) :- file(X) & rank(Y) & type(Piece,Type)
base(color(Piece,Role)) :- type(Piece,Type) & role(Role)
base(control(Role)) :- role(Role)
base(strength(Role,M)) :- role(Role) & scoremap(M,N)
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,place(Piece,X,Y)) :- role(Role) & type(Piece,Type) & file(X) & rank(Y)
input(Role,noop) :- role(Role)
init(location(a,1,r1))
init(location(b,1,n1))
init(location(c,1,b1))
init(location(d,1,q1))
init(location(e,1,k1))
init(location(f,1,b2))
init(location(g,1,n2))
init(location(h,1,r2))
init(location(a,2,p1))
init(location(b,2,p2))
init(location(c,2,p3))
init(location(d,2,p4))
init(location(e,2,p5))
init(location(f,2,p6))
init(location(g,2,p7))
init(location(h,2,p8))
init(location(a,7,pa))
init(location(b,7,pb))
init(location(c,7,pc))
init(location(d,7,pd))
init(location(e,7,pe))
init(location(f,7,pf))
init(location(g,7,pg))
init(location(h,7,ph))
init(location(a,8,r3))
init(location(b,8,n3))
init(location(c,8,b3))
init(location(d,8,q2))
init(location(e,8,k2))
init(location(f,8,b4))
init(location(g,8,n4))
init(location(h,8,r4))
init(color(k1,white))
init(color(q1,white))
init(color(b1,white))
init(color(b2,white))
init(color(n1,white))
init(color(n2,white))
init(color(r1,white))
init(color(r2,white))
init(color(p1,white))
init(color(p2,white))
init(color(p3,white))
init(color(p4,white))
init(color(p5,white))
init(color(p6,white))
init(color(p7,white))
init(color(p8,white))
init(color(k2,black))
init(color(q2,black))
init(color(b3,black))
init(color(b4,black))
init(color(n3,black))
init(color(n4,black))
init(color(r3,black))
init(color(r4,black))
init(color(pa,black))
init(color(pb,black))
init(color(pc,black))
init(color(pd,black))
init(color(pe,black))
init(color(pf,black))
init(color(pg,black))
init(color(ph,black))
init(control(white))
init(strength(white,16))
init(strength(black,16))
init(step(1))
legal(Role,move(X1,Y1,X2,Y2)) :- true(control(Role)) & true(color(Piece,Role)) & true(location(X1,Y1,Piece)) & validmove(Piece,X1,Y1,X2,Y2) & ~celloccupiedby(X2,Y2,Role)
legal(Role,place(Piece,X,Y)) :- true(control(Role)) & true(color(Piece,Role)) & ~onboard(Piece) & cellempty(X,Y)
legal(white,noop)
legal(black,noop)
next(location(X2,Y2,Piece)) :- does(Role,move(X1,Y1,X2,Y2)) & true(location(X1,Y1,Piece))
next(location(X,Y,Piece)) :- does(Role,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(location(X,Y,Piece)) :- does(Role,place(Piece,X,Y))
next(location(X,Y,Piece)) :- does(Role,place(Piece1,X1,Y1)) & true(location(X,Y,Piece))
next(location(X,Y,Piece)) :- true(control(Role)) & does(Role,noop) & true(location(X,Y,Piece))
next(color(Piece,Role)) :- does(Role,move(X1,Y1,X2,Y2)) & true(location(X2,Y2,Piece))
next(color(Piece,Color)) :- does(Role,move(X1,Y1,X2,Y2)) & true(color(Piece,Color)) & ~true(location(X2,Y2,Piece))
next(color(Piece,Color)) :- does(Role,place(Anything,X,Y)) & true(color(Piece,Color))
next(color(Piece,Color)) :- true(control(Role)) & does(Role,noop) & true(color(Piece,Color))
next(strength(Role,N)) :- does(Role,move(X1,Y1,X2,Y2)) & celloccupied(X2,Y2) & true(strength(Role,M)) & pp(M,N)
next(strength(Opponent,M)) :- does(Role,move(X1,Y1,X2,Y2)) & celloccupiedby(X2,Y2,Opponent) & true(strength(Opponent,N)) & pp(M,N)
next(strength(Anyone,Count)) :- does(Role,move(X1,Y1,X2,Y2)) & ~celloccupied(X2,Y2) & true(strength(Anyone,Count))
next(strength(Anyone,Count)) :- does(Role,place(Anything,X,Y)) & true(strength(Anyone,Count))
next(strength(Anyone,Count)) :- true(control(Role)) & does(Role,noop) & true(strength(Anyone,Count))
next(control(white)) :- true(control(black))
next(control(black)) :- true(control(white))
next(step(N)) :- true(step(M)) & pp(M,N)
goal(Role,Goal) :- true(strength(Role,Count)) & scoremap(Count,Goal)
terminal :- true(strength(Role,32))
terminal :- true(step(60))
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(Piece,X1,Y1,X2,Y2) :- type(Piece,pawn) & true(color(Piece,white)) & whitepawnmove(X1,Y1,X2,Y2)
validmove(Piece,X1,Y1,X2,Y2) :- type(Piece,pawn) & true(color(Piece,black)) & 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)
onboard(Piece) :- true(location(X,Y,Piece))
celloccupied(X,Y) :- true(location(X,Y,Piece))
celloccupiedby(X,Y,Role) :- true(location(X,Y,Piece)) & true(color(Piece,Role))
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)
type(k1,king)
type(k2,king)
type(q1,queen)
type(q2,queen)
type(p1,pawn)
type(b1,bishop)
type(b2,bishop)
type(b3,bishop)
type(b4,bishop)
type(n1,knight)
type(n2,knight)
type(n3,knight)
type(n4,knight)
type(r1,rook)
type(r2,rook)
type(r3,rook)
type(r4,rook)
type(p1,pawn)
type(p2,pawn)
type(p3,pawn)
type(p4,pawn)
type(p5,pawn)
type(p6,pawn)
type(p7,pawn)
type(p8,pawn)
type(pa,pawn)
type(pb,pawn)
type(pc,pawn)
type(pd,pawn)
type(pe,pawn)
type(pf,pawn)
type(pg,pawn)
type(ph,pawn)
scoremap(0,0)
scoremap(1,3)
scoremap(2,6)
scoremap(3,9)
scoremap(4,12)
scoremap(5,15)
scoremap(6,18)
scoremap(7,21)
scoremap(8,25)
scoremap(9,28)
scoremap(10,31)
scoremap(11,34)
scoremap(12,37)
scoremap(13,40)
scoremap(14,43)
scoremap(15,46)
scoremap(16,50)
scoremap(17,53)
scoremap(18,56)
scoremap(19,59)
scoremap(20,62)
scoremap(21,65)
scoremap(22,68)
scoremap(23,71)
scoremap(24,75)
scoremap(25,78)
scoremap(26,81)
scoremap(27,84)
scoremap(28,87)
scoremap(29,90)
scoremap(30,93)
scoremap(31,96)
scoremap(32,100)
pp(0,1)
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)
pp(60,61)
pp(61,62)
pp(62,63)
pp(63,64)
pp(64,65)
pp(65,66)
pp(66,67)
pp(67,68)
pp(68,69)
pp(69,70)
pp(70,71)
pp(71,72)
pp(72,73)
pp(73,74)
pp(74,75)
pp(75,76)
pp(76,77)
pp(77,78)
pp(78,79)
pp(79,80)
pp(80,81)
pp(81,82)
pp(82,83)
pp(83,84)
pp(84,85)
pp(85,86)
pp(86,87)
pp(87,88)
pp(88,89)
pp(89,90)
pp(90,91)
pp(91,92)
pp(92,93)
pp(93,94)
pp(94,95)
pp(95,96)
pp(96,97)
pp(97,98)
pp(98,99)
pp(99,100)
