Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 JAVA
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 LinkedListsolutionPath; 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; iqueen.jpg
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started