Hardware Reference
In-Depth Information
(It's immutable.) So cellsVisitedList is a list that contains tuples, which in turn contain
pairs of x and z coordinates. You can use the Python shell to take a look inside this list. Here's
an example from one run of the program, showing a path taken through the maze:
>>> print cellsVisitedList
[(6, 6,), (6, 7), (6, 8), (5, 8), (4, 8), (3, 8), (3, 7)]
For step 5 in the algorithm, you go back to the previous position in the path if your cell has
no unvisited neighbours. his involves taking the last position out of the list. here's a list
method called pop() you can use to do that. It takes the last item from a list and deletes it
from that list. In your program, you put it into a variable called retrace , which then stores
a tuple for the x and z positions in the maze. As with a list, you can use index numbers to
access the individual elements in a tuple. he index numbers start at 0, so retrace[0] will
hold your previous x position, and retrace[1] will hold your previous z position. Here's
the code, including a line to show the gold block in its new position:
else: # do this when there are no unvisited neighbours
retrace = cellsVisitedList.pop()
xposition = retrace[0]
zposition = retrace[1]
showMaker(xposition, zposition)
Note that your else statement should be in line with the if statement it's paired with, in
this case the one that tests whether you found any possible directions to move in.
Step 6 in the algorithm has already been implemented because the while loop will keep
repeating the indented code underneath it until every cell has been visited.
Adding a Ceiling
Personally, I think it's more fun to leave the ceiling open and be free to ly up and marvel at
your maze, and drop into it at any point. If you wanted to build a game around your maze,
though, and stop people from cheating, you can add a ceiling using the following code. Just
change the variable CEILING to True at the start of the program. I've made the ceiling out
of glass bricks, so it doesn't get too dark in there:
if CEILING == True:
mc.setBlocks(MAZE_X, GROUND+HEIGHT+1, MAZE_Z, ;
MAZE_X+(SIZE*2), GROUND+HEIGHT+1, MAZE_Z+(SIZE*2), 20)
Search WWH ::




Custom Search