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

📄 particle.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.app.tutorial4;import sim.engine.*;import sim.util.*;/** A bouncing particle. */public class Particle implements Steppable    {    public boolean randomize = false;    public int xdir;  // -1, 0, or 1    public int ydir;  // -1, 0, or 1        public int getXDir() { return xdir; }    public int getYDir() { return ydir; }    public boolean getRandomize() { return randomize; }    public void setRandomize(boolean val) { randomize = val; }    public Particle(int xdir, int ydir)        {        this.xdir = xdir;        this.ydir = ydir;        }    public void step(SimState state)        {        Tutorial4 tut = (Tutorial4)state;                // We could just store my location internally, but for purposes of        // show, let's get my position out of the particles grid        Int2D location = tut.particles.getObjectLocation(this);        // leave a trail        tut.trails.field[location.x][location.y] = 1.0;                // Randomize my direction if requested        if (randomize)            {            xdir = tut.random.nextInt(3) - 1;            ydir = tut.random.nextInt(3) - 1;            randomize = false;            tut.collisions++;            }                // move        int newx = location.x + xdir;        int newy = location.y + ydir;                // reverse course if hitting boundary        if (newx < 0) { newx++; xdir = -xdir; }        else if (newx >= tut.trails.getWidth()) {newx--; xdir = -xdir; }        if (newy < 0) { newy++ ; ydir = -ydir; }        else if (newy >= tut.trails.getHeight()) {newy--; ydir = -ydir; }                // set my new location        Int2D newloc = new Int2D(newx,newy);        tut.particles.setObjectLocation(this,newloc);                // randomize everyone at that location if need be        Bag p = tut.particles.getObjectsAtLocation(newloc);        if (p.numObjs > 1)            {            for(int x=0;x<p.numObjs;x++)                ((Particle)(p.objs[x])).randomize = true;            }        }    }

⌨️ 快捷键说明

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