⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ca.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.app.tutorial1and2;import sim.engine.*;import sim.field.grid.*;public class CA implements Steppable    {    // 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<width;x++)            for(int y=0;y<height;y++)                {                count = 0;                // count the number of neighbors around the cell,                // and for good measure include the cell itself                for(int dx = -1; dx < 2; dx++)                    for(int dy = -1; dy < 2; dy++)                        count += tempGrid.field[tempGrid.stx(x+dx)][tempGrid.sty(y+dy)];                // if the count is 2 or less, or 5 or higher, the cell dies                // else if the count is 3 exactly, a dead cell becomes live again                // else the cell stays as it is                                        if (count <= 2 || count >= 5)  // dead                    tut.grid.field[x][y] = 0;                else if (count == 3) // life                    tut.grid.field[x][y] = 1;                }        }    }

⌨️ 快捷键说明

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