Class Bot

java.lang.Object
  extended by Bot

public class Bot
extends Object

A primitive representation of a Bot, drawing from PacMan and Karel J. Robot. Bots have a location, an orientation, and dots which they have eaten (picked up). They can turn and move themselves, and pick up and put down dots.


Field Summary
protected  BotWorld world
          The world the bot lives in (should never be null).
 
Constructor Summary
Bot(BotWorld world)
          Create a new Bot at the origin (0, 0), facing East, with the specified BotWorld.
Bot(BotWorld world, int x, int y)
          Create a new Bot at the specified coordinates, facing East, attached to the specified BotWorld.
Bot(BotWorld world, int x, int y, char dir)
          Create a new Bot at the specified coordinates, facing the specified direction, and attached to the given BotWorld.
 
Method Summary
 boolean eatDot()
          Tries to eat a dot from the world cell at the current location.
 char getDirection()
          Returns the direction toward which the bot faces.
 int getDots()
          Returns the number of dots that the bot has.
 int getX()
          Returns the bot's x coordinate.
 int getY()
          Returns the bot's y coordinate.
 boolean move()
          Tries to move the bot forward one space.
 boolean putDot()
          Tries to put a dot in the world cell at the current location.
 String toString()
          Returns a String description of the Bot, for example: "Bot at (3, 8) facing w with 5 dots."
 char turnLeft()
          Turns the bot counter-clockwise by 90 degrees.
 char turnRight()
          Turns the bot clockwise by 90 degrees.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

world

protected BotWorld world
The world the bot lives in (should never be null).

Constructor Detail

Bot

public Bot(BotWorld world)
Create a new Bot at the origin (0, 0), facing East, with the specified BotWorld.

Parameters:
world - the BotWorld for this Bot to exist in

Bot

public Bot(BotWorld world,
           int x,
           int y)
Create a new Bot at the specified coordinates, facing East, attached to the specified BotWorld.

Parameters:
world - the BotWorld for this Bot to exist in
x - the x coordinate for this Bot's initial position
y - the y coordinate for this Bot's initial position

Bot

public Bot(BotWorld world,
           int x,
           int y,
           char dir)
Create a new Bot at the specified coordinates, facing the specified direction, and attached to the given BotWorld.

Parameters:
world - the BotWorld for this Bot to exist in
x - the x coordinate for this Bot's initial position
y - the y coordinate for this Bot's initial position
dir - the direction the bot should face initially, one of 'n', 's', 'w', 'e'.
Method Detail

eatDot

public boolean eatDot()
Tries to eat a dot from the world cell at the current location. On success, increases this bot's dot count by one. Returns whether the attempt was successful.

Returns:
true if the attempt was successful, otherwise false

getDirection

public char getDirection()
Returns the direction toward which the bot faces.

Returns:
the bot's direction ('n', 's', 'w', or 'e')

getDots

public int getDots()
Returns the number of dots that the bot has.


getX

public int getX()
Returns the bot's x coordinate.

Returns:
the bot's x coordinate

getY

public int getY()
Returns the bot's y coordinate.

Returns:
the bot's y coordinate

move

public boolean move()
Tries to move the bot forward one space. Returns whether the move was successful.

Returns:
true if the move was successful, otherwise false

putDot

public boolean putDot()
Tries to put a dot in the world cell at the current location. On success, decreases this bot's dot count by one. (The dot count cannot become negative.) Returns whether the attempt was successful.

Returns:
true if the attempt was successful, otherwise false

toString

public String toString()
Returns a String description of the Bot, for example: "Bot at (3, 8) facing w with 5 dots."

Overrides:
toString in class Object

turnLeft

public char turnLeft()
Turns the bot counter-clockwise by 90 degrees.

Returns:
the bot's new direction

turnRight

public char turnRight()
Turns the bot clockwise by 90 degrees.

Returns:
the bot's new direction