Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This question involves a simulation of a robot finding the exit of a maze game. You may assume the maze is configured to be always
This question involves a simulation of a robot finding the exit of a maze game. You may assume the maze is configured to be always solvable by the robot, which means the robot will eventually get to the exit
is configured to be always solvable by the robot, which means the robot
public class Robot
Constructs a Robot object which has initially taken zero moves in its forward direction public Robot
implementation not shown
Precondition: can only take a String from "front", "left", or "right"
Returns true if the Robot senses a wall in the direction indicated by a
public boolean hasWall String d
implementation not shown Sets the number of times the Robot has moved forward in total to num
public int setNumMoves int num
Returns true if the Robot is currently at the exit position, false otherwise public boolean isExit
implementation not shown
Robot moves forward by one unit, its orientation remains unchanged public void moveForward
Robot rotates counterclockwise by degrees, its position remains unchanged public void turnLeftBy
implementation not shown Robot rotates clockwise by degrees, its position remains unchanged public void turnRightBy
implementation not shown
There may be additional instance variables, constructors and methods not shown
The maze game is represented by the Maze class. You will write a method of the Maze class.
public class Maze
private Robot
Postcondition: The Robot is properly instantiated to face right in the Maze public Maze
Precondition: The Robot has been properly instantiated in the Maze next to a wall
Postcondition: The Robot will reach the exit and stop moving
publi
To be implemented
There may be additional instance variables, constructors and methods not shown
The Maze class has a solveMaze method, which moves the Robot around in the maze until it reaches the exit and returns the number of times the Robot has changed its orientation, namely, either turned left or right. Keep in mind that at any time during the maze game, the Robot keeps track of the number of moves forward it has taken.
This method procedure:
The Robot always moves forward one unit at a time when no wall is in front of it and a wall is on its right.
As soon as the Robot detects no wall on its right, it turns right by to first ensure there is always a wall
When there is a wall on the right of the Rone unit.
The following example shows the path the "Right Wal
: The Robot has been properly instantiated before invoking this method The Robot will reach the exit and stop its orientation, namely, either turned left or right n: The Robot will reach the exit and stop moving
Step 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