Question
Please correct the code and make sure it does the following: Write a MazeSolver class in Java. This program needs to prompt the user for
Please correct the code and make sure it does the following:
Write a MazeSolver class in Java. This program needs to prompt the user for a maze filename and then explore the maze. Display how many exits were found and the positions (not indices) of the valid exits. Your program can display the valid exits found in any order. Run the code in your program to verify that it runs.
import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays;
public class MazeSolver { int numRows; int numCols; int startRow; int startCol; int rows; int col; public static void main (String[] args){ MazeSolver addmaze = new MazeSolver(); addmaze.loadMaze(); } public void loadMaze(){ //int numRows; //int numCols; int startRow; int startCol; int rows; int col; try{ Scanner input = new Scanner(System.in); System.out.println("Please enter file name:"); String filename = input.nextLine(); File file = new File(filename); Scanner fileInput = new Scanner(file); numRows = fileInput.nextInt(); numCols = fileInput.nextInt(); ArrayList wallCols= new ArrayList
// Mark current position as visited visited[row][col] = true; exploreMaze(row-1, col, visited, maze,exitRows, exitCols); // up exploreMaze(row, col+1, visited, maze,exitRows, exitCols); // right exploreMaze(row+1, col, visited, maze,exitRows, exitCols); // down exploreMaze(row, col-1, visited, maze,exitRows, exitCols); // left
// Recursively explore neighboring positions }
}
Here are the maze files that I will be inserting to test it.
mazec 35 \# \# \# \#\# \#\#
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