%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goodbuttonsandlights
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% metadata
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
role(robot)
base(p(X)) :- index(X)
base(q(X)) :- index(X)
base(r(X)) :- index(X)
base(step(X,1)) :- index(X)
base(step(X,2)) :- index(X)
base(step(X,3)) :- index(X)
base(step(X,4)) :- index(X)
base(step(X,5)) :- index(X)
base(step(X,6)) :- index(X)
base(step(X,7)) :- index(X)
action(a(X)) :- index(X)
action(b(X)) :- index(X)
action(c(X)) :- index(X)
index(1)
index(2)
index(3)
index(4)
index(5)
index(6)
index(7)
index(8)
index(9)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
init(step(1,1))
init(step(2,1))
init(step(3,1))
init(step(4,1))
init(step(5,1))
init(step(6,1))
init(step(7,1))
init(step(8,1))
init(step(9,1))
init(control(robot))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% legal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legal(a(5)) :- index(5) & ~step(5,7)
legal(b(5)) :- index(5) & ~step(5,7)
legal(c(5)) :- index(5) & ~step(5,7)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a(X) :: ~p(X) ==> p(X)
a(X) :: p(X) ==> ~p(X)
a(X) :: step(X,M) & successor(M,N) ==> ~step(X,M) & step(X,N)
b(X) :: q(X) ==> p(X)
b(X) :: ~q(X) ==> ~p(X)
b(X) :: p(X) ==> q(X)
b(X) :: ~p(X) ==> ~q(X)
b(X) :: step(X,M) & successor(M,N) ==> ~step(X,M) & step(X,N)
c(X) :: q(X) ==> r(X)
c(X) :: ~q(X) ==> ~r(X)
c(X) :: r(X) ==> q(X)
c(X) :: ~r(X) ==> ~q(X)
c(X) :: step(X,M) & successor(M,N) ==> ~step(X,M) & step(X,N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% goal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
goal(robot,100) :- p(5) & q(5) & r(5)
goal(robot,50) :- p(5) & q(5) & ~r(5)
goal(robot,50) :- p(5) & ~q(5) & r(5)
goal(robot,50) :- ~p(5) & q(5) & r(5)
goal(robot,25) :- p(5) & ~q(5) & ~r(5)
goal(robot,25) :- ~p(5) & q(5) & ~r(5)
goal(robot,25) :- p(5) & ~q(5) & ~r(5)
goal(robot,0) :- ~p(5) & ~q(5) & ~r(5)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% terminal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
terminal :- p(5) & q(5) & r(5)
terminal :- step(5,7)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
successor(1,2)
successor(2,3)
successor(3,4)
successor(4,5)
successor(5,6)
successor(6,7)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%