How do you solve a simple maze without knowing what the maze looks like from above?
Well, let's first define the maze. Let's say the maze (I'll call it the Johnesian maze) is a rectangular 'grid' with 2 openings on edges of the grid (for start and exit), and enough walls taken out as to provide at least one path between the openings. Remember that these features define the maze–– the grid is a Johnesian maze only if it has exactly two openings on the edge, and enough grid-walls are removed to provide a path to each.
To show you the first and easiest method, let's think about the lines (note: lines are connected strips walls, not the walls themselves) in the maze. There must be two lines, because the two lines end at the start and finish and cannot be connected in the middle (or else there is no solution path). There can also be island lines, or lines that touch neither the start nor finish.
By that logic, there are two lines that touch both the start and the finish. Therefore, you can just follow one of the walls beside the start until you eventually reach the finish. This is called the left (or right)-hand rule.
For the second, the answer is much less confusing. If one can tell the difference between the start and the finish, and discern therefore that the start is not the finish, you can just pick completely random paths and eventually (after infinity) it is guaranteed that the finish is found. Of course that solution assumes that there is unlimited food and water. This solution is the Random Mouse.
The third is more difficult. As you walk down a passage, draw a line behind you to mark your path. When you hit a dead end turn around and go back the way you came. When you encounter a junction you haven't visited before, pick a new passage at random. If you're walking down a new passage and encounter a junction you have visited before, treat it like a dead end and go back the way you came so that you won't go around in circles or missing passages. If walking down a passage you have visited before (i.e. marked once) and you encounter a junction, take any new passage if one is available, otherwise take an "old" one. Every passage will be either empty (if not visited yet), marked once, or marked twice (if you were forced to backtrack). When you reach the solution, the paths which were marked exactly once will indicate the direct way back to the start. If the maze has no solution, you'll find yourself back at the start with all passages marked twice. It's kind of complicated, but I'm sure it works. BTW, this is called the Tremaux algorithm.
If you can look from above, a good strategy is to fill out all dead ends or nooses (eg, places where you must backtrack to find a solution). Then you fill in the places that lead only to dead ends and nooses. And etc, until the only paths not filled in are solutions.
The last one is the Pledge Algorithm. The idea is to try to always go in one chosen direction, if you do not turn more than 359 degrees in any direction.
So let's measure our angles- a left turn is worth -1 and a right turn is worth 1, and you add each on to your 'turn count' whenever you turn. Choose a direction that goes towards the finish, and calibrate it to turn count=0, -4, 4, and so on. Just know that no multiple of 4 that is not 0 is equal to 0, just for this algorithm. In the algorithm:
1) If turn count = 0 and path ahead is open, then go forward.
2) If turn count is 0 and there is a wall directly ahead, then follow that wall in a random direction until turn count=0.
This algorithm is confusing and difficult, but it works.
NOTE: Only one of these methods is mine, and a ton of them I don't understand at all. If I have left something out, sorry!
Good sites:
Labyrinth.htm
Wikipedia- Maze solving algorithms
I bet your brain exploded a while ago, so I might as well just shut up now. See ya!
Stay coolio,
John
No comments:
Post a Comment
Comment if you dare