%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% threepuzzle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(robot)
base(board(X,Y,Z,b)) :- tile(X) & tile(Y) & tile(Z)
base(board(X,Y,b,Z)) :- tile(X) & tile(Y) & tile(Z)
base(board(X,b,Y,Z)) :- tile(X) & tile(Y) & tile(Z)
base(board(b,X,Y,Z)) :- tile(X) & tile(Y) & tile(Z)
base(step(1))
base(step(N)) :- successor(M,N)
action(up)
action(down)
action(left)
action(right)
tile(1)
tile(2)
tile(3)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(board(b,3,2,1))
init(step(1))
control(robot)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(up) :- board(X,Y,b,Z)
legal(up) :- board(X,Y,Z,b)
legal(down) :- board(b,X,Y,Z)
legal(down) :- board(X,b,Y,Z)
legal(left) :- board(X,b,Y,Z)
legal(left) :- board(X,Y,Z,b)
legal(right) :- board(b,X,Y,Z)
legal(right) :- board(X,Y,b,Z)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
up :: board(X,Y,b,Z) ==> ~board(X,Y,b,Z) & board(b,Y,X,Z)
up :: board(X,Y,Z,b) ==> ~board(X,Y,Z,b) & board(X,b,Z,Y)
down :: board(b,X,Y,Z) ==> ~board(b,X,Y,Z) & board(Y,X,b,Z)
down :: board(X,b,Y,Z) ==> ~board(X,b,Y,Z) & board(X,Z,Y,b)
left :: board(X,b,Y,Z) ==> ~board(X,b,Y,Z) & board(b,X,Y,Z)
left :: board(X,Y,Z,b) ==> ~board(X,Y,Z,b) & board(X,Y,b,Z)
right :: board(b,X,Y,Z) ==> ~board(b,X,Y,Z) & board(X,b,Y,Z)
right :: board(X,Y,b,Z) ==> ~board(X,Y,b,Z) & board(X,Y,Z,b)
up :: step(M) & successor(M,N) ==> ~step(M) & step(N)
down :: step(M) & successor(M,N) ==> ~step(M) & step(N)
left :: step(M) & successor(M,N) ==> ~step(M) & step(N)
right :: step(M) & successor(M,N) ==> ~step(M) & step(N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(robot,100) :- board(1,2,3,b)
goal(robot,0) :- ~board(1,2,3,b)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- step(7)
successor(1,2)
successor(2,3)
successor(3,4)
successor(4,5)
successor(5,6)
successor(6,7)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%