Question: Q13 IN JAVA import java.util.*; public class MazeMaker5 { static int desiredPathLength; static Maze maze; public static void main (String[] argv) { generateMaze (5, 5);

Q13 IN JAVAQ13 IN JAVA import java.util.*; public class MazeMaker5 { static int desiredPathLength;

import java.util.*; public class MazeMaker5 { static int desiredPathLength; static Maze maze; public static void main (String[] argv) { generateMaze (5, 5); if (maze != null) { // We will seek a path from the top-left to the bottom-right corner. Coord start = new Coord (0,0); Coord end = new Coord (4,4); solveMaze (maze, start, end); maze.display (); } else { System.out.println ("Maze creation did not work"); } } // A path is a list of cells, i.e., a list of Coord instances. static LinkedList solutionPath; static void solveMaze (Maze maze, Coord start, Coord end) { // We'll mark visited cells as we go along our path. Initially: maze.markAllUnvisited (); // Mark the start cell as visited. maze.markVisited (start); // Create the list. solutionPath = new LinkedList (); // Recursively find the path and fill in coord's into the list. recursivelyFindPath (maze, start, end); // The start node gets added last. Why? solutionPath.addFirst (start); // Pass the path into the GUI. maze.setSolutionPath (solutionPath); } static boolean recursivelyFindPath (Maze maze, Coord c, Coord end) { // If we've reached the end, we're done. if ( (c.row == end.row) && (c.col == end.col) ) { return true; } // Otherwise, let's find a neighbor to explore. Coord[] validNeighbors = maze.getUnvisitedOpenNeighbors (c); if (validNeighbors == null) { // If we couldn't find any neighbors to explore, we're stuck. return false; } // Try each neighbor, as many as needed. for (int i=0; i 

In-Class Exercise 13: Download MazeMaker5.java, compile and execute. Does it find a solution? Then add code to answer these questions: How many dead-end's are reached in trying to find a path? Add code to count such dead-end's. What does a trace look like? Add copious println's to see how the recursion works. Use the indented printing we studied in Module 4 In-Class Exercise 13: Download MazeMaker5.java, compile and execute. Does it find a solution? Then add code to answer these questions: How many dead-end's are reached in trying to find a path? Add code to count such dead-end's. What does a trace look like? Add copious println's to see how the recursion works. Use the indented printing we studied in Module 4

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!