Hardware Reference
In-Depth Information
Figure 7-3:
Your grid in
Minecraft.
Understanding the Maze Algorithm
Before you dig into the code that turns your wale into a maze, let me tell you how it works.
You're going to make what's known as a “perfect maze” (that's a technical term, not me brag-
ging). hat means there are no loops in it, and no parts of the maze you can't get into. here
is only one path between any two points in the maze.
Here's how the program works:
1. You start with the “wale” you've built, with every cell having all four walls.
2. You pick a random cell in the maze to start at.
3. You look at your current cell's neighbours, and make a list of all those that have all four
walls intact. hese are the cells that have not yet been visited.
4. If you found some unvisited neighbours, you pick one at random, knock down the
wall between it and your current cell, and then move into that cell, making it your cur-
rent cell.
5. If your current cell has no unvisited neighbours, you go back one cell in the path you've
taken, and make that your current cell.
6. You repeat steps 3 to 5 until you've visited every cell.
Search WWH ::




Custom Search