Difference between revisions of "Computer Science/61b/Homework/hw9/GRADER"
< Computer Science | 61b | Homework | hw9
m (Lensovet moved page CS/61b/Homework/hw9/GRADER to Computer Science/61b/Homework/hw9/GRADER) |
|
(One intermediate revision by the same user not shown) | |
(No difference)
|
Latest revision as of 03:51, 20 February 2023
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.
- 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
- 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.