forked from 50m30n3/Neurobots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
122 lines (96 loc) · 3.38 KB
/
stats.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var statdelay;
var time = new Date().getTime();
var fps, smoothfps = 0;
var selected;
var stats = [];
function botstats( braindump )
{
if( selected == -1 )
{
document.getElementById( "botstats" ).style.display = "none";
document.getElementById( "worldopts" ).style.display = "block";
return;
}
document.getElementById( "botstats" ).style.display = "block";
document.getElementById( "worldopts" ).style.display = "none";
document.getElementById( "botgenspan" ).innerHTML = bots[selected].generation;
document.getElementById( "botagespan" ).innerHTML = bots[selected].age;
document.getElementById( "botdepthspan" ).innerHTML = bots[selected].braindepth;
document.getElementById( "botsizespan" ).innerHTML = bots[selected].brainsize;
document.getElementById( "botfoodspan" ).innerHTML = Math.round( bots[selected].foodlevel );
document.getElementById( "botratespan" ).innerHTML = bots[selected].mutationrate.toFixed(4);
document.getElementById( "botchildspan" ).innerHTML = bots[selected].children;
document.getElementById( "botdotsspan" ).innerHTML = bots[selected].dotseaten;
if( braindump )
{
document.getElementById( "braindata" ).value = bots[selected].getdata();
refreshlist();
}
bctx = document.getElementById( "brain" ).getContext( "2d" );
bctx.clearRect( 0, 0, 160, 160 );
for( var x=0; x<bots[selected].brainsize; x++ )
for( var y=0; y<bots[selected].braindepth; y++ )
{
var act = Math.round( bots[selected].neurons[y][x].activation*255.0 );
bctx.fillStyle = "rgb( "+act+", "+act+", "+act+" )";
bctx.fillRect( x*10, y*10, 10, 10 );
}
}
function do_stats()
{
var currstats = {};
var age, rate;
currstats.population = bots.length;
currstats.foodcount = food.length;
age = 0;
rate = 0;
for( var i in bots )
{
age += bots[i].age;
rate += bots[i].mutationrate;
}
currstats.avgage = age / bots.length;
currstats.avgrate = rate / bots.length;
document.getElementById( "popspan" ).innerHTML = currstats.population;
document.getElementById( "foodspan" ).innerHTML = currstats.foodcount;
document.getElementById( "agespan" ).innerHTML = Math.round(currstats.avgage);
document.getElementById( "ratespan" ).innerHTML = currstats.avgrate.toFixed(4);
smoothfps = smoothfps*0.9+fps*0.1;
document.getElementById( "fpsspan" ).innerHTML = Math.round( smoothfps );
stats.unshift( currstats );
if( stats.length >= 500 )
stats.pop();
var sctx = document.getElementById( "stats" ).getContext( "2d" );
sctx.clearRect( 0, 0, 500, 102 );
for( var i=0; i<=10; i++ )
{
sctx.beginPath();
sctx.moveTo( 0, i*10+1 );
sctx.lineTo( 500, i*10+1 );
sctx.strokeStyle = "rgb( 200, 200, 200 )"
sctx.stroke();
}
sctx.strokeStyle = "rgb( 0, 0, 0 )"
sctx.strokeRect( 0, 0, 500, 102 );
sctx.beginPath();
for( var i in stats )
sctx.lineTo( 499-i, 101-stats[i].avgage/100.0 );
sctx.strokeStyle = "rgb( 0, 0, 255 )"
sctx.stroke();
sctx.beginPath();
for( var i in stats )
sctx.lineTo( 499-i, 101-stats[i].avgrate*100.0 );
sctx.strokeStyle = "rgb( 0, 0, 0 )"
sctx.stroke();
sctx.beginPath();
for( var i in stats )
sctx.lineTo( 499-i, 101-(stats[i].foodcount/((foodradius*foodradius)/2000)*100) );
sctx.strokeStyle = "rgb( 0, 255, 0 )"
sctx.stroke();
sctx.beginPath();
for( var i in stats )
sctx.lineTo( 499-i, 101-(stats[i].population/((worldsize*worldsize)/15000)*100/4) );
sctx.strokeStyle = "rgb( 255, 0, 0 )"
sctx.stroke();
botstats( false );
}