lightcycles.java

来自「MASON代表多主体邻里或网络仿真(Multi-Agent Simulator 」· Java 代码 · 共 60 行

JAVA
60
字号
package sim.app.lightcycles;import sim.engine.*;import sim.field.grid.*;import ec.util.*;import java.io.*;public class LightCycles extends SimState    {    public int gridHeight;    public int gridWidth;    public int cycleCount;        // The intGrid holds the walls drawn behind the cycles...    public IntGrid2D grid;    // while the sparsegrid holds the cycles themselves.    public SparseGrid2D cycleGrid;    /** Creates a LightCycles simulation with the given random number seed. */    public LightCycles(long seed)        {        this(seed, 100, 100, 10);        }            public LightCycles(long seed, int width, int height, int count)        {        super(new MersenneTwisterFast(seed), new Schedule(2));        gridWidth = width; gridHeight = height; cycleCount = count;        createGrids();        }    protected void createGrids()        {        grid = new IntGrid2D(gridWidth, gridHeight,0);        cycleGrid = new SparseGrid2D(gridWidth, gridHeight);        }        /** Resets and starts a simulation */    public void start()        {        super.start();  // clear out the schedule                // make new grids        createGrids();        // Create the cycles, add to both grid and schedule        for(int x=0;x<cycleCount;x++)            {            Cycle c = new Cycle(x+5, random.nextInt(4)+1);            cycleGrid.setObjectLocation(c, random.nextInt(gridWidth), random.nextInt(gridHeight));            c.stopper = schedule.scheduleRepeating(c);            }        }        public static void main(String[] args)        {        doLoop(LightCycles.class, args);        System.exit(0);        }        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?