Hardware Reference
In-Depth Information
If you have an error, check for missing colons at the end of your def and if statements.
Creating the Main Loop
Your maze algorithm runs until you've visited every cell, so it starts with the following statement:
while numberOfVisitedCells < numberOfCells:
You need to test whether your current cell's neighbour cells have all their walls intact. To do
that, you check each direction in turn, using the testAllWalls(x, z) function. When you
ind a cell with all the walls intact, you add its direction to the list possibleDirections[]
using the append() list method. his implements step 3 in the algorithm (remember it's all
indented underneath the while statement):
possibleDirections = []
if testAllWalls(xposition-1, zposition):
possibleDirections.append(“left”)
if testAllWalls(xposition+1, zposition):
possibleDirections.append(“right”)
if testAllWalls(xposition, zposition-1):
possibleDirections.append(“up”)
if testAllWalls(xposition, zposition+1):
possibleDirections.append(“down”)
he values of up , down , left and right are somewhat arbitrary in 3D space, but I've used
them because they're easy to understand. If you ly into the air and look down on the maze
as it's being generated and you have the block identifying the starting corner of the maze
( MAZE_X , MAZE_Z ) in the top left, these directions will look correct to you.
Incidentally, you might have noticed that there's no check for whether these cell positions
are inside the maze borders. What happens if you look for a cell of the left edge of the maze,
or of the bottom edge? No problem. he program implementation automatically respects
the borders of the maze because when it looks at “cells” outside the borders, they don't have
all four walls (their only wall is the maze's border), so they are never visited.
 
Search WWH ::




Custom Search