Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 youimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago