-
Notifications
You must be signed in to change notification settings - Fork 0
/
BirdsModel.java
97 lines (65 loc) · 2.34 KB
/
BirdsModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package sim.app.birds;
import sim.engine.*;
import sim.field.continuous.*;
import sim.util.*;
import java.util.*;
public class BirdsModel extends SimState {
// The standard world size is 62.5x62.5 km^2
public static double WORLD_SIZE_X = 625.00 / 2.0;
public static double WORLD_SIZE_Y = 625.00 / 2.0;
public static double DISPLAY_SIZE_X = WORLD_SIZE_X * 20;
public static double DISPLAY_SIZE_Y = WORLD_SIZE_X * 20;
//public static int NUM_BIRDS = 300000 / 2 / 2;
public static int NUM_BIRDS = 300;
// The standard signal radius is 100 meters. Since the world is scaled down by
// a factor of 100:
public static double STD_SIGNAL_RADIUS = 1;
public static int SEASON_LENGTH = 50;
private static BirdsModel instance;
public BirdsModel(long seed) { super(seed); instance = this; }
public BirdsModel(long seed, int width, int height, int count) {
super(seed);
instance = this;
}
public static BirdsModel getInstance() {
if (instance == null) {
instance = new BirdsModel(System.currentTimeMillis());
}
return instance;
}
public String getName() { return "Birds"; }
private Season season;
private Stoppable scheduled_birds;
private Continuous2D bird_grid;
public Continuous2D getWorld() { return bird_grid; }
public Season getSeason() { return season; }
public void reschedule(LinkedList<Bird> b) {
scheduled_birds.stop();
Bird[] birds = b.toArray(new Bird[0]);
scheduled_birds = schedule.scheduleRepeating(new RandomSequence(birds));
}
public void start() {
super.start();
season = new Season();
bird_grid = new Continuous2D(1, WORLD_SIZE_X, WORLD_SIZE_Y);
Bird[] birds = new Bird[NUM_BIRDS];
for( int i = 0; i < NUM_BIRDS; i++ ) {
birds[i] = new Bird(i);
Double2D pos = new Double2D(WORLD_SIZE_X * random.nextDouble(),
WORLD_SIZE_Y * random.nextDouble());
birds[i].setPos(pos);
}
scheduled_birds = schedule.scheduleRepeating(new RandomSequence(birds));
schedule.scheduleRepeating(new MultiStep(season, SEASON_LENGTH, true));
}
public double visibility(Double2D pos) {
return pos.x / WORLD_SIZE_X;
}
public double audRange(Double2D pos) {
return 1 - visibility(pos);
}
public static void main(String[] args) {
doLoop(BirdsModel.class, args);
System.exit(0);
}
}