% Row 1

wall([X,1]) :- X =\= 2.

% Row 2

wall([X,2]) :- X = 1; X = 4; X = 6.

% Row 3

wall([X,3]) :- X = 1; X = 2; X = 6.

% Row 4

wall([X,4]) :- X =\= 3,X =\= 5.

% Row 5

wall([X,5]) :- X = 1; X = 4; X = 6.

% Row 6

wall([X,6]) :- X =\= 2.

% Start / end

start([2,1]).
end([2,6]).

% Maze Size

mazeSize([6,6]).

badSpot([X,Y]) :- wall([X,Y]).
badSpot([X,Y]) :- X < 1; Y < 1.
badSpot([X,Y]) :- mazeSize([W, H]), (X > W; Y > H).



%up
move([CurrX, CurrY], [CurrX, NextY]) :- NextY is CurrY + 1.
%left
move([CurrX, CurrY], [NextX, NextY]) :- NextY = CurrY, NextX is CurrX - 1.
%down
move([CurrX, CurrY], [NextX, NextY]) :- NextY is CurrY - 1, NextX = CurrX.
%right
move([CurrX, CurrY], [NextX, NextY]) :- NextY = CurrY, NextX is CurrX + 1.



solve(CurrentLocation, _, Path) :- end(CurrentLocation), Path = [CurrentLocation].


solve(CurrentLocation, BeenThere, Path) :- move(CurrentLocation, NewLocation),
        \+badSpot(NewLocation),
        \+member(NewLocation, BeenThere),
        solve(NewLocation, [NewLocation | BeenThere], RestOfPath),
        Path = [CurrentLocation | RestOfPath].

% Convenience rule:
solve(Path) :-
	start(Start), solve(Start, [Start], Path).



	% What I found to be the besy aproch is the heading in genral direction.
% even tho the approch were you follow the left wayy will always lead to
% the exit it will offten times take the longerst. I also found that
% when you put all the point directly in the rules he program tends to
% run quicker. I also found that the order in which you put the move
% commands also matters. What i could see being a usefule alternitive is
% a kinda what i did in the stick to the left wall approch is to change
% the order of the directions. Im not sure exactly what you could use in
% to trigger the change in order. Maybe the keep track of the turns and
% swich every five or so or maybe just make it random. Implimenting this
% with keeping track of the beenthere locations could provide a
% substantiale advantage.
