|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.columbia.cs.coms4701.agent.environments.simple.SimpleEnvironmentObject
edu.columbia.cs.coms4701.agent.environments.grid.SimpleGridMap
public class SimpleGridMap
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.
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 |
---|
public SimpleGridMap()
Method Detail |
---|
public void setRectangle(DiscreteRectangle theRectangle)
setRectangle
in interface GridMap
theRectangle
- public DiscreteRectangle getRectangle()
getRectangle
in interface GridMap
public void updateObjectLocation(GridObject theObject, DiscretePoint2D theLocation)
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!
updateObjectLocation
in interface GridMap
theObject
- theLocation
-
java.lang.RuntimeException
- if the proposed location is not valid.public java.util.Set<GridObject> objectsAtLocation(DiscretePoint2D theLocation)
objectsAtLocation
in interface GridMap
theLocation
-
public boolean locationIsWithinBounds(DiscretePoint2D theLocation)
More complex subclasses may find this useful.
locationIsWithinBounds
in interface GridMap
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |