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

Q14 In JAVAQ14 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 

NEXT CODE

import java.util.*; import java.awt.*; import javax.swing.*; public class ChessBoard { // Instance variables. int size; char[][] board; // board[i][j] == 'X' if there's a queen on it. // Constructor. public ChessBoard (int size) { // Build the board. Initially empty: board[i][j] == 'O'. this.size = size; board = new char [size][size]; for (int i=0; i 

queen.jpg

static Maze maze; public static void main (String[] argv) { generateMaze (5,

You will also need ImageTool.java

In-Class Exercise 14: Can 3 queens he placed on a 3 queens he placed on a 33 board? Can 3 queens he placed on a 4x4 hoard? Download and modify NQueens.java and ChessBoard java to find out. You will also need Image Tool java and queen.jpg. In-Class Exercise 14: Can 3 queens he placed on a 3 queens he placed on a 33 board? Can 3 queens he placed on a 4x4 hoard? Download and modify NQueens.java and ChessBoard java to find out. You will also need Image Tool java and queen.jpg

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!