% dfs.pl % naive attemp! Solution path found couldbe be 20,000 % steps away instead of just 4 or 5. % This predicate helps you choose a starting state and % displays the eventual solution path dfs :- write('Start at depth 4 5 6 7 8 or 18 ? : '), read( I ), start( I , X ), dfs( X, [], Sol ), reverse(Sol, Soln), nl, showSolPath( Soln). % This predicate helps you choose a starting state and % displays the lenght of the eventual solution path. % More useful here. dfs2 :- write('Start at depth 4 5 6 7 8 or 18 ? : '), read( I ), start( I , X ), dfs( X, [], Sol ), length(Sol, L), nl, write('Solution requires '), write(L), write(' steps'), nl. % This is the central predicate for depth first search % Same as solve(X, P, S) in notes dfs( X , P , [X | P] ) :- goal( X ). dfs( X , P , S ) :- move( X , X1 ), not(member(X1, P)), dfs( X1 , [X|P] , S ).