The bots talk at the table, each name in one of four tempers: a word on taking a chair, one from one of them as the duel begins, a line on a hard blow, a wizard brought down, its own death or the win, now and then a remark on a quiet turn, and an answer when named or when the talk speaks of bots; their lines go on the ledger as talk and are not counted as people talking in the tally or the visitors report. A duel in which every wizard has fallen while bots still stand is played out by the bots on the spot, where it used to wait forever for a turn no one could give
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0141G6xqLeNRYEtviLWSB5Up
This commit is contained in:
1 parent
07ebc41623
commit
89bc4083fc
6 files changed
+318
-10
No files matched your search
+35
-8
@@ -10,6 +10,7 @@ import { GESTURES, type Gesture } from '../../src/lib/game/spells';
|
||||
import { CURRENT_RULES, createGame, inDuel, SPECTATOR, type GameState, type TurnInput, type WizardId } from '../../src/lib/game/state';
|
||||
import { viewFor, type ChatLine, type RoomView } from '../../src/lib/game/view';
|
||||
import type { LedgerLine, Store } from './store';
|
||||
import { botLine, botsNamed, turnTalk } from './voices';
|
||||
|
||||
/** A dozen seats at most: a turn resolves only when every seat has moved, and the slowest sets the pace. */
|
||||
const SEAT_IDS: WizardId[] = 'ABCDEFGHJKLM'.split('');
|
||||
@@ -19,6 +20,8 @@ export { SPECTATOR };
|
||||
const CHAT_MAX_LENGTH = 300;
|
||||
/** Lines of talk kept and sent; the ledger keeps them all. */
|
||||
const CHAT_KEEP = 200;
|
||||
/** Turns the bots play on among themselves in one go; a duel still running past this many waits where it stands. */
|
||||
const BOTS_ALONE_LIMIT = 300;
|
||||
|
||||
export interface Seat {
|
||||
id: WizardId;
|
||||
@@ -207,12 +210,16 @@ export class Rooms {
|
||||
if (!room.galleryTalk) throw new RoomError('The gallery listens at this table; the host has not let it talk.', 403);
|
||||
const name = cleanName(rawName);
|
||||
if (room.seats.some((s) => s.name.toLowerCase() === name.toLowerCase())) throw new RoomError('A wizard at the table has that name.', 409);
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: SPECTATOR, name, text: cleanTalk(raw) });
|
||||
const text = cleanTalk(raw);
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: SPECTATOR, name, text });
|
||||
this.answer(room, name, text);
|
||||
}
|
||||
|
||||
/** The keeper of the site says a word at a table from the keeper's door, whether or not the gallery may talk: the answer to a call they could not take up. */
|
||||
keeperSays(room: Room, keeper: string, raw: unknown): void {
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: SPECTATOR, name: keeper, text: cleanTalk(raw), keeper: true });
|
||||
const text = cleanTalk(raw);
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: SPECTATOR, name: keeper, text, keeper: true });
|
||||
this.answer(room, keeper, text);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,6 +389,9 @@ export class Rooms {
|
||||
if (room.state) throw new RoomError('The duel has already begun.', 409);
|
||||
if (room.seats.length < 2) throw new RoomError('A duel needs at least two wizards.', 409);
|
||||
this.commit(room, { t: 'start', seed: newSeed(), rules: CURRENT_RULES });
|
||||
const bots = this.voiced(room);
|
||||
const bot = bots[Math.floor(Math.random() * bots.length)];
|
||||
if (bot) this.commit(room, { t: 'chat', at: Date.now(), id: bot.id, text: botLine(bot.name, 'begin') });
|
||||
}
|
||||
|
||||
/** The host seats a bot in an empty chair. */
|
||||
@@ -392,7 +402,9 @@ export class Rooms {
|
||||
const taken = new Set(room.seats.map((s) => s.name.toLowerCase()));
|
||||
const pool = BOT_NAMES.filter((n) => !taken.has(n.toLowerCase()));
|
||||
const name = pool[Math.floor(Math.random() * pool.length)] ?? 'The Construct';
|
||||
return this.sit(room, name, true).seat;
|
||||
const seat = this.sit(room, name, true).seat;
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: seat.id, text: botLine(name, 'sit') });
|
||||
return seat;
|
||||
}
|
||||
|
||||
/** Take the next free seat. The token is returned once and never stored; the ledger keeps its hash. */
|
||||
@@ -492,18 +504,33 @@ export class Rooms {
|
||||
if (seat.bot && needsInput(state, seat.id) && !(seat.id in inputs)) inputs[seat.id] = chooseBotTurn(state, seat.id);
|
||||
}
|
||||
this.commit(room, { t: 'turn', at: Date.now(), inputs });
|
||||
// A time stop owed to a bot resolves at once; a human's waits for them.
|
||||
while (room.state && !room.state.over && room.state.timeStops[0] && room.seats.find((s) => s.id === room.state!.timeStops[0])?.bot) {
|
||||
const actor = room.state.timeStops[0];
|
||||
this.commit(room, { t: 'turn', at: Date.now(), inputs: { [actor]: chooseBotTurn(room.state, actor) } });
|
||||
// A turn nobody at the table is awaited for is the bots' alone, whether a time stop owed to
|
||||
// one of them or the rest of a duel every wizard has left; it resolves at once, to the end.
|
||||
for (let played = 0; room.state && !room.state.over && waitingOn(room).length === 0 && played < BOTS_ALONE_LIMIT; played++) {
|
||||
const theirs: Record<WizardId, TurnInput> = {};
|
||||
for (const seat of room.seats) if (seat.bot && needsInput(room.state, seat.id)) theirs[seat.id] = chooseBotTurn(room.state, seat.id);
|
||||
this.commit(room, { t: 'turn', at: Date.now(), inputs: theirs });
|
||||
}
|
||||
if (room.state?.over) this.commit(room, { t: 'over', at: Date.now(), winner: room.state.over.winner, reason: room.state.over.reason });
|
||||
for (const line of turnTalk(this.voiced(room), state, room.state!)) this.commit(room, { t: 'chat', at: Date.now(), id: line.id, text: line.text });
|
||||
}
|
||||
|
||||
/** Table talk, from a seat to everyone at the table and in the gallery. */
|
||||
say(room: Room, token: string | undefined, raw: unknown): void {
|
||||
const seat = this.seatOf(room, token);
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: seat.id, text: cleanTalk(raw) });
|
||||
const text = cleanTalk(raw);
|
||||
this.commit(room, { t: 'chat', at: Date.now(), id: seat.id, text });
|
||||
this.answer(room, seat.name, text);
|
||||
}
|
||||
|
||||
/** The bots at the table, speaking for themselves; one standing in for a wizard keeps that wizard's silence. */
|
||||
private voiced(room: Room): { id: WizardId; name: string }[] {
|
||||
return room.seats.filter((s) => s.bot && !s.standIn).map((s) => ({ id: s.id, name: s.name }));
|
||||
}
|
||||
|
||||
/** A bot named in a line of talk answers it. */
|
||||
private answer(room: Room, speaker: string, text: string): void {
|
||||
for (const bot of botsNamed(text, this.voiced(room))) this.commit(room, { t: 'chat', at: Date.now(), id: bot.id, text: botLine(bot.name, bot.moment, { who: speaker }) });
|
||||
}
|
||||
|
||||
/** The view for a seat, or for the gallery when the seat is SPECTATOR. */
|
||||
|
||||
Reference in new issue
Block a user