feat: prompt presets, setup dialog, /games + leaderboard, one-game gate
Backend:
- prompts.py: 5 personality presets (уличный_гопник default, профессор,
поэт, молчун, шут). Each provides voice + label + description.
build_system_prompt accepts `preset` parameter; the MCP-tools section
+ must-call-move rule is shared common tail.
- coordinator: `start_new_game` now accepts `overrides` ({white: {agent,
model, prompt}, black: {...}}) — missing fields filled randomly.
MODEL_OPTIONS published per agent.
- AppState.prompts tracks the preset id per side; persisted into game's
agents dict and PGN.
- AppState.eval_cache cleared on new_game (was per-life-of-process before).
- persistence.save_game now stores full history (with comments) and the
per-position eval cache in the game JSON.
- ChessGame.abort() — manual game termination with result='*' and
Termination='aborted'.
- New endpoints:
• GET /api/options — agents, models per agent, prompt presets.
• GET /api/stats — leaderboard aggregated from games/*.json:
per (agent, model) and per persona, with score = wins + 0.5*draws.
• POST /api/abort-game — force-end current game.
- POST /api/new-game now returns 409 when a game is in progress.
- GET /api/games[/{id}[/pgn]] also 409 while in progress — gallery is
hidden behind the one-game-at-a-time rule.
Frontend:
- New setup dialog: per-side agent / model / persona selects, swap +
random shortcuts, persona description preview, abort button inline
when current game blocks the start.
- 'games & stats' link in the board footer; greyed out while a game is
active.
- /games page reworked: leaderboard (player × model + by persona),
games table with persona labels, replay panel showing eval per ply
with prev/next/first/last + arrow-key nav.
- chess.js loadPgn → load_pgn fix consolidated; replay prefers saved
history (comments + side) over PGN parse when available.
This commit is contained in:
+165
-2
@@ -251,6 +251,7 @@ function applySnapshot(s) {
|
||||
STATE.evalByFen.clear();
|
||||
for (const e of (s.evals || [])) storeEval(e);
|
||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
||||
refreshGamesLink();
|
||||
}
|
||||
|
||||
function connect() {
|
||||
@@ -285,6 +286,9 @@ function connect() {
|
||||
STATE.game.status.termination = ev.termination;
|
||||
}
|
||||
renderStatus();
|
||||
refreshGamesLink();
|
||||
// unlock the setup dialog if it was open and waiting
|
||||
try { refreshSetupGate(); } catch (e) {}
|
||||
log(`game over: ${ev.result} (${ev.termination})`);
|
||||
return;
|
||||
}
|
||||
@@ -298,8 +302,167 @@ connect();
|
||||
|
||||
// ---------- controls ----------
|
||||
$("live-btn").addEventListener("click", goLive);
|
||||
$("new-game").addEventListener("click", async () => {
|
||||
await fetch("/api/new-game", { method: "POST" });
|
||||
// ---------- new game setup dialog ----------
|
||||
let OPTIONS = null;
|
||||
|
||||
async function loadOptions() {
|
||||
if (OPTIONS) return OPTIONS;
|
||||
OPTIONS = await (await fetch("/api/options")).json();
|
||||
return OPTIONS;
|
||||
}
|
||||
|
||||
function fillModelOptions(side) {
|
||||
const agent = document.querySelector(`[name="${side}-agent"]`).value;
|
||||
const models = OPTIONS.models[agent] || [];
|
||||
const sel = document.querySelector(`[name="${side}-model"]`);
|
||||
sel.innerHTML = "";
|
||||
for (const m of models) {
|
||||
const o = document.createElement("option");
|
||||
o.value = m; o.textContent = m;
|
||||
sel.appendChild(o);
|
||||
}
|
||||
}
|
||||
|
||||
function fillPromptOptions(side) {
|
||||
const sel = document.querySelector(`[name="${side}-prompt"]`);
|
||||
sel.innerHTML = "";
|
||||
for (const p of OPTIONS.prompts) {
|
||||
const o = document.createElement("option");
|
||||
o.value = p.id; o.textContent = p.label; o.dataset.desc = p.description;
|
||||
sel.appendChild(o);
|
||||
}
|
||||
if (OPTIONS.defaults?.prompt) sel.value = OPTIONS.defaults.prompt;
|
||||
updatePromptDesc(side);
|
||||
}
|
||||
|
||||
function updatePromptDesc(side) {
|
||||
const sel = document.querySelector(`[name="${side}-prompt"]`);
|
||||
const target = document.querySelector(`.setup-promptdesc[data-for="${side}"]`);
|
||||
if (!sel || !target) return;
|
||||
const opt = sel.options[sel.selectedIndex];
|
||||
target.textContent = opt?.dataset?.desc || "";
|
||||
}
|
||||
|
||||
function isGameInProgress() {
|
||||
return !!(STATE.game && !STATE.game.status?.result);
|
||||
}
|
||||
|
||||
function refreshGamesLink() {
|
||||
const link = $("games-link");
|
||||
if (!link) return;
|
||||
if (isGameInProgress()) {
|
||||
link.classList.add("disabled");
|
||||
link.title = "finish or abort the current game to open games & stats";
|
||||
link.removeAttribute("href");
|
||||
} else {
|
||||
link.classList.remove("disabled");
|
||||
link.removeAttribute("title");
|
||||
link.setAttribute("href", "/games");
|
||||
}
|
||||
}
|
||||
|
||||
function refreshSetupGate() {
|
||||
const blocked = isGameInProgress();
|
||||
$("setup-warning").hidden = !blocked;
|
||||
$("setup-start").disabled = blocked;
|
||||
}
|
||||
|
||||
async function openSetupDialog() {
|
||||
await loadOptions();
|
||||
// Populate agent selects
|
||||
for (const side of ["white", "black"]) {
|
||||
const sel = document.querySelector(`[name="${side}-agent"]`);
|
||||
if (!sel.children.length) {
|
||||
for (const a of OPTIONS.agents) {
|
||||
const o = document.createElement("option");
|
||||
o.value = a; o.textContent = a;
|
||||
sel.appendChild(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Seed defaults from current bindings if available
|
||||
const b = STATE.bindings || {};
|
||||
for (const side of ["white", "black"]) {
|
||||
const agent = b[side]?.agent || OPTIONS.agents[(side === "white") ? 0 : 1];
|
||||
document.querySelector(`[name="${side}-agent"]`).value = agent;
|
||||
fillModelOptions(side);
|
||||
const curModel = b[side]?.model;
|
||||
if (curModel && OPTIONS.models[agent]?.includes(curModel)) {
|
||||
document.querySelector(`[name="${side}-model"]`).value = curModel;
|
||||
}
|
||||
fillPromptOptions(side);
|
||||
}
|
||||
refreshSetupGate();
|
||||
$("setup-dialog").showModal();
|
||||
}
|
||||
|
||||
document.addEventListener("click", (e) => {
|
||||
if (e.target?.id === "abort-now") {
|
||||
fetch("/api/abort-game", { method: "POST" })
|
||||
.then(() => setTimeout(refreshSetupGate, 100));
|
||||
}
|
||||
});
|
||||
|
||||
$("new-game").addEventListener("click", () => openSetupDialog());
|
||||
|
||||
// Agent change → repopulate models
|
||||
for (const side of ["white", "black"]) {
|
||||
document.querySelector(`[name="${side}-agent"]`).addEventListener("change", () => {
|
||||
fillModelOptions(side);
|
||||
});
|
||||
document.querySelector(`[name="${side}-prompt"]`).addEventListener("change", () => {
|
||||
updatePromptDesc(side);
|
||||
});
|
||||
}
|
||||
|
||||
// Swap white/black selections
|
||||
$("swap-sides").addEventListener("click", () => {
|
||||
for (const field of ["agent", "model", "prompt"]) {
|
||||
const w = document.querySelector(`[name="white-${field}"]`);
|
||||
const b = document.querySelector(`[name="black-${field}"]`);
|
||||
const tmp = w.value; w.value = b.value; b.value = tmp;
|
||||
}
|
||||
// Reset model lists for new agent values
|
||||
fillModelOptions("white"); fillModelOptions("black");
|
||||
updatePromptDesc("white"); updatePromptDesc("black");
|
||||
});
|
||||
|
||||
// Randomize: pick random agent/model/prompt per side, agents on opposite sides if possible
|
||||
$("randomize").addEventListener("click", () => {
|
||||
const agents = [...OPTIONS.agents].sort(() => Math.random() - 0.5);
|
||||
const prompts = OPTIONS.prompts.map(p => p.id);
|
||||
const sides = ["white", "black"];
|
||||
for (let i = 0; i < sides.length; i++) {
|
||||
const side = sides[i];
|
||||
const agent = agents[i % agents.length];
|
||||
document.querySelector(`[name="${side}-agent"]`).value = agent;
|
||||
fillModelOptions(side);
|
||||
const models = OPTIONS.models[agent];
|
||||
document.querySelector(`[name="${side}-model"]`).value = models[Math.floor(Math.random() * models.length)];
|
||||
document.querySelector(`[name="${side}-prompt"]`).value = prompts[Math.floor(Math.random() * prompts.length)];
|
||||
updatePromptDesc(side);
|
||||
}
|
||||
});
|
||||
|
||||
// Submit
|
||||
$("setup-start").addEventListener("click", async (e) => {
|
||||
e.preventDefault();
|
||||
const overrides = {};
|
||||
for (const side of ["white", "black"]) {
|
||||
overrides[side] = {
|
||||
agent: document.querySelector(`[name="${side}-agent"]`).value,
|
||||
model: document.querySelector(`[name="${side}-model"]`).value,
|
||||
prompt: document.querySelector(`[name="${side}-prompt"]`).value,
|
||||
};
|
||||
}
|
||||
await fetch("/api/new-game", {
|
||||
method: "POST",
|
||||
headers: {"content-type": "application/json"},
|
||||
body: JSON.stringify({ overrides }),
|
||||
});
|
||||
// tell coordinator to inject the first prompt right away
|
||||
fetch("/api/dispatch-first", { method: "POST" }).catch(() => {});
|
||||
$("setup-dialog").close();
|
||||
});
|
||||
|
||||
const dialog = $("settings-dialog");
|
||||
|
||||
+75
-20
@@ -2,34 +2,89 @@
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>ai-chess — games</title>
|
||||
<title>ai-chess — games & stats</title>
|
||||
<link rel="stylesheet" href="/static/vendor/chessground.base.css" />
|
||||
<link rel="stylesheet" href="/static/vendor/chessground.brown.css" />
|
||||
<link rel="stylesheet" href="/static/vendor/chessground.cburnett.css" />
|
||||
<link rel="stylesheet" href="/static/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main style="padding: 16px;">
|
||||
<h1>Games</h1>
|
||||
<a href="/">← back to live</a>
|
||||
<table id="games-table" style="width: 100%; margin-top: 16px;">
|
||||
<thead><tr><th>id</th><th>white</th><th>black</th><th>result</th><th>termination</th><th>moves</th><th>pgn</th></tr></thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<div id="replay-wrap" style="display: none;">
|
||||
<h3 id="replay-title"></h3>
|
||||
<div style="display: grid; grid-template-columns: 360px 1fr; gap: 16px;">
|
||||
<div id="replay-board" style="width: 360px; aspect-ratio: 1/1;"></div>
|
||||
<div>
|
||||
<div>
|
||||
<button id="prev">←</button>
|
||||
<button id="next">→</button>
|
||||
<span id="ply">ply 0</span>
|
||||
<main id="games-page">
|
||||
<header id="games-page-header">
|
||||
<a id="back-link" href="/">← back to live</a>
|
||||
<h1>games & stats</h1>
|
||||
<span id="games-count"></span>
|
||||
</header>
|
||||
|
||||
<div id="blocked-banner" hidden>
|
||||
<strong>Game in progress.</strong> Finish or abort it on the
|
||||
<a href="/">main page</a> before browsing past games.
|
||||
</div>
|
||||
|
||||
<div id="page-grid">
|
||||
<section id="stats-pane">
|
||||
<header class="col-header"><span>leaderboard (player × model)</span></header>
|
||||
<table id="leaderboard">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>agent / model</th>
|
||||
<th>games</th>
|
||||
<th>wins</th>
|
||||
<th>draws</th>
|
||||
<th>losses</th>
|
||||
<th>score</th>
|
||||
<th>winrate</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
<header class="col-header"><span>by persona</span></header>
|
||||
<table id="leaderboard-prompts">
|
||||
<thead>
|
||||
<tr><th>persona</th><th>games</th><th>wins</th><th>draws</th><th>losses</th><th>score</th></tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section id="games-pane">
|
||||
<header class="col-header"><span>games</span></header>
|
||||
<table id="games-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>id</th>
|
||||
<th>white</th>
|
||||
<th>black</th>
|
||||
<th>result</th>
|
||||
<th>termination</th>
|
||||
<th>moves</th>
|
||||
<th>pgn</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
<div id="replay-wrap" hidden>
|
||||
<header class="col-header"><span id="replay-title">replay</span>
|
||||
<button id="replay-close" type="button">close</button>
|
||||
</header>
|
||||
<div id="replay-layout">
|
||||
<div id="replay-board"></div>
|
||||
<aside id="replay-side">
|
||||
<div id="replay-controls">
|
||||
<button id="replay-first">⏮</button>
|
||||
<button id="replay-prev">←</button>
|
||||
<button id="replay-next">→</button>
|
||||
<button id="replay-last">⏭</button>
|
||||
<span id="replay-ply">ply 0/0</span>
|
||||
<span id="replay-eval"></span>
|
||||
</div>
|
||||
<ol id="replay-history"></ol>
|
||||
</aside>
|
||||
</div>
|
||||
<ol id="replay-history" style="max-height: 60vh; overflow: auto;"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
<script src="/static/games.js" type="module"></script>
|
||||
|
||||
+164
-45
@@ -2,65 +2,184 @@ import { Chess } from "/static/vendor/chess.min.js";
|
||||
import { Chessground } from "/static/vendor/chessground.min.js";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const tbody = document.querySelector("#games-table tbody");
|
||||
|
||||
let cg = null, chess = null, history = [], ply = 0;
|
||||
let cg = null;
|
||||
let replay = { history: [], evals: new Map(), ply: 0 };
|
||||
|
||||
function renderReplay() {
|
||||
chess = new Chess();
|
||||
for (let i = 0; i < ply; i++) chess.move(history[i].san);
|
||||
cg.set({ fen: chess.fen() });
|
||||
$("ply").textContent = `ply ${ply}/${history.length}`;
|
||||
const ol = $("replay-history");
|
||||
ol.innerHTML = "";
|
||||
history.forEach((h, i) => {
|
||||
const li = document.createElement("li");
|
||||
li.textContent = h.san + (h.comment ? " «" + h.comment + "»" : "");
|
||||
if (i === ply - 1) li.style.background = "#444";
|
||||
ol.appendChild(li);
|
||||
});
|
||||
function fenKey(fen) { return fen.split(" ").slice(0, 3).join(" "); }
|
||||
|
||||
// ---------- gating ----------
|
||||
async function checkBlocked() {
|
||||
try {
|
||||
const r = await fetch("/api/state");
|
||||
const s = await r.json();
|
||||
return !!(s.game && !s.game.status?.result);
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
|
||||
// ---------- leaderboard ----------
|
||||
function renderLeaderboard(stats) {
|
||||
$("games-count").textContent = `${stats.total_games} games`;
|
||||
const tb = document.querySelector("#leaderboard tbody");
|
||||
tb.innerHTML = "";
|
||||
for (const p of stats.players) {
|
||||
const wr = p.games ? Math.round(100 * (p.wins + 0.5 * p.draws) / p.games) : 0;
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td><strong>${p.agent}</strong> / ${p.model}</td>
|
||||
<td>${p.games}</td>
|
||||
<td>${p.wins}</td>
|
||||
<td>${p.draws}</td>
|
||||
<td>${p.losses}</td>
|
||||
<td>${p.score.toFixed(1)}</td>
|
||||
<td>${wr}%</td>`;
|
||||
tb.appendChild(tr);
|
||||
}
|
||||
const tp = document.querySelector("#leaderboard-prompts tbody");
|
||||
tp.innerHTML = "";
|
||||
for (const p of stats.prompts) {
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td>${p.prompt}</td>
|
||||
<td>${p.games}</td>
|
||||
<td>${p.wins}</td>
|
||||
<td>${p.draws}</td>
|
||||
<td>${p.losses}</td>
|
||||
<td>${p.score.toFixed(1)}</td>`;
|
||||
tp.appendChild(tr);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- games list ----------
|
||||
function renderGames(games) {
|
||||
const tb = document.querySelector("#games-table tbody");
|
||||
tb.innerHTML = "";
|
||||
for (const g of games) {
|
||||
const w = g.agents?.white || {};
|
||||
const b = g.agents?.black || {};
|
||||
const tr = document.createElement("tr");
|
||||
const result = g.result || "*";
|
||||
tr.innerHTML = `
|
||||
<td><a href="#" data-id="${g.id}">${(g.id || "?").slice(0, 10)}…</a></td>
|
||||
<td>${w.agent || "?"}/${w.model || "?"}<br><span class="persona">${w.prompt || ""}</span></td>
|
||||
<td>${b.agent || "?"}/${b.model || "?"}<br><span class="persona">${b.prompt || ""}</span></td>
|
||||
<td class="result-${result.replace(/\//g, "_")}">${result}</td>
|
||||
<td>${g.termination || ""}</td>
|
||||
<td>${g.moves_count ?? 0}</td>
|
||||
<td><a href="/api/games/${g.id}/pgn">pgn</a></td>`;
|
||||
tr.querySelector("a[data-id]").addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
openReplay(g.id);
|
||||
});
|
||||
tb.appendChild(tr);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- replay ----------
|
||||
async function openReplay(id) {
|
||||
const data = await (await fetch(`/api/games/${id}`)).json();
|
||||
const meta = data.meta;
|
||||
const w = meta.agents?.white || {};
|
||||
const b = meta.agents?.black || {};
|
||||
$("replay-title").textContent =
|
||||
`${id} — ${w.agent || "?"}/${w.model || "?"} vs ${b.agent || "?"}/${b.model || "?"} → ${meta.result || "*"}`;
|
||||
chess = new Chess();
|
||||
chess.load_pgn(data.pgn);
|
||||
// chess.js 0.13.4: history({verbose:true}) returns [{san, ...}, ...]
|
||||
history = chess.history({ verbose: true }).map(m => ({ san: m.san, comment: null }));
|
||||
ply = 0;
|
||||
if (!cg) cg = Chessground($("replay-board"), { viewOnly: true, fen: "start" });
|
||||
$("replay-wrap").style.display = "block";
|
||||
`${id.slice(0,10)}… — ${w.agent||"?"}/${w.model||"?"} (${w.prompt||"?"}) vs ${b.agent||"?"}/${b.model||"?"} (${b.prompt||"?"}) → ${meta.result || "*"}`;
|
||||
// Prefer saved history (with comments) if present in meta
|
||||
let history = [];
|
||||
if (Array.isArray(meta.history) && meta.history.length) {
|
||||
history = meta.history.filter(h => h.san);
|
||||
} else {
|
||||
// fallback to PGN parse
|
||||
const c = new Chess();
|
||||
c.load_pgn(data.pgn);
|
||||
history = c.history({ verbose: true }).map(m => ({
|
||||
san: m.san, uci: m.from + m.to + (m.promotion || ""), comment: null, side: m.color === "w" ? "white" : "black",
|
||||
}));
|
||||
}
|
||||
replay.history = history;
|
||||
replay.evals.clear();
|
||||
for (const e of (meta.evals || [])) {
|
||||
const sideToMove = (e.fen || "").split(" ")[1] || "w";
|
||||
const flip = sideToMove === "b";
|
||||
replay.evals.set(fenKey(e.fen), {
|
||||
cp: e.cp == null ? null : (flip ? -e.cp : e.cp),
|
||||
mate: e.mate == null ? null : (flip ? -e.mate : e.mate),
|
||||
best_uci: e.best_uci,
|
||||
pv: e.pv,
|
||||
});
|
||||
}
|
||||
replay.ply = 0;
|
||||
if (!cg) {
|
||||
cg = Chessground($("replay-board"), { viewOnly: true, fen: "start" });
|
||||
}
|
||||
$("replay-wrap").hidden = false;
|
||||
renderReplay();
|
||||
$("replay-wrap").scrollIntoView({ behavior: "smooth", block: "nearest" });
|
||||
}
|
||||
|
||||
function renderReplay() {
|
||||
const c = new Chess();
|
||||
for (let i = 0; i < replay.ply; i++) c.move(replay.history[i].san);
|
||||
const fen = c.fen();
|
||||
const e = replay.evals.get(fenKey(fen));
|
||||
const shapes = (e?.best_uci && e.best_uci.length >= 4)
|
||||
? [{ orig: e.best_uci.slice(0,2), dest: e.best_uci.slice(2,4), brush: "green" }] : [];
|
||||
cg.set({ fen, drawable: { autoShapes: shapes } });
|
||||
$("replay-ply").textContent = `ply ${replay.ply}/${replay.history.length}`;
|
||||
$("replay-eval").textContent = e
|
||||
? (e.mate != null ? `#${e.mate}` : (e.cp != null ? ((e.cp/100).toFixed(2)) : "—"))
|
||||
: "—";
|
||||
const ol = $("replay-history");
|
||||
ol.innerHTML = "";
|
||||
replay.history.forEach((h, i) => {
|
||||
const li = document.createElement("li");
|
||||
li.className = `replay-row bubble bubble-${h.side}`;
|
||||
if (i === replay.ply - 1) li.classList.add("active");
|
||||
const meta = document.createElement("div");
|
||||
meta.className = "bubble-meta";
|
||||
meta.innerHTML = `<span>${h.side}</span><span class="bubble-san">${Math.floor(i/2)+1}${h.side==="white"?".":"..."} ${h.san}</span>`;
|
||||
const body = document.createElement("div");
|
||||
body.className = "bubble-body" + (h.comment ? "" : " bubble-empty");
|
||||
body.textContent = h.comment || "—";
|
||||
li.append(meta, body);
|
||||
li.addEventListener("click", () => { replay.ply = i + 1; renderReplay(); });
|
||||
ol.appendChild(li);
|
||||
});
|
||||
const activeRow = ol.querySelector(".replay-row.active");
|
||||
if (activeRow) activeRow.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
||||
}
|
||||
|
||||
$("replay-first").addEventListener("click", () => { replay.ply = 0; renderReplay(); });
|
||||
$("replay-prev").addEventListener("click", () => { if (replay.ply > 0) { replay.ply--; renderReplay(); } });
|
||||
$("replay-next").addEventListener("click", () => { if (replay.ply < replay.history.length) { replay.ply++; renderReplay(); } });
|
||||
$("replay-last").addEventListener("click", () => { replay.ply = replay.history.length; renderReplay(); });
|
||||
$("replay-close").addEventListener("click", () => { $("replay-wrap").hidden = true; });
|
||||
window.addEventListener("keydown", (e) => {
|
||||
if ($("replay-wrap").hidden) return;
|
||||
if (e.key === "ArrowLeft" && replay.ply > 0) { replay.ply--; renderReplay(); }
|
||||
else if (e.key === "ArrowRight" && replay.ply < replay.history.length) { replay.ply++; renderReplay(); }
|
||||
});
|
||||
|
||||
// ---------- bootstrap ----------
|
||||
async function main() {
|
||||
const games = await (await fetch("/api/games")).json();
|
||||
for (const g of games) {
|
||||
const w = g.agents?.white || {};
|
||||
const b = g.agents?.black || {};
|
||||
const tr = document.createElement("tr");
|
||||
tr.innerHTML = `
|
||||
<td><a href="#" data-id="${g.id}">${(g.id || "?").slice(0, 10)}…</a></td>
|
||||
<td>${w.agent || "?"}/${w.model || "?"}</td>
|
||||
<td>${b.agent || "?"}/${b.model || "?"}</td>
|
||||
<td>${g.result || "*"}</td>
|
||||
<td>${g.termination || ""}</td>
|
||||
<td>${g.moves_count ?? 0}</td>
|
||||
<td><a href="/api/games/${g.id}/pgn">pgn</a></td>
|
||||
`;
|
||||
tr.querySelector("a[data-id]").addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
openReplay(g.id);
|
||||
});
|
||||
tbody.appendChild(tr);
|
||||
const blocked = await checkBlocked();
|
||||
if (blocked) {
|
||||
$("blocked-banner").hidden = false;
|
||||
document.getElementById("page-grid").style.opacity = "0.4";
|
||||
document.getElementById("page-grid").style.pointerEvents = "none";
|
||||
// refresh every 5s — when game finishes, unblock
|
||||
const intv = setInterval(async () => {
|
||||
if (!(await checkBlocked())) {
|
||||
clearInterval(intv);
|
||||
location.reload();
|
||||
}
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
const [games, stats] = await Promise.all([
|
||||
fetch("/api/games").then(r => r.json()),
|
||||
fetch("/api/stats").then(r => r.json()),
|
||||
]);
|
||||
renderGames(games);
|
||||
renderLeaderboard(stats);
|
||||
}
|
||||
main();
|
||||
|
||||
$("prev").addEventListener("click", () => { if (ply > 0) { ply--; renderReplay(); } });
|
||||
$("next").addEventListener("click", () => { if (ply < history.length) { ply++; renderReplay(); } });
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<span id="status-line">…</span>
|
||||
<span id="sf-pv"></span>
|
||||
<button id="live-btn" hidden>live</button>
|
||||
<a id="games-link" href="/games">games & stats</a>
|
||||
<button id="new-game">new game</button>
|
||||
<button id="settings-btn" title="settings">⚙</button>
|
||||
</div>
|
||||
@@ -53,6 +54,59 @@
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<dialog id="setup-dialog">
|
||||
<form method="dialog" id="setup-form">
|
||||
<header class="setup-header">
|
||||
<h3>new game</h3>
|
||||
<div class="setup-actions">
|
||||
<button type="button" id="swap-sides" title="swap white/black">⇄ swap</button>
|
||||
<button type="button" id="randomize" title="randomize">🎲 random</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="setup-grid">
|
||||
<fieldset class="setup-side setup-white">
|
||||
<legend>WHITE</legend>
|
||||
<label>agent
|
||||
<select name="white-agent"></select>
|
||||
</label>
|
||||
<label>model
|
||||
<select name="white-model"></select>
|
||||
</label>
|
||||
<label>persona
|
||||
<select name="white-prompt"></select>
|
||||
</label>
|
||||
<p class="setup-promptdesc" data-for="white"></p>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="setup-side setup-black">
|
||||
<legend>BLACK</legend>
|
||||
<label>agent
|
||||
<select name="black-agent"></select>
|
||||
</label>
|
||||
<label>model
|
||||
<select name="black-model"></select>
|
||||
</label>
|
||||
<label>persona
|
||||
<select name="black-prompt"></select>
|
||||
</label>
|
||||
<p class="setup-promptdesc" data-for="black"></p>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<p id="setup-warning" hidden>
|
||||
⚠ Current game is in progress.
|
||||
<button type="button" id="abort-now">abort current game</button>
|
||||
to enable a new one.
|
||||
</p>
|
||||
|
||||
<menu>
|
||||
<button value="cancel">cancel</button>
|
||||
<button value="start" id="setup-start">start game</button>
|
||||
</menu>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<script src="/static/app.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+95
-2
@@ -165,7 +165,100 @@ button:hover { background: #2e2e36; }
|
||||
|
||||
dialog {
|
||||
background: #15151a; color: #e7e5e4; border: 1px solid #2a2a30;
|
||||
padding: 16px; border-radius: 6px;
|
||||
padding: 16px; border-radius: 8px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.6);
|
||||
}
|
||||
dialog form { display: flex; flex-direction: column; gap: 10px; min-width: 320px; }
|
||||
dialog::backdrop { background: rgba(0,0,0,0.55); }
|
||||
dialog form { display: flex; flex-direction: column; gap: 12px; min-width: 320px; }
|
||||
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 0; }
|
||||
dialog h3 { margin: 0; font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
|
||||
dialog select, dialog input[type="number"], dialog input[type="text"] {
|
||||
background: #1f1f25; color: #e7e5e4; border: 1px solid #34343a;
|
||||
border-radius: 4px; padding: 4px 6px; font-size: 12px;
|
||||
}
|
||||
|
||||
/* setup dialog */
|
||||
#setup-dialog { min-width: 580px; }
|
||||
.setup-header { display: flex; justify-content: space-between; align-items: center; }
|
||||
.setup-actions { display: flex; gap: 8px; }
|
||||
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
|
||||
.setup-side {
|
||||
border: 1px solid #34343a; border-radius: 6px; padding: 10px 12px;
|
||||
display: flex; flex-direction: column; gap: 8px;
|
||||
background: #1a1a20;
|
||||
}
|
||||
.setup-side legend { padding: 0 6px; font-size: 11px; letter-spacing: 0.1em; opacity: 0.8; }
|
||||
.setup-white legend { color: #e7e5e4; }
|
||||
.setup-black legend { color: #c0a060; }
|
||||
.setup-side label {
|
||||
display: flex; flex-direction: column; gap: 3px;
|
||||
font-size: 10px; opacity: 0.55; text-transform: uppercase; letter-spacing: 0.08em;
|
||||
}
|
||||
.setup-side select { font-size: 13px; opacity: 1; text-transform: none; letter-spacing: 0; }
|
||||
.setup-promptdesc {
|
||||
margin: 4px 0 0; font-size: 11px; opacity: 0.55; line-height: 1.4;
|
||||
min-height: 2.4em;
|
||||
}
|
||||
#setup-warning { background: #3a2a1a; border: 1px solid #5a4020; color: #f0c080; padding: 8px 10px; border-radius: 4px; font-size: 12px; margin: 0; }
|
||||
#setup-start { background: #3d342a; color: #f0d090; }
|
||||
#games-link { font-size: 12px; color: #c0a060; text-decoration: none; margin-right: 4px; }
|
||||
#games-link:hover { text-decoration: underline; }
|
||||
#games-link.disabled { color: #555; cursor: not-allowed; }
|
||||
#games-link.disabled:hover { text-decoration: none; }
|
||||
|
||||
/* ============ /games page ============ */
|
||||
#games-page {
|
||||
max-width: 1500px; margin: 0 auto; padding: 24px;
|
||||
display: flex; flex-direction: column; gap: 18px;
|
||||
}
|
||||
#games-page-header {
|
||||
display: flex; align-items: baseline; gap: 16px;
|
||||
border-bottom: 1px solid #2a2a30; padding-bottom: 12px;
|
||||
}
|
||||
#games-page-header h1 { margin: 0; font-size: 18px; letter-spacing: 0.05em; }
|
||||
#games-count { opacity: 0.55; font-size: 12px; }
|
||||
#back-link { color: #c0a060; text-decoration: none; }
|
||||
#back-link:hover { text-decoration: underline; }
|
||||
|
||||
#blocked-banner {
|
||||
background: #3a2a1a; border: 1px solid #5a4020; color: #f0c080;
|
||||
padding: 12px 14px; border-radius: 6px;
|
||||
}
|
||||
#blocked-banner a { color: #f0d090; }
|
||||
|
||||
#page-grid {
|
||||
display: grid; grid-template-columns: 420px 1fr; gap: 18px;
|
||||
}
|
||||
#stats-pane, #games-pane {
|
||||
background: #15151a; border: 1px solid #2a2a30; border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#stats-pane table, #games-pane table {
|
||||
width: 100%; border-collapse: collapse; font-size: 12.5px;
|
||||
}
|
||||
#stats-pane th, #stats-pane td, #games-pane th, #games-pane td {
|
||||
padding: 6px 10px; text-align: left; border-bottom: 1px solid #1f1f24;
|
||||
}
|
||||
#stats-pane th, #games-pane th {
|
||||
font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
|
||||
opacity: 0.55; font-weight: 600;
|
||||
}
|
||||
#stats-pane td:nth-child(n+2), #games-pane td:nth-child(n+4) { font-variant-numeric: tabular-nums; }
|
||||
.persona { font-size: 10px; opacity: 0.5; }
|
||||
.result-1-0 { color: #f0eee6; font-weight: 700; }
|
||||
.result-0-1 { color: #c0a060; font-weight: 700; }
|
||||
.result-1_2-1_2 { color: #88c0a0; font-weight: 700; }
|
||||
.result-_ { opacity: 0.4; }
|
||||
|
||||
/* replay */
|
||||
#replay-wrap { border-top: 1px solid #2a2a30; padding: 14px; }
|
||||
#replay-layout { display: grid; grid-template-columns: 360px 1fr; gap: 16px; }
|
||||
#replay-board { width: 360px; aspect-ratio: 1/1; }
|
||||
#replay-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
|
||||
#replay-controls { display: flex; gap: 6px; align-items: center; font-size: 12px; }
|
||||
#replay-controls button { padding: 2px 8px; }
|
||||
#replay-ply { opacity: 0.6; margin-left: 8px; }
|
||||
#replay-eval { margin-left: auto; font-weight: 700; color: #f0d090; }
|
||||
#replay-history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 540px; overflow-y: auto; }
|
||||
.replay-row { font-size: 12px; }
|
||||
#replay-close { background: #25252b; }
|
||||
|
||||
Reference in New Issue
Block a user