uchicago.src.repastdemos.life
Class LifeModel
java.lang.Object
uchicago.src.sim.engine.SimModelImpl
uchicago.src.sim.engine.SimpleModel
uchicago.src.repastdemos.life.LifeModel
- All Implemented Interfaces:
- DescriptorContainer, SimEventProducer, SimModel
public class LifeModel
- extends SimpleModel
An implementation of Conway's game of Life. This is implemented
here on both a bounded toroidal grid and on an "infinite"
space. The infinite space is in fact a really large sparse matrix,
see InfiniteLifeSpace.java for more.
This is an implementation of John Conway's game of life. Life is
typically played on an "infinite" square grid. Each cell can be
either live or dead. A cell comes to life if it has three
neighboring live cells, and will die of "loneliness" if it has less
than two neighbors, and will die of overcrowding if it has more
than three neighbors.
Particular starting patterns of live cells can yield some very
interesting results. This implementation provides a rather bland
random initialization as well as the R-Pentimino. You can create
your own starting pattern by choosing Empty as the initial pattern
and stepping one tick into the simulation to show the display. You
can then click on the display to add live cells wherever you
want. Percent full is used to specify the percent full for the
random initial pattern. This implementation provides an "infinite"
(a really large) grid as well as a torus of user-defined size. When
using the the infinite space you can scroll the display to see
what's happening off-screen. Make sure the display frame has focus,
and then press the arrow keys to scroll the display.
The web is littered with web pages devoted to Conway's Life. One
such is http://www.math.com/students/wonders/life/life.html.
This simulation uses SimpleModel as its base class. As such all the
behavoir begins with LifeModel's step(), and postStep() method.
Every tick each checks if it has 2 or 3 neighbors. If so, it continues
to live, else it dies. LifeAgents do not die immediately. They are
added to a deathList and then removed from the main list of agents
(agentList) in postStep(). After this check is done for every agent,
we call step on the space. This if any empty space is surrounded by
3 and only 3 agents. If so a new agent is born. Like death, birth is
delayed until postStep().
| Methods inherited from class uchicago.src.sim.engine.SimpleModel |
atEnd, atPause, begin, buildSchedule, getInitParam, getName, getNextDoubleFromTo, getNextIntFromTo, getSchedule, preStep, run, runAutoStep, setRngSeed, setStoppingTime, setStoppingTime |
| Methods inherited from class uchicago.src.sim.engine.SimModelImpl |
addPropertyListener, addSimEventListener, clearMediaProducers, clearPropertyListeners, fireBooleanPropertyEvent, fireEndSim, fireNumericPropertyEvent, fireObjectPropertyEvent, firePauseSim, fireSimEvent, fireStopSim, fireStringPropertyEvent, generateNewSeed, getController, getMediaProducers, getModelManipulator, getParameterDescriptors, getPropertiesValues, getRngSeed, getTickCount, pause, registerDisplaySurface, registerMediaProducer, removePropertyListener, removeSimEventListener, setController, stop |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LifeModel
public LifeModel()
getInitialPattern
public uchicago.src.repastdemos.life.LifeModel.ISetup getInitialPattern()
setInitialPattern
public void setInitialPattern(uchicago.src.repastdemos.life.LifeModel.ISetup val)
getWidth
public int getWidth()
setWidth
public void setWidth(int val)
getHeight
public int getHeight()
setHeight
public void setHeight(int val)
getPercentFull
public float getPercentFull()
setPercentFull
public void setPercentFull(float val)
getInfinite
public boolean getInfinite()
setInfinite
public void setInfinite(boolean val)
buildModel
public void buildModel()
- Overrides:
buildModel in class SimpleModel
setup
public void setup()
- Description copied from interface:
SimModel
- Prepares a model for a new run, typically by deallocating objects or
setting them to some reasonable default. Called whenever the setup button
is clicked or if operating in batch mode whenever a single run has ended in
preparation for the next. Also called when the model is first loaded.
- Specified by:
setup in interface SimModel- Overrides:
setup in class SimpleModel
removeAgent
public void removeAgent(LifeAgent agent)
addAgent
public void addAgent(LifeAgent agent)
step
public void step()
- Overrides:
step in class SimpleModel
postStep
public void postStep()
- Overrides:
postStep in class SimpleModel
main
public static void main(java.lang.String[] args)