edu.columbia.cs.coms4701.agent.environments.grid
Class SimpleGridMap

java.lang.Object
  extended by edu.columbia.cs.coms4701.agent.environments.simple.SimpleEnvironmentObject
      extended by edu.columbia.cs.coms4701.agent.environments.grid.SimpleGridMap
All Implemented Interfaces:
EnvironmentObject, GridMap

public class SimpleGridMap
extends SimpleEnvironmentObject
implements GridMap

Represents an environment object that can be used to keep track of the location of other objects in a 2-dimensional grid.

Initially, a rectangular location and size are set. Then, environment objects can be set to particular locations (the GridMap should take care of updating the location of GridObjects, so the environment only has to manipulate locations once.)

GridObjects can be queried directly for their location, or the GridMap can be queried to find out what objects are in a particular location.

Version:
0.1

User: aaron Date: Aug 25, 2006 Time: 2:38:50 PM

Author:
aaron@cs

Field Summary
 
Fields inherited from class edu.columbia.cs.coms4701.agent.environments.simple.SimpleEnvironmentObject
changeSupport
 
Constructor Summary
SimpleGridMap()
           
 
Method Summary
 DiscreteRectangle getRectangle()
          Returns the location and size of the map.
 boolean locationIsWithinBounds(DiscretePoint2D theLocation)
          Returns true if the given location is within the bounds of the map.
 java.util.Set<GridObject> objectsAtLocation(DiscretePoint2D theLocation)
          Returns a set (possibly empty) of the environment objects known to be present at the given location.
 void setRectangle(DiscreteRectangle theRectangle)
          Sets the location and size of the map.
 void updateObjectLocation(GridObject theObject, DiscretePoint2D theLocation)
          Updates the location of a GridObject.
 
Methods inherited from class edu.columbia.cs.coms4701.agent.environments.simple.SimpleEnvironmentObject
addPropertyChangeListener, isAlive, removePropertyChangeListener, setAlive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.columbia.cs.coms4701.agent.EnvironmentObject
addPropertyChangeListener, isAlive, removePropertyChangeListener, setAlive
 

Constructor Detail

SimpleGridMap

public SimpleGridMap()
Method Detail

setRectangle

public void setRectangle(DiscreteRectangle theRectangle)
Sets the location and size of the map.

Subinterfaces might permit fancier shapes than mere rectangles.

Specified by:
setRectangle in interface GridMap
Parameters:
theRectangle -

getRectangle

public DiscreteRectangle getRectangle()
Returns the location and size of the map.

Specified by:
getRectangle in interface GridMap
Returns:
rectangle representing the boundaries of the map.

updateObjectLocation

public void updateObjectLocation(GridObject theObject,
                                 DiscretePoint2D theLocation)
Updates the location of a GridObject.

The method should update both the object's location property, and whatever internal mechanism is used to permit efficient querying of locations for present objects.

Note that the method should also make sure to remove the old record of the object's location, if it has a current location!

Specified by:
updateObjectLocation in interface GridMap
Parameters:
theObject -
theLocation -
Throws:
java.lang.RuntimeException - if the proposed location is not valid.

objectsAtLocation

public java.util.Set<GridObject> objectsAtLocation(DiscretePoint2D theLocation)
Returns a set (possibly empty) of the environment objects known to be present at the given location.

Specified by:
objectsAtLocation in interface GridMap
Parameters:
theLocation -
Returns:
zero or more GridObjects known to be at the given location.

locationIsWithinBounds

public boolean locationIsWithinBounds(DiscretePoint2D theLocation)
Returns true if the given location is within the bounds of the map.

More complex subclasses may find this useful.

Specified by:
locationIsWithinBounds in interface GridMap
Returns:
true if location is "on" the map, false otherwise