% 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).



move([CurrX, CurrY], [NextX, NextY],Faceold,FaceNew):-

	Faceold = n ,moven([CurrX, CurrY], [NextX, NextY],FaceNew).

move([CurrX, CurrY], [NextX, NextY],Faceold,FaceNew):-

	Faceold = e ,movee([CurrX, CurrY], [NextX, NextY],FaceNew).

move([CurrX, CurrY], [NextX, NextY],Faceold,FaceNew):-

	Faceold = s ,moves([CurrX, CurrY], [NextX, NextY],FaceNew).

move([CurrX, CurrY], [NextX, NextY],Faceold,FaceNew):-

	Faceold = w ,movew([CurrX, CurrY], [NextX, NextY], FaceNew).



%left faceing North:
moven([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX - 1,Face = w.

%up faceing North:
moven([CurrX, CurrY], [CurrX, NextY], Face) :-
	NextY is CurrY - 1,Face = n.

%right faceing North:
moven([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX + 1,Face = e.

%down faceing North:
moven([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY is CurrY + 1, NextX = CurrX,Face = s.




%up facing East:
movee([CurrX, CurrY], [CurrX, NextY], Face) :-
	NextY is CurrY - 1,Face = n.

%right facing East:
movee([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX + 1,Face = e.

%down facing East:
movee([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY is CurrY + 1, NextX = CurrX,Face = s.

%left facing East:
movee([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX - 1,Face = w.



%down facing West:
movew([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY is CurrY + 1, NextX = CurrX,Face = s.

%left facing West:
movew([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX - 1,Face = w.

%up facing West:
movew([CurrX, CurrY], [CurrX, NextY], Face) :-
	NextY is CurrY - 1,Face = n.


%right facing West:
movew([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX + 1,Face = e.




%right faceing South:
moves([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX + 1, Face = e.

%down faceing South:
moves([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY is CurrY + 1, NextX = CurrX,Face = s.

%left faceing South:
moves([CurrX, CurrY], [NextX, NextY], Face) :-
	NextY = CurrY, NextX is CurrX - 1,Face = w.

%up faceing South:
moves([CurrX, CurrY], [CurrX, NextY], Face) :-
	NextY is CurrY - 1,Face = n.



solve(CurrentLocation,_, _, Path) :-
	end(CurrentLocation), Path = [CurrentLocation].


solve(CurrentLocation,Face, BeenThere, Path) :-

	move(CurrentLocation, NewLocation,Face,FaceNew),
	%%%((to keep ur hand on the left wall just keep checking in u can go left first then staight then right then back))
        \+badSpot(NewLocation),
        %\+member(NewLocation, BeenThere),
        solve(NewLocation, FaceNew, [NewLocation | BeenThere], RestOfPath),
        Path = [CurrentLocation | RestOfPath].

% Convenience rule:
solve(Path) :-
	start(Start), solve(Start, [Start], Path).
