Answered step by step
Verified Expert Solution
Link Copied!

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
1***** Constructs a Robot object which has initially taken zero moves in its forward direction */ public Robot ()
implementation not shown **?
/** Precondition: d 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 counter-clockwise by 90 degrees, its position remains unchanged */ public void turnLeftBy 90()
implementation not shown * Robot rotates clockwise by 90 degrees, its position remains unchanged */ public void turnRightBy 90()
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 r;
/* 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 90 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
image text in transcribed

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

Step: 3

blur-text-image

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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions