Menu

[solved]-Assignment Write Function Takes 2d Char Array Representing Ascii Maze Returns Hashset Poss Q39040599

In this assignment, you will write a function that takes in a 2Dchar array representing an ASCII maze and returns a HashSet of allpossible paths from a person’s starting position in the maze to itsexit. Movement through these mazes is restricted to fourdirections: up, down, left, and right. All the mazes we pass toyour backtracking function in this program are guaranteed to abideby the following restrictions: • The 2D char array will be arectangle (which means that all rows in the array will have thesame length).
• The 2D char array passed to your backtracking function willcontain only the following characters:
◦ ‘@’ – This character denotes the person in the maze. There willbe exactly one of these characters in the maze (no more and nofewer), and it could appear anywhere in the maze. ◦ ‘e’ – This isthe exit that the person in the maze is trying to reach. There willalways be exactly one exit in the maze (no more and no fewer), andit could appear anywhere in the maze. ◦ ‘#’ – This characterdenotes a wall. The person in the maze cannot step on one of thesespaces.
◦ ‘ ’ – This character denotes a space where the person in the mazeis allowed to walk.
There are no guarantees regarding the number of walls in the mazeor the locations of those walls. It’s possible that the border ofthe maze might not be made up entirely of walls (i.e., it mightcontain spaces), in which case, it’s up to you to make sure theperson in the maze does not go outside the bounds of the 2D array.Note also that the initial positions of the ‘@’ and ‘e’ charactersmay vary from maze to maze.
There are no guarantees regarding the number of walls in the mazeor the locations of those walls. It’s possible that the border ofthe maze might not be made up entirely of walls (i.e., it mightcontain spaces), in which case, it’s up to you to make sure theperson in the maze does not go outside the bounds of the 2D array.Note also that the initial positions of the ‘@’ and ‘e’ charactersmay vary from maze to maze.

When creating a string to denote a path, we indicate eachdirectional movement from the person’s starting position using asingle character: ‘u’ (up), ‘d’ (down), ‘l’ (left), or ‘r’ (right).The characters in each string must be separated with a singlespace. There should be no spaces at the beginning or end of thestring. For example, the strings representing the two paths aboveare as follows (and should be placed into a HashSet to be returnedby the wrapper method that calls your backtracking method):

Method and Class Requirements
Implement the following methods in a class named Pathfinder.
public static HashSet<String> findPaths(char [][] maze) Thismethod receives a 2D char array representing an ASCII maze andreturns a HashSet of strings representing all valid paths from thestarting position (‘@’) to the exit (‘e’) using the formatdescribed above. The maze array will be non-null and non-empty andis guaranteed to be well-formed according to the guarantees givenin the problem statement above. If there are no solutions, youshould return an empty HashSet (rather than returning null). Pleasenote that when your method returns, the maze array must be in thesame state that it was in when this method was called initially,without any changes

Expert Answer


Answer to In this assignment, you will write a function that takes in a 2D char array representing an ASCII maze and returns a Has… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *