diff --git a/subjects/tron/legacy.html b/subjects/tron/legacy.html new file mode 100644 index 00000000..927cb4a9 --- /dev/null +++ b/subjects/tron/legacy.html @@ -0,0 +1,386 @@ + + + + Tron + + + + + + +
+ + +
+
+

AI-0

+ LOADING +
+ 0 +
+ +
+

AI-1

+ LOADING +
+ 0 +
+
+
+
+
+
+
+ > scroll or keys to move step by step, click to jump. (shift = fast) + +
+
+ + + diff --git a/subjects/tron/lib/display-canvas.js b/subjects/tron/lib/display-canvas.js new file mode 100644 index 00000000..ebd49ee2 --- /dev/null +++ b/subjects/tron/lib/display-canvas.js @@ -0,0 +1,20 @@ +const state = new Float32Array(100 * 100 * 2) +const [canvas] = document.getElementsByTagName('canvas') + +const ctx = canvas.getContext('2d') +const memo = fn => (c => a => c[a] || (c[a] = fn(a)))(Object.create(null)) +const toHex = memo(color => '#'+ `00000${color.toString(16)}`.slice(-6)) +export const colorize = (x, y, color) => { + ctx.fillStyle = toHex(color) + ctx.fillRect(x * 12, y * 12, 12, 12) +} + +export const move = (x, y, color, turn) => { + const index = (x * 100 + y) * 2 + if (state[index]) return state[index] + state[index] = turn + colorize(x, y, color) +} + +export const update = () => {} +export const reset = () => {}