vacworld
Class VacuumState

java.lang.Object
  extended by agent.State
      extended by vacworld.VacuumState

public class VacuumState
extends State

Represents a state in the vacuum world.


Field Summary
static int CLEAR
          Constant representing a clear location.
static int DIRT
          Constant representing a dirty location.
static int WALL
          Constant representing a location with an obstacle.
 
Constructor Summary
VacuumState(int[][] map)
          Construct a new vacuum state given an array that specifies the map.
 
Method Summary
 boolean bumped()
          Return true if the agent bumped into an obstacle on its previous move.
 void display()
          Print an output of the state to the screen.
 void display(java.io.PrintStream output)
          Print an output of the state to a print stream.
static void fillUnreachableSquares(VacuumState state)
           
 int getAgentDir()
          Return the agent's orientation.
 java.lang.String getAgentDirString()
          Return a string the represents the agent's orientation.
 int getAgentX()
          Return the agent's X position.
 int getAgentY()
          Return the agent's Y position.
static VacuumState getInitState()
          Return the default initial state for the vacuum world.
 int getNumDirtyLocs()
          Return the number of dirty locations in the state.
static VacuumState getRandomState()
          Return a random initial state for the vacuum world.
static VacuumState getRandomState(int randSeed)
          Return a random initial state for the vacuum world using a specific seed.
 boolean hasDirt(int x, int y)
          Return true if the specified location has dirt in it.
 boolean hasObstacle(int x, int y)
          Return true if the specified location has an obstacle in it.
 boolean inBounds(int x, int y)
          Return true if the location is within bounds of the state's map.
 boolean isRobotOff()
          Return true if the robot is turned off in the state.
 void removeDirt(int x, int y)
          Remove dirt from the specified location.
 void setAgentDir(int dir)
          Change the agent's orientation.
 void setAgentX(int x)
          Change the agent's X position.
 void setAgentY(int y)
          Change the agent's Y position.
 void setBump(boolean bump)
          Set an indicator that the robot bumped into an obstacle during its previous move.
 void setRobotOff(boolean off)
          Set an indicator that the robot has shut down in the state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLEAR

public static final int CLEAR
Constant representing a clear location.

See Also:
Constant Field Values

DIRT

public static final int DIRT
Constant representing a dirty location.

See Also:
Constant Field Values

WALL

public static final int WALL
Constant representing a location with an obstacle.

See Also:
Constant Field Values
Constructor Detail

VacuumState

public VacuumState(int[][] map)
Construct a new vacuum state given an array that specifies the map.

Method Detail

getInitState

public static VacuumState getInitState()
Return the default initial state for the vacuum world.


getRandomState

public static VacuumState getRandomState()
Return a random initial state for the vacuum world. The agent's initial location, dirt locations and other obstacles are random. This method fills in areas that are impossible to reach with walls.


getRandomState

public static VacuumState getRandomState(int randSeed)
Return a random initial state for the vacuum world using a specific seed. The agent's initial location, dirt locations and other obstacles are random. This method fills in areas that are impossible to reach with walls.


fillUnreachableSquares

public static void fillUnreachableSquares(VacuumState state)

getAgentX

public int getAgentX()
Return the agent's X position.


getAgentY

public int getAgentY()
Return the agent's Y position.


getAgentDir

public int getAgentDir()
Return the agent's orientation. Note that the constants in the Direction class are used to interpret the meaning of this result.


getAgentDirString

public java.lang.String getAgentDirString()
Return a string the represents the agent's orientation.


setAgentX

public void setAgentX(int x)
Change the agent's X position.


setAgentY

public void setAgentY(int y)
Change the agent's Y position.


setAgentDir

public void setAgentDir(int dir)
Change the agent's orientation.


setRobotOff

public void setRobotOff(boolean off)
Set an indicator that the robot has shut down in the state.


setBump

public void setBump(boolean bump)
Set an indicator that the robot bumped into an obstacle during its previous move.


removeDirt

public void removeDirt(int x,
                       int y)
Remove dirt from the specified location.


hasDirt

public boolean hasDirt(int x,
                       int y)
Return true if the specified location has dirt in it.


hasObstacle

public boolean hasObstacle(int x,
                           int y)
Return true if the specified location has an obstacle in it.


bumped

public boolean bumped()
Return true if the agent bumped into an obstacle on its previous move.


inBounds

public boolean inBounds(int x,
                        int y)
Return true if the location is within bounds of the state's map.


isRobotOff

public boolean isRobotOff()
Return true if the robot is turned off in the state.


getNumDirtyLocs

public int getNumDirtyLocs()
Return the number of dirty locations in the state.


display

public void display(java.io.PrintStream output)
Print an output of the state to a print stream. This output includes a map as well as information about the agent's location and the direction it is facing. On the map, "A" denotes the agent, "*" denotes dirt, and "X" denotes an obstacle. Depending on the direction the agent is facing, it may also be displayed as "<", "V", or ">".


display

public void display()
Print an output of the state to the screen. This output includes a map as well as information about the agent's location and the direction it is facing. On the map, "A" denotes the agent, "*" denotes dirt, and "X" denotes an obstacle. The user must press ENTER to continue.

Specified by:
display in class State