📄 swarmgame.java
字号:
package sim.app.swarmgame;import sim.engine.*;import sim.util.*;import sim.field.continuous.*;public class SwarmGame extends SimState { public Continuous2D agents; public double width = 100; public double height = 100; public int numAgents = 100; public double jump = 0.5; // how far do we move in a timestep? public double stalker_v = 0.5; public double avoider_v = 0.5; public double defender_v = 0.0; public double aggressor_v = 0.0; public double random_v = 0.0; // some properties to appear in the inspector public double getGoTowardsA() { return stalker_v; } public void setGoTowardsA(double val) { stalker_v = val; } public double getGoAwayFromB() { return avoider_v; } public void setGoAwayFromB(double val) { avoider_v = val; } public double getGoBetweenAAndB() { return defender_v; } public void setGoBetweenAAndB(double val) { defender_v = val; } public double getGetBehindBFromA() { return aggressor_v; } public void setGetBehindBFromA(double val) { aggressor_v = val; } public double getMoveRandomly() { return random_v; } public void setMoveRandomly(double val) { random_v = val; } /** Creates a SwarmGame simulation with the given random number seed. */ public SwarmGame(long seed) { super(new ec.util.MersenneTwisterFast(seed), new Schedule(1)); } public void start() { super.start(); // set up the agents field agents = new Continuous2D(width,width,height); // make a bunch of agents and schedule 'em for(int x=0;x<numAgents;x++) { Agent agent = new Agent(); agents.setObjectLocation(agent, new Double2D(random.nextDouble()*width, random.nextDouble() * height)); schedule.scheduleRepeating(agent); } // have them pick their A and B targets for(int x=0;x<agents.allObjects.numObjs;x++) { ((Agent)(agents.allObjects.objs[x])).pick(this); } } public static void main(String[] args) { doLoop(SwarmGame.class, args); System.exit(0); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -