Академический Документы
Профессиональный Документы
Культура Документы
safe([F,W,G,C]) :- F = G, !.
safe([F,W,G,C]) :- F = W, F = C.
cross(w,e).
cross(e,w).
depth_first_search(AnsPath) :-
initial_state(Init),
depth_first([Init], AnsPath).
depth_first([S|Path], [S]) :-
final_state(S), !.
depth_first([S|Path], [S|AnsPath]) :-
extend([S|Path], S1),
depth_first([S1,S|Path], AnsPath).
extend([S|Path], S1) :-
next_state(S,S1),
not(member_state(S1, [S|Path])).
member_state(S, [S|_]).
member_state(X, [_|T]) :- member_state(X,T).
output: