% ==========================================================================
% $Id: labyrinth.pl,v 1.1 2014/01/28 06:18:50 jlang Exp $
% CSI2120 example Code for lecture 7
% ==========================================================================
% (C)opyright:
%
%   Jochen Lang
%   SITE, University of Ottawa
%   800 King Edward Ave.
%   Ottawa, On., K1N 6N5
%   Canada. 
%   http://www.eecs.uottawa.ca/~jlang
% 
% Creator: jlang (Jochen Lang)
% Email:   jlang@eecs.uottawa.ca
% ==========================================================================
% $Log: labyrinth.pl,v $
% Revision 1.1  2014/01/28 06:18:50  jlang
% Added tree and graph examples.
%
% ==========================================================================
link(0,1). % start = 0
link(1,2).
link(2,6).
link(6,5).
link(6,7).
link(5,4).
link(5,9).
link(9,8).
link(8,12).
link(9,10).
link(10,11).
link(9,13).
link(13,14).
link(14,15). % finish = 1

successor(A,B) :- link(A,B).
successor(A,B) :- link(B,A).
% Define the finish node
finish(15).
% Boundary case if finish is reached
pathFinder([Last|Path],[Last|Path]) :-
	finish(Last).
% Go to the next node in a depth first manner unless it is a loop
pathFinder([Curr|Path],Solution) :-
	successor(Curr,Next),
 	\+member(Next,Path),write(Next),nl,
	pathFinder([Next,Curr|Path],Solution).

