java.lang.Object | +--net.jmge.prj.csprings.Springlet
To code your own rule or rulespace that will install into Cellsprings, you simply subclass this class. You must do a minimum of two things in your subclass. First, you must provide a default (i.e., parameterless) constructor that passes some parameters back to the superclass constructor. Second, you must override the computeCell() method. Normally, however, you will go beyond the minimum class definition and override a couple of other methods - so as to create a rulespace (parameterized rule) rather than a hardcoded rule, provide a description to the user, etc.
You should know that in general the system takes a laissez faire attitude toward your code, and for the most part doesn't insulate itself from mistakes. For example, you could mess things up royally by writing to the inherited instance variables, so treat them as though they were read-only.
A word about the cellSize field. In Cellsprings, a rule's cellsize is part of its basic definition. Whether or not your springlet parameterizes cellsize, you must pass a default value for the cellSize field back to the superclass at construction.
Another thing to note is that there is a distinction between "update time" and "edit time". The state-related inherited instance variables - mCells and the index arrays - are valid only at update time, i.e., in the beforeUniversePass() and computeCell() methods. Don't try to read them elsewhere. On the other hand, the cellSize field is always valid, though it can change only at edit time.
| Field Summary | |
protected int |
cellSize
The rule's "cellsize", meaning that valid cell values are confined to the range 0..cellSize-1. |
protected int[] |
iE
Table of precalculated neighbor indices for the current universe, where iE[i] maps the current cell's column index to its modular increment, i.e., the column index of the toroidal East neighbor. |
protected int[] |
iW
(West) Like iE, but a decrement map. |
protected int[] |
jN
(North) Like jS, but a decrement map. |
protected int[] |
jS
Table of precalculated neighbor indices for the current universe, where jS[j] maps the current cell's row index to its modular increment, i.e., the row index of the toroidal South neighbor. |
protected static int |
MAX_CELLSIZE
Cellsprings will not run rules with cellsizes that exceed this value (currently 256); your rule's default cellsize must be between 2 and MAX_CELLSIZE, inclusive. |
protected short[][] |
mCells
The entire CA cell matrix at time t. |
| Constructor Summary | |
protected |
Springlet(int cellsize,
boolean cellsize_parameterized,
java.lang.String[][] paramdefs)
This is the only constructor, hence subclasses are required to call it in their own constructors, which themselves must not take parameters. |
| Method Summary | |
protected void |
beforeUniversePass()
An optional override that provides the opportunity to do any setup that might need doing prior to each universe pass. |
protected java.lang.Object |
clone()
If your subclass defines any mutable instance variables, you should override this method to enable Cellsprings to manage your springlet properly. |
protected abstract int |
computeCell(int i,
int j)
You are required to override this method - it's the cell update method whose definition constitutes your rule proper. |
java.lang.String[] |
getDescription()
Override this method to provide some textual info about your rule or rule-family to the Cellsprings end-user. |
protected boolean |
parameterChanged(java.lang.String name,
java.lang.String value)
Override this method only if you have defined your own runtime parameters. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final int MAX_CELLSIZE
cellSizeprotected short[][] mCells
protected int[] iE
iWprotected int[] iW
iEprotected int[] jS
jNprotected int[] jN
jSprotected int cellSize
MAX_CELLSIZE| Constructor Detail |
protected Springlet(int cellsize,
boolean cellsize_parameterized,
java.lang.String[][] paramdefs)
cellsize - Default number of allowable cellstates under your rulespace, from 2 to
MAX_CELLSIZE.cellsize_parameterized - Pass 'true' to allow the user to change the cellSize field.paramdefs - An array of key-value pairs, defining parameters for the user to set.
For best results, parameter names should be short and devoid of spaces.
Also, don't use the name "C", as it is reserved for system use. If
you don't want to define any parameters of your own, pass 'null'.| Method Detail |
public java.lang.String[] getDescription()
protected boolean parameterChanged(java.lang.String name,
java.lang.String value)
name - The name of the parameter that has been updated.value - The new value for the parameter.protected void beforeUniversePass()
protected abstract int computeCell(int i,
int j)
protected short[][] mCells; // current cell matrix protected int[] iE, iW, jS, jN; // toroidal nearest-neighbor indices protected int cellSize; // (since it may be parameterized)Of course, since you have access to the entire cell matrix, you are free to define the neighborhood and universe topology differently from the nearest-neighbor and toroidal implied by the inherited index arrays. "It's your CA, we just connect you to it."
i - Column index of current cell.j - Row index of current cell.mCells,
iE,
iW,
jS,
jN,
cellSizeprotected java.lang.Object clone()
clone in class java.lang.Object