Bots that play on alone do it at a pace to watch, a round every two seconds after the first few, and a seat may hurry them to the end

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG
This commit is contained in:
Eric WagonerandClaude Opus 5.5 committed 2026-09-29 12:19:38 -04:00
1 parent 99a0b23f59
commit 403232087d
8 files changed
+120 -3

No files matched your search

+40
View File
@@ -164,4 +164,44 @@ describe('rooms', () => {
rooms.begin(host.room, host.token);
expect(() => rooms.say(host.room, host.token, 'Psst.', ['B'])).toThrow(/read no private talk/);
});
describe('a table the bots play on alone', () => {
/** A count to ten that only the bots play: the host is never owed a move. */
type Count = { n: number; over: { winner: null; reason: string } | null };
const count: GameSpec<Count, null> = {
seatIds: ['A', 'B'],
minSeats: 2,
botNames: ['Aldric'],
currentRules: 1,
create: () => ({ n: 0, over: null }),
resolve: (s) => ({ n: s.n + 1, over: s.n + 1 >= 10 ? { winner: null, reason: 'Ten.' } : null }),
needsInput: (s, seat) => seat === 'B' && !s.over,
over: (s) => s.over,
turn: (s) => s.n + 1,
view: (s) => s,
botInput: () => null,
cleanInput: () => null,
nameOf: (_s, seat) => seat
};
beforeEach(() => vi.useFakeTimers());
afterEach(() => vi.useRealTimers());
it('plays a few rounds at once, then one at a pace to watch, and the rest at once when hurried', () => {
const rooms = new Rooms(count, new Store(dir));
const host = rooms.create('Ann', 2);
rooms.addBot(host.room, host.token);
rooms.begin(host.room, host.token);
const room = host.room;
expect(room.state!.n).toBe(4);
expect(rooms.view(room, 'A').playingOn).toBe(true);
vi.advanceTimersByTime(2000);
expect(room.state!.n).toBe(5);
rooms.hurry(room, host.token);
vi.runAllTimers();
expect(room.state!.n).toBe(10);
expect(room.over).toBe(true);
expect(rooms.view(room, 'A').playingOn).toBe(false);
});
});
});