% nacteni:
/* ['3.6_17.pl']. */

solution(Start ,Solution) :- breadth_first_search([[ Start ]], Solution).

breadth_first_search([[ Node|Path]|_],[Node|Path]) :- goal(Node).
breadth_first_search([[ N|Path]|Paths],Solution) :-
    bagof([M,N|Path],(move(N,M),\+ member(M,[N|Path])), NewPaths),
    NewPaths\=[], append(Paths,NewPaths,Path1), !,
    breadth_first_search(Path1,Solution); breadth_first_search(Paths,Solution).

% vzorova data
goal(e).
move(a,b). move(a,e). move(a,f).
move(b,c). move(f,c). move(c,d). move(d,e).

% demonstracni vypis

start:- 
    write('depth_first_search_limit'),nl,
    write('Prvni reseni solution(a,Solution):'),nl,
    solution(a,Solution),write(Solution),nl.
?-start.

