Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class MazeSolver { static char[][] maze; static int m, n; // dimensions of the maze; row and col static boolean[][] visited; /* Did: setMaze
public class MazeSolver { static char[][] maze; static int m, n; // dimensions of the maze; row and col static boolean[][] visited; /* Did: setMaze - sets up the board This method will take in a String, file, which is the path of the file we want to look at. Using BufferedReader and FileReader, write this method so that it sets the rows, m, and columns, n, to the first line of input. Then it fills the maze with the maze from the file. */ public static void setMaze(String file) throws IOException { DID } /* Did: isValid - checks if a position on the board has not been visited and is within bounds */ public static boolean isValid(int x, int y) { // modify // check if x and y are within the bounds of the maze if (x = maze.length || y = maze[0].length) { return false; } // check if the position has been visited if (visited[x][y]) { return false; } // check if the position is a wall if (maze[x][y] == '#') { return false; } return true; } /* TODO: solveMaze - recursive function which will traverse the maze and find whether it's solveable S -> G The input is the index that we want to check: x = row, y = column ------ Hint ------- Cell(i,j) -> if its a wall return false Cell(i,j) is G return true Otherwise, mark cell(i,j) as visited (maybe make it a wall) and return if you can find a way out from the top, bottom, left, or right */ public static boolean solveMaze(int x, int y) { // modify HERE!! return false; } /* TODO: solve - sets the maze up, solves the board, print whether it can be solved or not, returns whether its solvable or not */ public static boolean solve(String file) throws IOException { // modify HERE!! System.out.println("Maze can be solved: " + false); return false; }
}
This is an example of a maze.
Thank you. (JAVA)
\#. \#\#\#\#\#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