Open main menu

lensowiki β

Computer Science/61b/Homework/hw9/GRADER

< Computer Science‎ | 61b‎ | Homework‎ | hw9
Revision as of 06:42, 22 September 2007 by Lensovet (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

To generate a random maze, modify the depthFirstSearch() method so that the order in which you check each direction (such as if ((fromWhere != FROMRIGHT) && !verticalWall(x, y))) is randomized. Then, each time the method checks for a cycle, if it doesn't find one, it can eliminate the wall before recursively checking the other cells.

  1. Since the basic checking algorithm remains unchanged, it will still do the same things the current algorithm is doing - check every cell, but only once, for a cycle
  2. There are 4 potential directions to be checked - top, right, bottom, and left. Create an array of length 4 with the digits 1-4. Randomize the digits in the same way we randomized the walls in the original homework. Then have a switch statement, with each case containing the cell check (i.e. if ((fromWhere != FROMRIGHT) && !verticalWall(x, y))), and run a for loop iterating through the array and executing each case. This way we make sure that each case is direction is actually checked.