% No looping approach, no duplicating % states are simple atoms a, b, c, ... k. % moves or successor states are directly hardwired into code move(a,b). move(a,c). move(b,d). move(b,e). move(c,f). move(c,g). move(d,h). move(h,d). move(e,i). move(e,j). move(f,k). start(a). goal(j). goal(f). % Start with ?- solve(a, Sol). solve(X, Soln) :- solve(X, [], Sol), reverse(Sol, Soln). % solve(State, Path, Solution) solve(State, Path, [State|Path]) :- goal(State). solve(State, Path, Sol) :- move(State, NewState), not(member(NewState, Path)), solve(NewState, [State|Path], Sol).