action(X:Y,0:Y ):-
X > 0.
action(X:Y,X:0):-
Y > 0.
action(X:Y,4:Y):-
X < 4.
action(X:Y,X:3):-
Y < 3.
action(X:Y,4:Z):-
X < 4,Z is Y - (4 - X),Z >= 0.
action(X:Y,Z:3):-
Y < 3,Z is X - (3 - Y ),Z >= 0.
action(X:Y,Z:0):-
Y > 0,Z is (X + Y),Z =< 4.
action(X:Y,0:Z):-
X > 0,Z is (X + Y),Z =< 3.
path(X):-
path(0:0,[0:0],X).
path(2:0,Visited,Visited).
path(State,Visited,Path):-
action(State,NewState),
not(member(NewState,Visited)),
path(NewState,[NewState|Visited],Path).
member(X,[X|Y]).
member(X,[Y|Z]):-
member(X,Z).
No comments:
Post a Comment