我希望你能帮我解决这个问题。
我正在尝试了解 Prolog 中的深度优先搜索算法,我遇到了以下代码
go(Start, Goal) :-
empty_stack(Empty_been_list),
stack(Start, Empty_been_list, Been_list),
path(Start, Goal, Been_list).
% path implements a depth first search in PROLOG
% Current state = goal, print out been list
path(Goal, Goal, Been_list) :-
reverse_print_stack(Been_list).
path(State, Goal, Been_list) :-
mov(State, Next),
% not(unsafe(Next)),
not(member_stack(Next, Been_list)),
stack(Next, Been_list, New_been_list),
path(Next, Goal, New_been_list), !.
reverse_print_stack(S) :-
empty_stack(S).
reverse_print_stack(S) :-
stack(E, Rest, S),
reverse_print_stack(Rest),
write(E), nl.
我有点明白发生了什么,但我一辈子都找不到或发明一些我可以用它的事实。
请帮忙。即使这是一组非常简单的事实,我只需要从某个地方开始
先感谢您