vitro.grid
Class GridActor

java.lang.Object
  extended by vitro.Actor
      extended by vitro.grid.GridActor

public class GridActor
extends Actor

GridActor provides a number of convenience methods for Actors that are meant to be part of a Grid model.


Field Summary
protected static int[][] ADJACENT
          A set of x/y deltas for vertically, horizontally and diagonally adjacent cells.
protected static int[][] DIAGONAL
          A set of x/y deltas for diagonally adjacent cells.
protected  Grid model
          A reference to this Actor's Model.
protected static int[][] ORTHOGONAL
          A set of x/y deltas for vertically or horizontally adjacent cells.
 
Constructor Summary
GridActor(Grid model)
          Build a new GridActor associated with a specific Model.
 
Method Summary
 Location location()
          Get the Location of this Actor in the current Model.
 MoveAction move(Location location, Set<Action> options)
          Find an Action corresponding to moving this Actor to a specific Location.
 Set<Action> moves(Set<Location> locations)
          Produce a Set of MoveActions corresponding to moving this Actor to each of a Set of Locations.
 Set<Location> neighbors(int[][] deltas)
          Obtain references to Location objects representing neighboring cells.
 Set<Location> neighbors(Location location, int[][] deltas)
          Obtain references to Location objects representing cells neighboring a specific Location.
 Set<Location> passableNeighbors(int[][] deltas)
          Performs the same function as neighbors(), but only returns Locations which would be passable to a this Actor.
 Set<Location> passableNeighbors(Location location, int[][] deltas)
          Performs the same function as neighbors(), but only returns Locations which would be passable to a this Actor.
 Set<Location> pumpingNeighbors(int[][] deltas)
          Performs the same function as neighbors(), but will "pump on" a delta for as long as the resulting Location is passable to this Actor.
 
Methods inherited from class vitro.Actor
actions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORTHOGONAL

protected static final int[][] ORTHOGONAL
A set of x/y deltas for vertically or horizontally adjacent cells.


DIAGONAL

protected static final int[][] DIAGONAL
A set of x/y deltas for diagonally adjacent cells.


ADJACENT

protected static final int[][] ADJACENT
A set of x/y deltas for vertically, horizontally and diagonally adjacent cells.


model

protected final Grid model
A reference to this Actor's Model.

Constructor Detail

GridActor

public GridActor(Grid model)
Build a new GridActor associated with a specific Model.

Method Detail

location

public Location location()
Get the Location of this Actor in the current Model.

Returns:
this Actor's Location.

neighbors

public Set<Location> neighbors(int[][] deltas)
Obtain references to Location objects representing neighboring cells. See Grid.neighbors().

Parameters:
deltas - a collection of x and y offsets to neighboring cells.
Returns:
a Set of neighboring Locations.

neighbors

public Set<Location> neighbors(Location location,
                               int[][] deltas)
Obtain references to Location objects representing cells neighboring a specific Location. See Grid.neighbors().

Parameters:
location - the origin Location.
deltas - a collection of x and y offsets to neighboring cells.
Returns:
a Set of neighboring Locations.

passableNeighbors

public Set<Location> passableNeighbors(Location location,
                                       int[][] deltas)
Performs the same function as neighbors(), but only returns Locations which would be passable to a this Actor.

Parameters:
location - the origin Location.
deltas - a collection of x and y offsets to neighboring cells.
Returns:
a Set of passable neighboring Locations.

passableNeighbors

public Set<Location> passableNeighbors(int[][] deltas)
Performs the same function as neighbors(), but only returns Locations which would be passable to a this Actor. Deltas are treated as relative to this Actor.

Parameters:
deltas - a collection of x and y offsets to neighboring cells.
Returns:
a Set of passable neighboring Locations.

pumpingNeighbors

public Set<Location> pumpingNeighbors(int[][] deltas)
Performs the same function as neighbors(), but will "pump on" a delta for as long as the resulting Location is passable to this Actor. For example, assuming a passable() method which disallows multiple Actors in the same Grid cell, given DIAGONAL as a set of deltas this method would return valid non-capturing moves for a chess Bishop.

Parameters:
deltas - a collection of x and y offsets to neighboring cells.
Returns:
a Set of passable neighboring Locations.

moves

public Set<Action> moves(Set<Location> locations)
Produce a Set of MoveActions corresponding to moving this Actor to each of a Set of Locations.

Parameters:
locations - the Locations to which this Actor might move.
Returns:
a Set of Moves for this Actor.

move

public MoveAction move(Location location,
                       Set<Action> options)
Find an Action corresponding to moving this Actor to a specific Location.

Parameters:
location - the Actor's desired destination.
options - a Set of Actions to consider.
Returns:
the found MoveAction or null if none is available.