Once I've created the maze, I then relocate to the random starting point
at the top of the maze. This time I'm looking for a path to the bottom of the
maze, so I use a different stack. I pick a random direction and go until I
find either a dead-end or a junction. If I find a junction, I push it onto
the stack and then pick a new random direction. If I find a dead-end, I pop
the last junction from the stack and start over. I continue until I work my
way to the bottom of the maze. Once there, I mark the cell that I've arrived
at as the exit point.
Once I got the maze algorithm to work, I couldn't resist doing a bit of
tweaking, so I added a routine to show the solution path through the maze
and code to allow users to work their own way through the maze by clicking
on cells with the mouse.
I also added code to show a bitmap behind the maze.
To pick your way through the maze, look for the red dot at the top of the maze.
This is the starting location. Use the mouse to left-click on any cell adjacent to
the starting point to begin finding your way through the maze. You can scroll
the maze either by using the scroll bars or by holding down the right mouse-button
and dragging the mouse.
To see the solution path, click on the "solve" button. To keep the current maze
but start over, click on the "reset" button, and to generate a brand new maze, click
on the "new" button.
|