Question: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class MazeSolver { static char[][] maze; static int m, n; // dimensions of the
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class MazeSolver { static char[][] maze; static int m, n; // dimensions of the maze static boolean[][] visited; // check visited public static void setMaze(String file) throws IOException { BufferedReader br = new BufferedReader(new FileReader(file)); String[] dimensions = br.readLine().split(" "); m = Integer.parseInt(dimensions[0]); n = Integer.parseInt(dimensions[1]); maze = new char[m][n]; visited = new boolean[m][n]; for (int i = 0; i < m; i++) { String line = br.readLine(); for (int j = 0; j < n; j++) { maze[i][j] = line.charAt(j); } } br.close(); } public static boolean isValid(int x, int y) { // check if x and y are within the bounds of the maze if (x < 0 || x >= maze.length || y < 0 || 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: Using a stack, solve the maze WITHOUT recursion. Pseudo: 1) Push start position onto Stack. 2) While it's not empty; 3) Pop from the stack to get the current considered location 4) If it's already explored ignore 5) If it's the goal, return true 6) If it's not the goal, then explore it. 7) You will need to compute all the possible neighbors. Then push those on the stack 8) Return false */ public static boolean solveMazeStack(int x, int y) throws EmptyStackE { return false; } // TODO: Using a queue, solve the maze. Be sure to explain your algorithm for full points. public static boolean solveMazeQueue(int x, int y) throws EmptyQueueE{ return false; } // TODO: Solve the board. Mode 1 = stack solving. Mode 2 = queue solving. // 1: stack // 2: queue public static boolean solve(String file, int mode) throws IOException, EmptyStackE, EmptyQueueE { // find starting point // check if the maze can be solved boolean solved = false; System.out.println("Maze can be solved: " + solved); return false; } }
Please save my life
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
