-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstats.js
More file actions
144 lines (116 loc) · 4.37 KB
/
Copy pathstats.js
File metadata and controls
144 lines (116 loc) · 4.37 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var statdelay;
var time = new Date().getTime();
var fps, smoothfps = 0;
var selected;
var stats = new Array();
function botstats( braindump )
{
var canvaswidth = 400;
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, blockwidth, 100 );
var blockwidth = Math.floor(canvaswidth/bots[selected].vision.length);
for( var x=0; x<bots[selected].vision.length; x++ ) {
var act = Math.round( bots[selected].vision[x]*255.0 );
bctx.fillStyle = "rgb( "+act+", "+act+", "+act+" )";
bctx.fillRect( x*blockwidth, 0, blockwidth, 10 );
}
blockwidth = Math.floor(canvaswidth/bots[selected].brainsize);
for( var x=0; x<bots[selected].brainsize; x++ )
for( var y=0; y<bots[selected].braindepth; y++ )
{
var act = Math.round( bots[selected].brain.neurons[y][x].activation*255.0 );
if( act >= 0)
bctx.fillStyle = "rgb( 0, "+act+", 0 )";
else
bctx.fillStyle = "rgb( "+Math.abs(act)+", 0, 0 )";
bctx.fillRect( x*blockwidth, y*10+10, blockwidth, 10 );
}
blockwidth = Math.floor(canvaswidth/bots[selected].output.length);
for( var x=0; x<bots[selected].output.length; x++ ) {
var act = Math.round( bots[selected].output[x]*255.0 );
if( act >= 0)
bctx.fillStyle = "rgb( 0, "+act+", 0 )";
else
bctx.fillStyle = "rgb( "+Math.abs(act)+", 0, 0 )";
bctx.fillRect( x*blockwidth, 10*bots[selected].braindepth+10, blockwidth, 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*0.5 );
sctx.strokeStyle = "rgb( 0, 255, 0 )"
sctx.stroke();
sctx.beginPath();
for( var i in stats )
sctx.lineTo( 499-i, 101-stats[i].population*0.5 );
sctx.strokeStyle = "rgb( 255, 0, 0 )"
sctx.stroke();
botstats( false );
}