Class Robot

java.lang.Object
  |
  +--Robot

public class Robot
extends Object
implements Labeled

This class describes a simple robot that can move forward, turn 90 degree to the left and to the right, and test the possibility of a forward move. The robot has a direction: it looks either to the north, east, south, or west. In this program, the direction is presented by an integer:


Constructor Summary
Robot(int direction)
          Creates a new robot that looks to the given direction.
 
Method Summary
 Room getRoom()
          In which room is this robot located at?
 String label()
          One letter string describing the direction of this robot.
 void setRoom(Room room)
          Sets the room in which this robot is located at.
 void solve(Maze m, Room goal)
          The method tries to move this robot from the current room to the goal room in a maze.
 boolean stepForward()
          You should implement this in exercise 2.1.
 boolean testForward()
          You should implement this in exercise 2.1.
 String toString()
          Redefine the predefined toString method.
 void turnLeft()
          You should implement this in exercise 2.1.
 void turnRight()
          You should implement this in exercise 2.1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Robot

public Robot(int direction)
Creates a new robot that looks to the given direction.
Method Detail

getRoom

public Room getRoom()
In which room is this robot located at?
Returns:
the current room containing the robot or null if the robot is in no room.

setRoom

public void setRoom(Room room)
Sets the room in which this robot is located at.
Parameters:
room - the new location of this robot.

testForward

public boolean testForward()
You should implement this in exercise 2.1. Can this robot move forwards?
Returns:
true if a forward move is possible and false if it is not.

stepForward

public boolean stepForward()
You should implement this in exercise 2.1. Move the robot forwards if it is possible.
Returns:
true if a forward move is possible and false if it is not.

turnLeft

public void turnLeft()
You should implement this in exercise 2.1. Turn the direction of the robot 90 degrees to the left (counterclockwise).

turnRight

public void turnRight()
You should implement this in exercise 2.1. Turn the direction of the robot 90 degrees to the right (clockwise).

label

public String label()
One letter string describing the direction of this robot.
Specified by:
label in interface Labeled
Returns:
"^" if the robot is looking to the North, ">" if the robot is looking to the East, "v" if the robot is looking to the South, and "<" if the robot is looking to the West.

toString

public String toString()
Redefine the predefined toString method.
Overrides:
toString in class Object
Returns:
a string describing this robot

solve

public void solve(Maze m,
                  Room goal)
The method tries to move this robot from the current room to the goal room in a maze. This method should be redefined in the subclasses of Robot.
Parameters:
m - a maze containing the robot
goal - the goal room