org.vizzini.example.ant
Class Grid

java.lang.Object
  extended by org.vizzini.example.ant.Grid
All Implemented Interfaces:
Cloneable

public class Grid
extends Object
implements Cloneable

Provides a grid for the artificial ant problem.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
static String GRID_PROPERTY
           
 
Constructor Summary
Grid()
          Construct this object.
 
Method Summary
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Add a PropertyChangeListener for a specific property.
protected  String antToString(String heading)
          Return a string representation of the ant based upon the heading.
 void clear(int x, int y)
          Clear the cell at the given coordinates.
 Object clone()
          Return a clone of this instance.
protected  int count(int type)
          Return the amount of the given item is on the grid.
 int foodConsumed()
          Return the amount of food consumed from the grid.
 int foodCount()
          Return the amount of food on the grid.
 String getHeading()
           
 int getInitialFoodCount()
           
 boolean isAnt(int x, int y)
          Return true if the cell at the given coordinates contains the ant.
 boolean isEmpty(int x, int y)
          Return true if the cell at the given coordinates is empty.
 boolean isFood(int x, int y)
          Return true if the cell at the given coordinates contains food.
 boolean isFootprint(int x, int y)
          Return true if the cell at the given coordinates contains a footprint.
protected  boolean isType(int x, int y, int type)
          Return true if the cell at the given coordinates contains the given type.
 int keepOnGrid(int value)
          Return a coordinate that is on the grid.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove a PropertyChangeListener for a specific property.
 void setAnt(int x, int y, String heading)
          Set the ant at the given coordinates.
 void setFood(int x, int y)
          Set food at the given coordinates.
 void setFootprint(int x, int y)
          Set a footprint at the given coordinates.
 void setHeading(String heading)
           
 int size()
          Return the size of one side of the square grid.
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GRID_PROPERTY

public static final String GRID_PROPERTY
See Also:
Constant Field Values
Constructor Detail

Grid

public Grid()
Construct this object.

Since:
v0.3
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property.

Parameters:
propertyName - The name of the property to listen on.
listener - The PropertyChangeListener to be added.
Since:
v0.3

clear

public void clear(int x,
                  int y)
Clear the cell at the given coordinates.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

clone

public Object clone()
Return a clone of this instance.

Overrides:
clone in class Object
Since:
v0.3

foodConsumed

public int foodConsumed()
Return the amount of food consumed from the grid.

Since:
v0.3

foodCount

public int foodCount()
Return the amount of food on the grid.

Since:
v0.3

getHeading

public String getHeading()
Returns:
Return heading.
Since:
v0.3

getInitialFoodCount

public int getInitialFoodCount()
Returns:
Return initialFoodCount.
Since:
v0.3

isAnt

public boolean isAnt(int x,
                     int y)
Return true if the cell at the given coordinates contains the ant.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

isEmpty

public boolean isEmpty(int x,
                       int y)
Return true if the cell at the given coordinates is empty.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

isFood

public boolean isFood(int x,
                      int y)
Return true if the cell at the given coordinates contains food.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

isFootprint

public boolean isFootprint(int x,
                           int y)
Return true if the cell at the given coordinates contains a footprint.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

keepOnGrid

public int keepOnGrid(int value)
Return a coordinate that is on the grid.

Parameters:
value - Possible grid coordinate.
Since:
v0.3

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property.

Parameters:
propertyName - The name of the property that was listened on.
listener - The PropertyChangeListener to be removed.
Since:
v0.3

setAnt

public void setAnt(int x,
                   int y,
                   String heading)
Set the ant at the given coordinates.

Parameters:
x - X coordinate.
y - Y coordinate.
heading - Ant heading.
Since:
v0.3

setFood

public void setFood(int x,
                    int y)
Set food at the given coordinates.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

setFootprint

public void setFootprint(int x,
                         int y)
Set a footprint at the given coordinates.

Parameters:
x - X coordinate.
y - Y coordinate.
Since:
v0.3

setHeading

public void setHeading(String heading)
Parameters:
heading - the heading to set
Since:
v0.3

size

public int size()
Return the size of one side of the square grid.

Since:
v0.3

toString

public String toString()
Return a string representation of this object.

Overrides:
toString in class Object
Since:
v0.3

antToString

protected String antToString(String heading)
Return a string representation of the ant based upon the heading.

Parameters:
heading - Ant heading.
Since:
v0.3

count

protected int count(int type)
Return the amount of the given item is on the grid.

Since:
v0.3

isType

protected boolean isType(int x,
                         int y,
                         int type)
Return true if the cell at the given coordinates contains the given type.

Parameters:
x - X coordinate.
y - Y coordinate.
type - Cell content type.
Since:
v0.3


Copyright © 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02