
role(robot)

base(cell(M,N,T)) :- index(M) & index(N) & tile(T)
base(step(1))
base(step(N)) :- successor(M,N)

input(robot,left)
input(robot,right)
input(robot,up)
input(robot,down)

index(1)
index(2)

tile(1)
tile(2)
tile(3)
tile(b)

init(cell(1,1,b))
init(cell(1,2,3))
init(cell(2,1,2))
init(cell(2,2,1))
init(step(1))

legal(robot,left) :- true(cell(M,2,b))
legal(robot,right) :- true(cell(M,1,b))
legal(robot,up) :- true(cell(2,N,b))
legal(robot,down) :- true(cell(1,N,b))

next(cell(1,N,b)) :- does(robot,up) & true(cell(2,N,b))
next(cell(2,N,b)) :- does(robot,down) & true(cell(1,N,b))
next(cell(M,1,b)) :- does(robot,left) & true(cell(M,2,b))
next(cell(M,2,b)) :- does(robot,right) & true(cell(M,1,b))
next(cell(2,N,X)) :- does(robot,up) & true(cell(2,N,b)) & true(cell(1,N,X))
next(cell(1,N,X)) :- does(robot,down) & true(cell(1,N,b)) & true(cell(2,N,X))
next(cell(M,2,X)) :- does(robot,left) & true(cell(M,2,b)) & true(cell(M,1,X))
next(cell(M,1,X)) :- does(robot,right) & true(cell(M,1,b)) & true(cell(M,2,X))
next(cell(M,N,W)) :- does(robot,up) & true(cell(X,Y,b)) & true(cell(M,N,W)) & distinct(Y,N)
next(cell(M,N,W)) :- does(robot,down) & true(cell(X,Y,b)) & true(cell(M,N,W)) & distinct(Y,N)
next(cell(M,N,W)) :- does(robot,left) & true(cell(X,Y,b)) & true(cell(M,N,W)) & distinct(X,M)
next(cell(M,N,W)) :- does(robot,right) & true(cell(X,Y,b)) & true(cell(M,N,W)) & distinct(X,M)
next(step(N)) :- true(step(M)) & successor(M,N)

goal(robot,100) :- true(cell(1,1,1)) & true(cell(1,2,2)) & true(cell(2,1,3))
goal(robot,0) :- ~true(cell(1,1,1))
goal(robot,0) :- ~true(cell(1,2,2))
goal(robot,0) :- ~true(cell(2,1,3))

terminal :- true(step(7))

successor(1,2)
successor(2,3)
successor(3,4)
successor(4,5)
successor(5,6)
successor(6,7)
