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 youMaze class in Java. Other three classes and direction posted as apicture. Please complete the program. Thank you import java.util.ArrayList; public class Maze{ private char[][] cells; /** Constructs a maze from a string describingits contents. @param contents a string consisting of *, spaces, and newlines

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 emptyNeighbors(Location loc) { ArrayList result = new ArrayList(); result.add(new Location(loc.getRow(), loc.getColumn() - 1)); result.add(new Location(loc.getRow(), loc.getColumn() + 1)); result.add(new Location(loc.getRow() - 1, loc.getColumn())); result.add(new Location(loc.getRow() + 1, loc.getColumn()));

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 20

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!