vacworld
Class VacuumState

java.lang.Object
  extended byagent.State
      extended byvacworld.VacuumState

public class VacuumState
extends State

Represents a state in the vacuum world.


Field Summary
protected  int agentDir
           
protected  int agentX
           
protected  int agentY
           
protected  boolean bump
          True if the agent just bumped into something.
static int CLEAR
          Constant representing a clear location.
protected static int[][] defaultMap
           
static int DIRT
          Constant representing a dirty location.
protected static double DIRT_CHANCE
           
protected  int height
          Height of the map, including surrounding walls of the room.
protected static int INIT_DIR
           
protected static int INIT_X
           
protected static int INIT_Y
           
protected  int[][] map
          An array that contains the locations of objects in the world.
protected  int numDirtyLocs
           
protected  boolean robotOff
           
static int WALL
          Constant representing a location with an obstacle.
protected static double WALL_CHANCE
           
protected  int width
          Width of the map, including surrounding walls of the room.
 
Constructor Summary
protected VacuumState()
          Construct a new empty vacuum state.
  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.
 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.
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT_X

protected static int INIT_X

INIT_Y

protected static int INIT_Y

INIT_DIR

protected static int INIT_DIR

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

defaultMap

protected static int[][] defaultMap

DIRT_CHANCE

protected static double DIRT_CHANCE

WALL_CHANCE

protected static double WALL_CHANCE

agentX

protected int agentX

agentY

protected int agentY

agentDir

protected int agentDir

robotOff

protected boolean robotOff

bump

protected boolean bump
True if the agent just bumped into something.


map

protected int[][] map
An array that contains the locations of objects in the world.


numDirtyLocs

protected int numDirtyLocs

height

protected int height
Height of the map, including surrounding walls of the room.


width

protected int width
Width of the map, including surrounding walls of the room.

Constructor Detail

VacuumState

protected VacuumState()
Construct a new empty vacuum state. This should only be called internally, and should be followed by code that initializes the state.


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 position is always the same, but the dirt locations and other obstacles are random. Note, this may generate random states that are impossible for the agent to solve, i.e., dirt may be entirely surrounded by obstacles.


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 be displayed as "<", "^", 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