The first thing that happens in the program is the generation of the maze. This is done recursively, and starts at the end (this makes it so the end is a dead end). The recursive algorithm I used to generate the maze goes like this:
- Mark the current cell as 'visited'
- Recurse on all directly adjacent cells that have not been visited in a random order
- Remove walls between this and the next cell
- Return when all adjacent cells have been visited
Here's a quick example of the algorithm on a 5x5 grid:
The red signifies the places the algorithm has already visited, and the arrows within them show which neighbor they chose next (which cell the recursive function chose at random). The blue cell is the current cell, with the bold outlines showing where it's neighbors are. Because two of it's neighbors have been visited before (East and South of current), the current function only considers the North and West neighbors (green), and visits them in a random order, in this case North and then West. Note that it may never travel from the current cell to the West neighbor, as it may visit it later in the path before it has to return to go down that path, say, if it continues down this path:
That's all for this post, in my next post about this little project I will talk about the shadows and how they are computed. If you want to look at my code, the project can be downloaded from this link, however, note that you will need Processing to run it.


No comments:
Post a Comment