feat(menu): unified home screen + ai-vs-ai/play split + human mode

Routes:
- GET /        → menu.html (new home/menu).
- GET /ai-vs-ai → old index.html (AI-vs-AI live game).
- GET /play    → same index.html; app.js detects the human side from
  bindings and enables chessground move input on that side only.
- GET /games   → unchanged.

Backend:
- coordinator: 'human' is now an allowed agent type alongside claude/codex.
  start_new_game accepts overrides[side].agent = 'human'. _send_first /
  _send_turn / watchdog skip human sides.
- POST /api/human-move: humans submit moves from the browser (UCI/SAN
  + optional comment); rejected if it's not their turn or side isn't human.
- /api/options now also returns 'all_agents' = AI agents + 'human' for the
  human-vs-AI configurator.
- pane-agent.sh: when binding agent is 'human', the pane just prints a
  note and sleeps — no claude/codex is launched for that side.

Frontend menu (new public/menu.{html,css,js}):
- 'underground tournament' aesthetic: Major Mono Display title, JetBrains
  Mono body (Google Fonts), warm gold (#c0a060) / crimson (#c04040)
  accents, subtle film-grain overlay.
- Three big mode cards: 01 AI×AI, 02 HUMAN×AI, 03 GAMES·STATS.
- Inline configurator below the cards: WHITE / VS / BLACK columns with
  agent / model / persona selects, persona description preview, swap +
  randomize tools, abort-current warning that links to /api/abort-game.
- Start button routes to /ai-vs-ai or /play depending on whether a human
  side was picked. Enter submits.
- HUD strip with tmux / stockfish / games-played counters.

app.js changes:
- Chessground constructed with viewOnly toggling; renderBoard rebuilds
  movable.color + dests = legal moves at the live FEN from chess.js for
  the human's turn only; board is read-only when scrubbing history,
  during the AI's turn, or in AI-vs-AI.
- humanSide() helper reads bindings; orientation auto-flips when the
  human plays black.
This commit is contained in:
ai-chess
2026-05-15 01:10:47 +03:00
parent 42f23c71cc
commit ab38cda1bd
7 changed files with 889 additions and 13 deletions
+66 -5
View File
@@ -23,12 +23,34 @@ function fenKey(fen) {
return parts.slice(0, 3).join(" ");
}
async function submitHumanMove(orig, dest, prom) {
const uci = orig + dest + (prom ? prom : "");
try {
await fetch("/api/human-move", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ move: uci }),
});
} catch (e) {
console.warn("human-move failed", e);
}
}
const cg = Chessground($("board"), {
viewOnly: true,
viewOnly: false,
fen: "start",
orientation: "white",
movable: { free: false },
movable: { free: false, color: undefined, dests: new Map(), showDests: true },
draggable: { enabled: true, showGhost: true },
selectable: { enabled: true },
drawable: { enabled: true, visible: true },
events: {
move: (orig, dest) => {
// Only used in human-vs-AI mode; AI-vs-AI sets movable.color to undefined,
// making this unreachable.
submitHumanMove(orig, dest);
},
},
});
// ---------- responsive board sizing ----------
@@ -72,6 +94,25 @@ function currentFen() {
return c.fen();
}
function humanSide() {
const b = STATE.bindings || {};
if (b.white?.agent === "human") return "white";
if (b.black?.agent === "human") return "black";
return null;
}
function legalDestsForFen(fen) {
// Build a Map<from, to[]> of legal moves at this position. Used to let
// chessground accept only legal squares for the human side.
const c = new Chess(fen);
const dests = new Map();
for (const m of c.moves({ verbose: true })) {
if (!dests.has(m.from)) dests.set(m.from, []);
dests.get(m.from).push(m.to);
}
return dests;
}
function renderBoard() {
if (!STATE.game) return;
const moves = (STATE.game.history || []).filter(h => h.san);
@@ -82,13 +123,33 @@ function renderBoard() {
const uci = moves[idx].uci || "";
if (uci.length >= 4) lastMove = [uci.slice(0, 2), uci.slice(2, 4)];
}
// Pass shapes via set() to atomically replace last move + arrow.
// Arrow comes from stored eval for this FEN, if any.
const e = STATE.evalByFen.get(fenKey(fen));
const shapes = (e && 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, lastMove, drawable: { autoShapes: shapes } });
// Human-vs-AI: enable board moves only on the human's turn at the live FEN.
const hSide = humanSide();
const sideToMove = STATE.game.side_to_move;
const isHumanTurn = (
hSide && hSide === sideToMove
&& STATE.viewPly === null
&& !STATE.game.status?.result
);
const movable = isHumanTurn
? { free: false, color: hSide, dests: legalDestsForFen(fen), showDests: true, events: {} }
: { free: false, color: undefined, dests: new Map(), showDests: false };
cg.set({
fen, lastMove,
orientation: hSide === "black" ? "black" : "white",
movable,
draggable: { enabled: !!isHumanTurn, showGhost: true },
selectable: { enabled: !!isHumanTurn },
drawable: { enabled: true, visible: true, autoShapes: shapes },
viewOnly: !isHumanTurn,
});
$("live-btn").hidden = STATE.viewPly === null;
applyEvalForFen(fen);
}