From e4dc16b27231806e0e982b67cf25e6934138afc9 Mon Sep 17 00:00:00 2001 From: Clement Denis Date: Sun, 14 Jun 2020 20:54:25 +0200 Subject: [PATCH] tron: legacy --- subjects/tron/legacy.html | 386 ++++++++++++++++++++++++++++ subjects/tron/lib/display-canvas.js | 20 ++ 2 files changed, 406 insertions(+) create mode 100644 subjects/tron/legacy.html create mode 100644 subjects/tron/lib/display-canvas.js 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 = () => {}