Hardware Reference
In-Depth Information
Setting Up the Variables and Lists
To implement this algorithm, you'll use the following variables:
numberOfCells : his is the total number of cells in the maze, which will be
SIZE*SIZE . ( * is the symbol for multiplication.)
numberOfVisitedCells : his keeps track of how many cells you've visited so far.
When this is the same as the numberOfCells , every cell has been visited and had a
wall demolished, and is therefore reachable. he maze is inished.
xposition : his remembers your x position as you move through the maze generating
it. It's measured in cells, and starts as a random number between 1 and the maze SIZE .
zposition : his remembers your z position as you move through the maze generat-
ing it, also measured in cells, and also starting as a random number.
cellsVisitedList[] : his is a list that stores the path you've taken, so the pro-
gram can retrace its steps. When you set it up, you put your starting position into it
using the append() list method.
playerx and playerz : hese are used to remember the starting position, so you can
put the player there when the maze has been built.
When an algorithm like this is implemented (it's called a depth-irst maze generation algo-
rithm ), it often requires a list or similar data structure to be used to store the locations of
walls. You don't need that because you have actual walls in Minecraft you can look at. he
game world stores your maze, if you like.
he following code lines set up your starting variables:
numberOfCells = SIZE*SIZE
numberOfVisitedCells = 1
cellsVisitedList = []
xposition = random.randint(1, SIZE)
zposition = random.randint(1, SIZE)
playerx = xposition
playerz = zposition
cellsVisitedList.append((xposition, zposition))
Creating the Functions
here are a number of basic functions you will need for your program:
realx(x) and realz(z) : hese convert coordinates in the maze (measured in cells)
into coordinates in the Minecraft world (measured in blocks, and ofset from the
maze's starting position).
Search WWH ::




Custom Search