dfs([Node | OPEN], _ , Goal) :-
Node==Goal, !,
write('yes! goal reached.... ' - Goal), nl.
dfs([Node | OPEN],CLOSED, Goal) :-
findall( Next,
(
arc(Node, Next), Next
not(member(Next, OPEN)), not(member(Next, CLOSED))
),
NewNode
),
append(NewNode, OPEN, NewOPEN),
write('OPEN = frontier of search...'), write(NewOPEN),nl,
write('CLOSED = nodes already visited...'), write([Node | CLOSED]),nl,nl,
dfs(NewOPEN, [Node | CLOSED], Goal). % recurse with new data
arc(a、b)。arc(a、c)。arc(b、d)。arc(b、e)。arc(c、f)。arc(f、g)。arc(e、z)。arc(d、e)。arc(z、g)。arc(z、d)。