TRMAUX -Methode Java
Trémaux method Java
-helps you to solve a Labyrinth
-there are two kind of Fields:
-Ways (there are two walls and just two free fields (one where you came from and one where you will go to)
-Crossings (there are at least three open ways) you have to mark the way where you came from and where you will go to)
-if a path has two or more marks do not cross it
-Let´s Go:
> if there are two walls and two open ways, choose the way you didn´t came from
> if there are are at least three open ways:
> mark the direction wehre you came from
> if you never visited the crossing before choose one of the paths and mark it too
> if you visited the place before (there allready is a mark in at least one direction (not counting the one you just put behind you)) go back and mark the way again
> if you visited the place before and behind you allready are two marks choose one of the paths with the smallest number of marks (0 or 1)
> if there are two or more marks or walls in every direction you just walked through the whole labyrinth
-the labyrinth is a twodimensional Array
-at a crossing you will scan the diffrent directions (left, ahead, right, back), so you will need a second system based on compass directions to change the coordinates
-For Example: Laby[y][x]
North = 1; East = 2; South = 3; West = 4;
startDirection = 3; N
if you move right: direction = direction + 1 ###
if you move left: direction = direction - 1 W# #E
if you move forward: direction stays the same ###
if you turn around: direction = direction + 2 S
if direction = 5: direction = 1 //in case you want to turn from South to North
if direction = 6: direction = 2 //in case you want to turn from West to East
if direction = 1: changePosition: y + 1 (go one field up(North))
if direction = 2: changePosition: x + 1 (go one field right(East))
if direction = 3: changePosition: y - 1 (go one field down(South))
if direction = 4: changePosition: x - 1 (go one field left(West))
//If I could help you, I would appreciate a little donation
znarfbay