-
Notifications
You must be signed in to change notification settings - Fork 2
/
train.html
82 lines (72 loc) · 1.74 KB
/
train.html
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
<head>
<title>World</title>
<style type="text/css">
canvas{
float:left;
margin-right: 100px;
padding: 0px;
}
</style>
</head>
<body style='background-color: black'>
<canvas id='board'></canvas>
<canvas id='debug'></canvas>
</body>
<script src="./lib/ai.js"></script>
<script src="./lib/world.js"></script>
<script src="./lib/debug.js"></script>
<script src="./config.js"></script>
<script>
var canvas = document.getElementById('board');
canvas.setAttribute('width', config.width*config.scale);
canvas.setAttribute('height', config.height*config.scale);
canvas.setAttribute('style', "border:1px solid lime;background-color:#000000");
//var canvas = document.getElementById("board");
var board = canvas.getContext("2d");
var world = new World(config);
//world.draw(board);
var canvas_debug = document.getElementById('debug');
var titles = {
input: {
0: "x1",
1: "y1",
2: "x2",
3: "y2",
4: "wall left",
5: "wall right",
6: "wall up",
7: "wall down",
8: "food left",
9: "food right",
10: "food up",
11: "food down",
12: "bias"
}
};
World.prototype.debug = function (brain)
{
//brain = new Network([2,2]);
debug (brain,canvas_debug,titles);
};
function draw ()
{
if (world.generation<config.demo || world.generation>=config.train || world.trained)
{
if (world.trained)
{
config.speed = 100;
}
world.run(board);
}
else
{
while (world.generation<config.train && !world.trained)
{
world.run();
}
config.speed = 100;
}
setTimeout(draw, config.speed)
}
draw();
</script>