-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.js
74 lines (61 loc) · 1.84 KB
/
debug.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
function cell_to_screen(cell) {
return {
x: (cell % 30 * 4 + 500 - offset_x) * 8,
y: ((0|cell / 30) * 4 + 20 - offset_y) * 8,
};
}
function DEBUG_distance_scores() {
if (!DEBUG)
return true;
for (let [cell, score] of world.entries()) {
if (isNaN(score) || score === 0 || score > 15)
continue;
let {x, y} = cell_to_screen(cell);
if (x > 480 - 32)
continue;
let prev_fill_style = c.fillStyle;
if (cell != critter) {
c.fillStyle = `hsla(
${score * 255 / 15}, 100%, 50%, ${0.2 - score / 75}`;
c.fillRect(x, y, 24, 24);
}
c.fillStyle = `rgba(255, 255, 255, ${0.5 - score / 30}`;
c.font = "16px monospace";
c.fillText(score, x + 2, y + 16);
c.fillStyle = prev_fill_style;
}
return true;
}
function DEBUG_flee_region() {
if (!DEBUG)
return true;
for (let [cell, score] of world.entries()) {
if (isNaN(score) || score === 0 || score > 15)
continue;
let {x, y} = cell_to_screen(cell);
if (x > 480 - 32)
continue;
let prev_fill_style = c.fillStyle;
if (score > world[critter]) {
c.fillStyle = `hsla(
${score * 255 / 15}, 100%, 50%, ${0.33 - score / 45}`;
c.fillRect(x, y, 24, 24);
}
c.fillStyle = prev_fill_style;
}
return true;
}
function DEBUG_critter_deciding(cell, {final}) {
if (!DEBUG)
return true;
let {x, y} = cell_to_screen(cell);
if (x < 480) {
let prev_fill_style = c.fillStyle;
c.fillStyle = final ?
`hsla(128, 100%, 50%, 0.5)`:
`hsla(200, 100%, 50%, 0.5)`;
c.fillRect(x, y, 24, 24);
c.fillStyle = prev_fill_style;
}
return true;
}