Question
Maze class in Java. Other three classes and direction posted as a picture. Please complete the program. Thank you import java.util.ArrayList; public class Maze {
Maze class in Java. Other three classes and direction posted as a picture. Please complete the program. Thank you
import java.util.ArrayList;
public class Maze { private char[][] cells;
/** Constructs a maze from a string describing its contents. @param contents a string consisting of *, spaces, and newlines terminating the rows. */ public Maze(String contents) { int rows = 0; int columns = 0; int currentLength = 0; for (int i = 0; i
public ArrayList
for (int i = result.size() - 1; i >= 0; i--) { if (!isEmpty(result.get(i))) result.remove(i); } return result; }
/** Checks whether a location is an exit. @param loc the location @return true if the location is an exit */ public boolean isExit(Location loc) { if(loc.getRow() == 0 || loc.getRow() == cells.length -1 ); if(loc.getColumn() == 0 || loc.getColumn() == cells[0].length -1 ); /*-----IMPLEMENT THIS-----*/ return false; }
/** Checks whether a location is within the maze. @param loc the location @return true if the location is valid */ public boolean isValid(Location loc) { // if(contents.charAt(i) = /*-----IMPLEMENT THIS-----*/ return false; }
/** Checks whether a location is within the maze and not a wall. @param loc the location @return true if the location is empty */ public boolean isEmpty(Location loc) { if(cells[loc.getRow()][loc.getColumn()] == ' ') { return true; } /*-----IMPLEMENT THIS-----*/ return false; } }
You are currently located inside a maze. The walls of the maze are indicated by asterisks (*) Use a backtracking approach to find a solution to the maze. Create a MazePartialsolution class with methods to examine and extend ( partial solutions. The recursive step should check whether you can escape from the maze: If you are at an exit, return true. Recursively check whether you can escape from one of the empty neighboring locations without visiting the current location. To help you, finish the implementation for the Maze class provided (see dropbox) and use it where appropriate. You must also implement a MazeSolution class containing the static void solve (MazePartialSolution) method that prints a solution to the maze. For example, the solution to the above maze would look like: *A *@t 20. You are currently located inside a maze. The walls of the maze are indicated by asterisks (*) Use a backtracking approach to find a solution to the maze. Create a MazePartialsolution class with methods to examine and extend ( partial solutions. The recursive step should check whether you can escape from the maze: If you are at an exit, return true. Recursively check whether you can escape from one of the empty neighboring locations without visiting the current location. To help you, finish the implementation for the Maze class provided (see dropbox) and use it where appropriate. You must also implement a MazeSolution class containing the static void solve (MazePartialSolution) method that prints a solution to the maze. For example, the solution to the above maze would look like: *A *@t 20Step 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