role(xplayer)
role(oplayer)
base(mark(I,J,K,L,x)) :- index(I) & index(J) & index(K) & index(L)
base(mark(I,J,K,L,o)) :- index(I) & index(J) & index(K) & index(L)
base(currentboard(I,J)) :- index(I) & index(J)
base(control(R)) :- role(R)
input(xplayer,play(I,J,K,L,x)) :- index(I) & index(J) & index(K) & index(L)
input(oplayer,play(I,J,K,L,o)) :- index(I) & index(J) & index(K) & index(L)
input(R,noop) :- role(R)
init(control(xplayer))
legal(xplayer,noop) :- true(control(oplayer))
legal(xplayer,play(I,J,K,L,x)) :- true(control(xplayer)) & firstmove & emptycell(I,J,K,L)
legal(xplayer,play(I,J,K,L,x)) :- true(control(xplayer)) & true(currentboard(I,J)) & emptycell(I,J,K,L)
legal(xplayer,play(I,J,K,L,x)) :- true(control(xplayer)) & currentboardclosed & emptycell(I,J,K,L)
legal(oplayer,noop) :- true(control(xplayer))
legal(oplayer,play(I,J,K,L,o)) :- true(control(oplayer)) & firstmove & emptycell(I,J,K,L)
legal(oplayer,play(I,J,K,L,o)) :- true(control(oplayer)) & true(currentboard(I,J)) & emptycell(I,J,K,L)
legal(oplayer,play(I,J,K,L,o)) :- true(control(oplayer)) & currentboardclosed & emptycell(I,J,K,L)
next(mark(I,J,K,L,Mark)) :- does(Player,play(I,J,K,L,Mark))
next(mark(I,J,K,L,Mark)) :- true(mark(I,J,K,L,Mark))
next(currentboard(K,L)) :- does(Player,play(I,J,K,L,Mark))
next(control(xplayer)) :- true(control(oplayer))
next(control(oplayer)) :- true(control(xplayer))
goal(xplayer,0) :- ~line(x) & ~line(o) & open
goal(xplayer,100) :- line(x)
goal(xplayer,50) :- ~line(x) & ~line(o) & ~open
goal(xplayer,0) :- line(o)
goal(oplayer,0) :- ~line(x) & ~line(o) & open
goal(oplayer,100) :- line(o)
goal(oplayer,50) :- ~line(x) & ~line(o) & ~open
goal(oplayer,0) :- line(x)
terminal :- line(x)
terminal :- line(o)
terminal :- ~open
row(I,J,K,Mark) :- true(mark(I,J,K,1,Mark)) & true(mark(I,J,K,2,Mark)) & true(mark(I,J,K,3,Mark))
col(I,J,K,Mark) :- true(mark(I,J,1,K,Mark)) & true(mark(I,J,2,K,Mark)) & true(mark(I,J,3,K,Mark))
diag(I,J,Mark) :- true(mark(I,J,1,1,Mark)) & true(mark(I,J,2,2,Mark)) & true(mark(I,J,3,3,Mark))
diag(I,J,Mark) :- true(mark(I,J,1,3,Mark)) & true(mark(I,J,2,2,Mark)) & true(mark(I,J,3,1,Mark))
line(Mark) :- index(I) & index(J) & index(K) & row(I,J,K,Mark)
line(Mark) :- index(I) & index(J) & index(K) & col(I,J,K,Mark)
line(Mark) :- index(I) & index(J) & diag(I,J,Mark)
emptycell(I,J,K,L) :- index(I) & index(J) & index(K) & index(L) & ~true(mark(I,J,K,L,x)) & ~true(mark(I,J,K,L,o))
open :- emptycell(I,J,K,L)
currentboardclosed :- true(currentboard(I,J)) & ~emptycell(I,J,1,1) & ~emptycell(I,J,1,2) & ~emptycell(I,J,1,3) & ~emptycell(I,J,2,1) & ~emptycell(I,J,2,2) & ~emptycell(I,J,2,3) & ~emptycell(I,J,3,1) & ~emptycell(I,J,3,2) & ~emptycell(I,J,3,3)
firstmove :- ~true(currentboard(1,1)) & ~true(currentboard(1,2)) & ~true(currentboard(1,3)) & ~true(currentboard(2,1)) & ~true(currentboard(2,2)) & ~true(currentboard(2,3)) & ~true(currentboard(3,1)) & ~true(currentboard(3,2)) & ~true(currentboard(3,3))
index(1)
index(2)
index(3)
