forked from fatiherikli/language-evolution-simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.js
More file actions
54 lines (45 loc) · 1.08 KB
/
Model.js
File metadata and controls
54 lines (45 loc) · 1.08 KB
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
function Model(size) {
this.width = 51;
this.height = 42;
this.iteration = -1;
this.islands = [];
this.agents = [];
this.eventLog = new EventLog();
this.counter = new Counter();
window.__COUNTER__ = this.counter;
}
Model.prototype.setup = function () {
Object.keys(__ISLANDS__).forEach(function (islandKey) {
this.islands[islandKey] = new Island(islandKey, this);
for (var i = 0; i < __POPULATION__[islandKey]; i++) {
this.agents.push(
new Agent(
this.islands[islandKey],
this,
this.eventLog,
this.counter
)
);
}
}.bind(this));
this.agents.forEach(function (agent) {
agent.setup();
});
};
Model.prototype.step = function () {
this.iteration++;
this.agents.forEach(function (agent) {
agent.step();
});
};
Model.prototype.reset = function () {
this.iteration = -1;
this.islands = [];
this.agents = [];
this.eventLog = new EventLog();
this.counter = new Counter();
// Reset agent ID counter
__agentIdCounter__ = 0;
window.__COUNTER__ = this.counter;
this.setup();
};