h(a,b). h(b,e). h(c,d). h(d,e). h(c,b). h(a,d). h(e,f). h(b,f). h(b,a). findall_m(X, G, _) :- asserta(found(mark)), call(G), asserta(found(X)), fail. findall_m(_, _, L) :- collect_found([], M), !, L = M. collect_found(S, L) :- getnext(X), !, collect_found([X|S], L). collect_found(L, L). getnext(X) :- retract(found(X)), !, X \== mark. cesta_do_sirky(Start, Cil) :- seek1([Start], Cil, [Start]). % seek1(OPEN,GOAL,CLOSE). seek1([], _, _) :- !, fail. seek1(Queue, Goal, _) :- member(Goal, Queue). seek1(Queue, Goal, Oldtail) :- seek2(Queue, [], Children, Oldtail, Newtail), seek1(Children, Goal, Newtail). % seek2(OPEN, SUCC_OPEN_IN, SUC_OPEN_OUT, CLOSE, CLOSE_OUT) seek2([], Children, Children, Newtail, Newtail) :- !. seek2([N|Ns], Sf, Children, Oldtail, Newtail) :- findall(D, h(N,D), Ds), addon(Ds, Sf, Newque, Oldtail, Temptail), seek2(Ns, Newque, Children, Temptail, Newtail). addon([], L, L, Tn, Tn). addon([N|Ns], L, M, To, Tn) :- (member(N, L);member(N, To)), !, addon(Ns, L, M, To, Tn). addon([N|Ns], L, M, To, Tn) :- addon(Ns, [N|L], M, [N|To], Tn).