forked from mljack/deeptraffic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval_webworker.js
37 lines (34 loc) · 1013 Bytes
/
eval_webworker.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
// webworker code for running the evaluation - imports a bunch of code, runs the user supplied net, starts the simulation and finally sends a result back to the main thread
var window = self;
importScripts("convnetjs/convnet.js");
importScripts("convnetjs/util.js");
importScripts("convnetjs/vis.js");
importScripts("convnetjs/deepqlearn.js");
importScripts("convnetjs/helperStuff.js");
headless = true;
function startEvalRun(code) {
eval(code);
importScripts("gameopt.js");
if (typeof brain != 'undefined') {
brain.learning = false;
}
var runs = 500;
var frames = 2000;
var percent = 0;
var mph = doEvalRun(runs, frames, true, function () {
console.log(percent + "% done");
postMessage({
percent: percent
});
percent++;
}, runs * frames / 100);
if (typeof brain != 'undefined') {
brain.learning = true;
}
postMessage({
mph: mph
});
}
onmessage = function (e) {
startEvalRun(e.data);
}