Question: public class MazeMaker3 { static int desiredPathLength; static Maze maze; public static void main (String[] argv) { generateMaze (5, 5); } public static void generateMaze

public class MazeMaker3 { static int desiredPathLength; static Maze maze; public static void main (String[] argv) { generateMaze (5, 5); } public static void generateMaze (int numRows, int numCols) { maze = new Maze (numRows, numCols); desiredPathLength = numRows * numCols; // Initially, we'll start with the top left cell. Coord start = new Coord (0, 0); maze.markVisited (start); // Generate the maze path recursively. boolean found = recursiveGenerate (start, 1); if (! found) { System.out.println ("Could not create the whole maze"); } // Break a few more walls randomly. breakRandomWalls (maze, 10); maze.display(); } static boolean recursiveGenerate (Coord c, int pathLength) { // Bottom out condition 1: if (pathLength == desiredPathLength) { return true; } // Bottom out condition 1: see if we're stuck. Coord[] validNeighbors = maze.getUnvisitedClosedNeighbors (c); if ((validNeighbors == null) || (validNeighbors.length == 0)) { return false; } // Otherwise, we have some neighbors to explore. // Permute the directions randomly. permute (validNeighbors); for (int i=0; i  

public class MazeMaker3 { static int desiredPathLength; static Maze maze; public static

In-Class Exercise 11: Download MazeMaker3java. compile and execute. Solve by hand the maze generated: start at the top-left corner and find a path to the bottom-right corner In-Class Exercise 11: Download MazeMaker3java. compile and execute. Solve by hand the maze generated: start at the top-left corner and find a path to the bottom-right corner

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!