sim.app.tutorial1and2.CA Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mason Show documentation
Show all versions of mason Show documentation
MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.
The newest version!
/*
Copyright 2006 by Sean Luke and George Mason University
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package sim.app.tutorial1and2;
import sim.engine.*;
import sim.field.grid.*;
public class CA implements Steppable
{
private static final long serialVersionUID = 1;
// the width and height will change later
public IntGrid2D tempGrid = new IntGrid2D(0,0);
public void step(SimState state)
{
Tutorial1 tut = (Tutorial1)state;
// first copy the grid into tempGrid
tempGrid.setTo(tut.grid);
// now apply the Game of Life!
// for each cell...
int count;
int width = tempGrid.getWidth();
int height = tempGrid.getHeight();
for(int x=0;x= 5) // dead
tut.grid.field[x][y] = 0;
else if (count == 3) // life
tut.grid.field[x][y] = 1;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy