:-eager_consume plan/3.
:-table plan(+,-,min).
plan(State,Plan,Len):-
is_final_state(State),!,
Plan=[],Len=0.
plan(State,[Move|Plan],Len):-
select_move(State,Move),
update(State,Move,State1),
plan(State1,Plan,Len1),
Len is Len1+1.
This program implements the depth-first search algorithm for state-transition problems. It terminates once a final state has been reached. For a state, only a plan of the shortest length is tabled. When applied to a graph, this program behaves like the Dijkstra's algorithm for finding shortest paths. Without the eager_consume declaration, the program would explore the state space in a breadth-first fashion.