Geoo/THX-01-bucket / snake /index.html
Geoo's picture
download
raw
6.98 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>THX-01 plays Snake</title>
<style>
:root {
--bg: #0e0e0d; --panel: #171716; --line: #2a2a28; --ink: #f4f3ee; --ink2: #b7b5ab; --muted: #7d7b73;
--accent: #3987e5; --food: #e66767; --good: #199e70; --bar: #2b2b29; --cell: #141413;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
header { display: flex; align-items: baseline; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header h1 { font-size: 20px; margin: 0; }
header .sub { color: var(--ink2); font-size: 13px; }
header .sp { flex: 1; }
header button { background: var(--panel); color: var(--ink2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; margin-left: 6px; cursor: pointer; font: inherit; font-size: 12px; }
main { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(340px, 1fr); gap: 16px; padding: 16px 20px; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
.board { background: #000; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
canvas { width: 100%; aspect-ratio: 1; display: block; image-rendering: pixelated; }
.row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.stat .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.card h2 { font-size: 12px; margin: 0 0 10px; color: var(--ink2); text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }
.act { display: grid; grid-template-columns: 64px 1fr 48px; align-items: center; gap: 8px; margin: 6px 0; font-variant-numeric: tabular-nums; }
.act .n { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--ink2); }
.act.on .n { color: var(--ink); font-weight: 700; }
.track { height: 10px; background: var(--bar); border-radius: 5px; overflow: hidden; }
.fill { height: 100%; background: var(--muted); border-radius: 5px; transition: width .08s linear; }
.act.on .fill { background: var(--accent); }
.act .p { text-align: right; font-size: 12px; color: var(--ink2); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12px; }
td, th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 500; }
.ok { color: var(--good); } .bad { color: var(--food); }
pre { margin: 0; white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, monospace; color: #d6d4ca; }
footer { color: var(--muted); font-size: 12px; padding: 0 20px 18px; }
</style>
</head>
<body>
<header>
<h1>THX-01 plays Snake</h1>
<span class="sub">no vision · no text generation · 8 yes/no questions answered in one forward pass per move</span>
<span class="sp"></span>
<span class="sub">speed</span>
<button onclick="sp(4)">slow</button><button onclick="sp(10)">normal</button><button onclick="sp(25)">fast</button>
</header>
<main>
<section>
<div class="board"><canvas id="c" width="640" height="640" aria-label="Snake board played by THX-01"></canvas></div>
<div class="row">
<div class="stat"><div class="k">Score</div><div class="v" id="score">0</div></div>
<div class="stat"><div class="k">Best</div><div class="v" id="best">0</div></div>
<div class="stat"><div class="k">Latency / move</div><div class="v" id="lat">–</div></div>
<div class="stat"><div class="k">Move</div><div class="v" id="mv">–</div></div>
</div>
</section>
<aside>
<div class="card">
<h2>Decision · P(safe) × (0.3 + 0.7·P(toward food))</h2>
<div id="acts"></div>
</div>
<div class="card">
<h2>The 8 typed answers (noul)</h2>
<table><thead><tr><th>direction</th><th>P(safe)</th><th>P(toward food)</th></tr></thead><tbody id="nouls"></tbody></table>
</div>
<div class="card">
<h2>State · the only thing the model reads</h2>
<pre id="state">waiting…</pre>
</div>
<div class="card">
<h2>Games</h2>
<table><thead><tr><th>#</th><th>score</th><th>moves</th><th>end</th></tr></thead><tbody id="games"></tbody></table>
</div>
</aside>
</main>
<footer>THX-01 · RTX 4090 · 0 output tokens · no Snake data in training — the model only reads the state text and answers typed yes/no questions.</footer>
<script>
const D = ["UP", "DOWN", "LEFT", "RIGHT"];
const $ = id => document.getElementById(id);
const cv = $("c"), ctx = cv.getContext("2d");
function sp(v) { fetch("/speed/" + v, {method: "POST"}); }
function draw(e) {
const n = e.w, s = cv.width / n;
ctx.fillStyle = "#0b0b0a"; ctx.fillRect(0, 0, cv.width, cv.height);
ctx.fillStyle = "#141413";
for (let x = 0; x < n; x++) for (let y = 0; y < n; y++) ctx.fillRect(x * s + 1, y * s + 1, s - 2, s - 2);
ctx.fillStyle = "#e66767"; ctx.beginPath(); ctx.arc(e.food[0] * s + s / 2, e.food[1] * s + s / 2, s * 0.36, 0, 7); ctx.fill();
e.body.forEach(([x, y], i) => {
ctx.fillStyle = i === 0 ? "#6fb1ff" : `rgba(57,135,229,${Math.max(0.35, 1 - i / (e.body.length + 4))})`;
ctx.beginPath(); ctx.roundRect(x * s + 2, y * s + 2, s - 4, s - 4, 6); ctx.fill();
});
if (e.dead) { ctx.fillStyle = "rgba(0,0,0,.55)"; ctx.fillRect(0, 0, cv.width, cv.height);
ctx.fillStyle = "#f4f3ee"; ctx.font = "bold 36px system-ui"; ctx.textAlign = "center"; ctx.fillText("game over · " + e.score, cv.width / 2, cv.height / 2); }
}
const es = new EventSource("/events");
es.onmessage = m => {
const e = JSON.parse(m.data);
if (e.type === "over") return;
draw(e);
$("score").textContent = e.score; $("best").textContent = e.best; $("lat").textContent = e.latency_ms.toFixed(1) + " ms"; $("mv").textContent = e.move;
$("acts").innerHTML = D.map(d => `<div class="act${d === e.move ? " on" : ""}"><span class="n">${d}</span><div class="track"><div class="fill" style="width:${(100 * e.probs[d]).toFixed(1)}%"></div></div><span class="p">${(100 * e.probs[d]).toFixed(0)}%</span></div>`).join("");
$("nouls").innerHTML = D.map(d => `<tr><td>${d}</td><td class="${e.safe[d] >= .5 ? "ok" : "bad"}">${(100 * e.safe[d]).toFixed(0)}%</td><td>${(100 * e.food_p[d]).toFixed(0)}%</td></tr>`).join("");
$("state").textContent = e.state;
$("games").innerHTML = e.games.slice().reverse().map((g, i) => `<tr><td>${e.games.length - i}</td><td>${g.score}</td><td>${g.steps}</td><td>${g.end}</td></tr>`).join("");
};
</script>
</body>
</html>

Xet Storage Details

Size:
6.98 kB
·
Xet hash:
5e233d665043411eac67a407d16c657554088a3fefa733c5f02ba7a9f554dd0f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.