A crowded table: keyed threats, a compact roster, a ledger selector, host-only starts

Threats are keyed by seat as well as hand and spell, so two opponents
building the same spell no longer crash the board (regression test).
Past three wizards the rail lists the others on a line each with health,
condition and whether they have moved; a row of names turns the ledger
toward any wizard, as do pressing a warning or choosing a target; each
seat keeps one colour across the ledger, the warnings and the rail. The
result strip folds untouched wizards into one line. A full table no
longer begins by itself: the host begins at every size and may send a
bot away. Target lists carry health and condition, and an intent
sentence says what the reveal will do.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0141G6xqLeNRYEtviLWSB5Up
This commit is contained in:
Eric Wagoner
2026-09-23 11:21:13 -04:00
co-authored by Claude Fable 5.1
parent c24fccaa35
commit 5c79a65319
19 changed files with 473 additions and 60 deletions
+7
View File
@@ -5,6 +5,7 @@
// POST /api/rooms/:id/join {name} take the next seat
// POST /api/rooms/:id/bot {token} seat a bot (any seated player may, before the duel begins)
// POST /api/rooms/:id/begin {token} the host begins the duel with the wizards seated so far
// POST /api/rooms/:id/unseat {token, seat} the host sends a bot away before the duel begins
// GET /api/rooms/:id?token= the view for that seat; without a token, the gallery's view
// POST /api/rooms/:id/turn {token, input} this seat's move
// POST /api/rooms/:id/say {token, text} table talk, from a seat to the whole room
@@ -205,6 +206,12 @@ async function handle(req: IncomingMessage, res: ServerResponse): Promise<void>
const seat = rooms.seatOf(room, body.token as string);
return send(res, 200, rooms.view(room, seat.id));
}
if (action === 'unseat') {
const token = typeof body.token === 'string' ? body.token : undefined;
rooms.unseat(room, token, body.seat);
const seat = rooms.seatOf(room, token);
return send(res, 200, rooms.view(room, seat.id));
}
if (action === 'begin') {
const token = typeof body.token === 'string' ? body.token : undefined;
rooms.begin(room, token);
+16 -3
View File
@@ -136,7 +136,7 @@ export class Rooms {
return this.sit(room, name, false);
}
/** The host, who opened the table, begins the duel once at least two are seated. A full table begins by itself. */
/** The host, who opened the table, begins the duel once at least two are seated, however full the table. */
begin(room: Room, token: string | undefined): void {
const seat = this.seatOf(room, token);
if (seat.id !== room.seats[0]?.id) throw new RoomError('Only the wizard who opened the table may begin the duel.', 403);
@@ -158,12 +158,22 @@ export class Rooms {
if (room.seats.length >= room.size) throw new RoomError('Every seat at this duel is taken.', 409);
const name = cleanName(rawName);
if (room.seats.some((s) => s.name.toLowerCase() === name.toLowerCase())) throw new RoomError('Another wizard here already has that name.', 409);
const seat: Seat = { id: SEAT_IDS[room.seats.length], name, token: bot ? '' : newId(18), bot };
const id = SEAT_IDS.find((s) => !room.seats.some((taken) => taken.id === s))!;
const seat: Seat = { id, name, token: bot ? '' : newId(18), bot };
this.commit(room, { t: 'seat', id: seat.id, name, token: seat.token, bot });
if (room.seats.length === room.size) this.commit(room, { t: 'start', seed: newSeed(), rules: CURRENT_RULES });
return seat;
}
/** The host sends a bot away before the duel begins. People leave by not coming back. */
unseat(room: Room, token: string | undefined, seatId: unknown): void {
const host = this.seatOf(room, token);
if (host.id !== room.seats[0]?.id) throw new RoomError('Only the wizard who opened the table may send a bot away.', 403);
if (room.state) throw new RoomError('The duel has begun; the table is set.', 409);
const seat = room.seats.find((s) => s.id === seatId);
if (!seat || !seat.bot) throw new RoomError('Only a bot can be sent away.', 400);
this.commit(room, { t: 'unseat', id: seat.id });
}
/** Record a seat's move; resolve the turn once nobody else is awaited. */
submit(room: Room, token: string | undefined, raw: unknown): void {
const seat = this.seatOf(room, token);
@@ -278,6 +288,9 @@ function apply(room: Room, line: LedgerLine): void {
case 'seat':
room.seats.push({ id: line.id, name: line.name, token: line.token, bot: line.bot });
break;
case 'unseat':
room.seats = room.seats.filter((s) => s.id !== line.id);
break;
case 'start':
room.state = createGame(Object.fromEntries(room.seats.map((s) => [s.id, s.name])), line.seed, line.rules ?? 1);
break;
+2
View File
@@ -9,6 +9,8 @@ import type { TurnInput, WizardId } from '../../src/lib/game/state';
export type LedgerLine =
| { t: 'room'; id: string; seats: number; createdAt: number }
| { t: 'seat'; id: WizardId; name: string; token: string; bot: boolean }
/** A bot sent away by the host before the duel began; its seat id is free again. */
| { t: 'unseat'; id: WizardId }
/** Ledgers from before revisions were recorded resolve under rules 1. */
| { t: 'start'; seed: number; rules?: number }
| { t: 'turn'; at: number; inputs: Record<WizardId, TurnInput> }