sim
Class BasicMatrixModel

java.lang.Object
  extended bysim.BasicMatrixModel
All Implemented Interfaces:
MatrixModel
Direct Known Subclasses:
BugWorldModel

public abstract class BasicMatrixModel
extends java.lang.Object
implements MatrixModel

This class creates and manages a simple 2D population model.


Constructor Summary
BasicMatrixModel(int r, int c)
          Using the cell counts given, create a new model.
 
Method Summary
 void addView(MatrixView view)
          Add a MatrixView to the current list of views that are looking at this model and want to hear about changes.
static CritterInfo createCritterInfoInstance(Critter me, int life, int repro, int maxCal, int burn, int strength)
          Get a new instance of an object that implements the CritterInfo interface.
 Critter getCritter(int[] loc)
          Get the Critter at the given (row,col) address in the cell array
 int[] getDimensions()
          This method returns an int array containing the dimensions of the Matrix being modelled.
 void step()
          Step the model one simulation step.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicMatrixModel

public BasicMatrixModel(int r,
                        int c)
Using the cell counts given, create a new model.

Parameters:
r - number of rows of cells
c - number of columns of cells
Method Detail

getDimensions

public int[] getDimensions()
Description copied from interface: MatrixModel
This method returns an int array containing the dimensions of the Matrix being modelled. There are as many elements in the array as there are dimensions in the model, and the value of each element is the number of cells along that dimension. For a 2-dimensional model, this method always returns a 2-element array. Element [0] contains the number of rows, and element [1] contains the number of columns.

Specified by:
getDimensions in interface MatrixModel
Returns:
an array containing the dimensions of the model
See Also:
MatrixModel.getDimensions()

addView

public void addView(MatrixView view)
Description copied from interface: MatrixModel
Add a MatrixView to the current list of views that are looking at this model and want to hear about changes.

Specified by:
addView in interface MatrixModel
Parameters:
view - the MatrixView to add to the list for this model
See Also:
MatrixModel.addView(MatrixView)

step

public void step()
Description copied from interface: MatrixModel
Step the model one simulation step.

Specified by:
step in interface MatrixModel
See Also:
MatrixModel.step()

getCritter

public Critter getCritter(int[] loc)
Description copied from interface: MatrixModel
Get the Critter at the given (row,col) address in the cell array

Specified by:
getCritter in interface MatrixModel
Parameters:
loc - a 2-element int array containing the address of the desired cell. The row address is in element [0] and the column address is in element [1].
Returns:
the Critter at the given address or null.
See Also:
MatrixModel.getCritter(int[])

createCritterInfoInstance

public static CritterInfo createCritterInfoInstance(Critter me,
                                                    int life,
                                                    int repro,
                                                    int maxCal,
                                                    int burn,
                                                    int strength)
Get a new instance of an object that implements the CritterInfo interface. This object is used to store a variety of interesting factoids about a Critter. In addition to the parameters supplied here, the CritterInfo object maintains dynamic values such as age and current calories.

This factory method is used instead of a constructor so that a Critter can create only one CritterInfo object to store information about itself.

Parameters:
me - the Critter for which this CritterInfo is being created
life - the life span defined for this Critter, in ticks
repro - time between reproduction events in ticks
maxCal - the maximum number of calories this Critter can store.
burn - the number of calories burned each tick of the clock. minimum is 1.
strength - the maximum strength of this Critter in arbitrary units