-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
40 lines (33 loc) · 1.36 KB
/
main.js
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
planck.testbed('Neuroevolution-bots', function (testbed) {
var pl = planck, Vec2 = pl.Vec2;
var world = new pl.World(Vec2(0, -10));
const generationPeriod = 10000;
updateUI('gperiod', parseInt(generationPeriod / 1000).toString() + ' seconds');
world.sceneSize = 2;
const pt1 = Vec2(-70.0, -15.0);
const pt2 = Vec2(70.0, -15.0);
const pt3 = Vec2(pt1.x, pt1.y + world.sceneSize * 10);
const pt4 = Vec2(pt2.x, pt2.y + world.sceneSize * 10);
world.createBody().createFixture(pl.Edge(pt1, pt2));
world.createBody().createFixture(pl.Edge(pt1, pt3));
world.createBody().createFixture(pl.Edge(pt2, pt4));
world.vtcl = { min: pt1.y, max: pt3.y };
world.hztl = { min: pt1.x + world.sceneSize * 5, max: pt2.x - world.sceneSize * 5 };
const popSize = 30;
updateUI('popsize', popSize.toString());
var generation;
const algo = sessionStorage.getItem('algo');
if (algo != 'vne'){
generation = new NEAT(world, popSize);
for (var i = 0; i < 100; i++) generation.neat.mutate();
}else{
generation = new Generation(world, popSize);
};
const pretrain = sessionStorage.getItem('pretrain');
generation.initialize(pretrain != 'no');
// Restart Generation every generationPeriod interval
setInterval(() => {
generation.evolve();
}, generationPeriod);
return world;
});