cs1705
Class VPIRobot

java.lang.Object
  extended byjava.util.Observable
      extended bykareltherobot.ur_Robot
          extended bykareltherobot.Robot
              extended bycs1705.Robot
                  extended bycs1705.TestableRobot
                      extended bycs1705.VPIRobot
All Implemented Interfaces:
kareltherobot.Directions, Runnable

public class VPIRobot
extends TestableRobot

A class that represents a robot. This code is based upon Begin's Karel J. Robot work, but has additional VPI functionality and better API documentation.

Version:
2003.07.31
Author:
Peter DePasquale

Nested Class Summary
 
Nested classes inherited from class kareltherobot.ur_Robot
kareltherobot.ur_Robot.ConnectStrategy
 
Nested classes inherited from class kareltherobot.Directions
kareltherobot.Directions.Direction
 
Field Summary
 
Fields inherited from interface kareltherobot.Directions
East, EastVal, infinity, North, NorthVal, South, SouthVal, West, WestVal
 
Constructor Summary
VPIRobot()
          Default constructor which places Karel at the intersection of 1st street and 1st avenue, holding no beepers, and facing north.
VPIRobot(int street, int avenue, kareltherobot.Directions.Direction direction, int numberOfBeepers)
          Constructor which supports the specific placement, orientation and setting the number of beepers for Karel.
 
Method Summary
 boolean anyBeepersInBeeperBag()
          Check whether the robot has any beepers in its bag.
 int countBeepersInPile()
          Returns the number of beepers in the beeper pile (if any ) at the intersection where Karel is located.
 boolean facingEast()
          Checks whether Karel is currently facing east.
 boolean facingNorth()
          Checks whether Karel is currently facing north.
 boolean facingSouth()
          Checks whether Karel is currently facing south.
 boolean facingWest()
          Checks whether Karel is currently facing west.
 boolean frontIsClear()
          Check to see if Karel is currently blocked by some obstacle directly in front.
 void move()
          Moves the robot one space (intersection) forward in the direction the robot is currently facing.
 boolean nextToABeeper()
          Checks whether Karel is currently at an intersection that also contains a beeper pile of one or more beepers.
 boolean nextToARobot()
          Checks whether Karel is currently at an intersection that also contains another robot.
 void pickBeeper()
          Attempts to pick up one beeper from the beeper pile at the intersection where the robot is currently located and place it in the robot's beeper bag.
 void putBeeper()
          Attempts to place one beeper from the robot's beeper bag in the pile at the intersection where this robot is currently located.
 void turnLeft()
          Turns this robot 90 degrees to the left.
 void turnOff()
          Turns off this robot.
 
Methods inherited from class cs1705.TestableRobot
assertAt, assertBeepersInBeeperBag, assertBeepersInBeeperBag, assertFacingEast, assertFacingNorth, assertFacingSouth, assertFacingWest, assertFrontIsBlocked, assertFrontIsClear, assertHasNeighbor, assertHasNoNeighbor, assertNextToABeeper, assertNoBeepersInBeeperBag, assertNotAt, assertNotFacingEast, assertNotFacingNorth, assertNotFacingSouth, assertNotFacingWest, assertNotNextToABeeper, assertNotOnAvenue, assertNotOnStreet, assertNotRunning, assertOnAvenue, assertOnStreet, assertRunning, getWorldAsObject, overrideNextRobotCreation
 
Methods inherited from class kareltherobot.ur_Robot
acceptConnection, acceptConnectionFrom, areYouHere, avenue, connectTo, direction, getNextCommunication, isVisible, neighbors, restoreInitialState, run, running, send, setVisible, showState, street, toString, waitForCommunication, waitForNextCommunication
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VPIRobot

public VPIRobot()
Default constructor which places Karel at the intersection of 1st street and 1st avenue, holding no beepers, and facing north.


VPIRobot

public VPIRobot(int street,
                int avenue,
                kareltherobot.Directions.Direction direction,
                int numberOfBeepers)
Constructor which supports the specific placement, orientation and setting the number of beepers for Karel. Karel is placed at the intersection of the specified street and avenue, facing in the specified direction and holding the specified number of beepers in the beeper bag.

Parameters:
street - street number of Karel's placement
avenue - avenue number of Karel's placement
direction - the direction Karel is pointing in (North, East, South, West)
numberOfBeepers - number of beepers in the beeper bag (>= 0)
Method Detail

anyBeepersInBeeperBag

public boolean anyBeepersInBeeperBag()
Check whether the robot has any beepers in its bag.

Returns:
true if beepers are present in the beeper bag, false otherwise.

countBeepersInPile

public int countBeepersInPile()
Returns the number of beepers in the beeper pile (if any ) at the intersection where Karel is located. If no beepers are present, zero (0) is returned.

Returns:
an integer value representing the number of beepers in the pile at Karel's current location

facingEast

public boolean facingEast()
Checks whether Karel is currently facing east.

Returns:
true if Karel is facing east, false otherwise.

facingNorth

public boolean facingNorth()
Checks whether Karel is currently facing north.

Returns:
true if Karel is facing north, false otherwise.

facingSouth

public boolean facingSouth()
Checks whether Karel is currently facing south.

Returns:
true if Karel is facing south, false otherwise.

facingWest

public boolean facingWest()
Checks whether Karel is currently facing west.

Returns:
true if Karel is facing west, false otherwise.

frontIsClear

public boolean frontIsClear()
Check to see if Karel is currently blocked by some obstacle directly in front.

Returns:
true if Karel is not obstructed, false if Karel's path forward is immediately blocked.

move

public void move()
Moves the robot one space (intersection) forward in the direction the robot is currently facing.


nextToABeeper

public boolean nextToABeeper()
Checks whether Karel is currently at an intersection that also contains a beeper pile of one or more beepers.

Returns:
true if there is a beeper pile present, false otherwise.

nextToARobot

public boolean nextToARobot()
Checks whether Karel is currently at an intersection that also contains another robot.

Returns:
true if there is another robot present, false otherwise.

pickBeeper

public void pickBeeper()
Attempts to pick up one beeper from the beeper pile at the intersection where the robot is currently located and place it in the robot's beeper bag.


putBeeper

public void putBeeper()
Attempts to place one beeper from the robot's beeper bag in the pile at the intersection where this robot is currently located.


turnLeft

public void turnLeft()
Turns this robot 90 degrees to the left.


turnOff

public void turnOff()
Turns off this robot. The robot cannot be turned back on again after issuing this call.