원카드: 카드 내기와 원카드 외치기 분리(내면서 외치기 없앰), 잡기 전 보호 시간(1~3초, 기본 2초), 컴퓨터도 사람처럼 늦게 외치고 잡기, 한 턴 시간 무제한, 원카드 보너스 옵션

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:15:18 +09:00
parent f12cf12b84
commit 28590df429
9 changed files with 378 additions and 57 deletions

View File

@@ -1,7 +1,8 @@
/** Computer players in rooms (docs/06-lobby-rooms.md §12): seating rules, practice rooms, driving, records, restore. */
import { afterEach, describe, expect, test } from 'bun:test';
import { GAMES } from '@bg/games';
import { BOT_STRATEGIES, LIVE_BOT_STRATEGIES } from '@bg/games/bots';
import { BOT_STRATEGIES, LIVE_BOT_STRATEGIES, botReactionAt } from '@bg/games/bots';
import { classicDeck, type OneCardState } from '@bg/games/one-card';
import { BOT_GAMES, ClientMessage, botProfile, isBotId, type ServerMessage } from '@bg/shared';
import { openDb } from '../db';
import { botPace, defaultBotDelay, type BotDelayInput } from './bots';
@@ -338,6 +339,63 @@ describe('playing with bots', () => {
});
});
describe('원카드: computers call and catch on their own reaction clock', () => {
test('a computer that played down to one card calls at its reaction time; a person can catch only after 2 s', () => {
const h = harness(undefined, undefined, (input) => defaultBotDelay(input, () => 0.5));
const room = h.manager.createPractice('A', 'one-card') as Room;
rooms.push(room);
const a = h.conn('A');
room.join(a, 'player');
expect(room.start('A')).toBeNull();
const bot = bots(room)[0]!;
// Rig: the computer's turn with [♥9, ♣3] on ♥5; the person is next.
const s = room.game!.state as OneCardState;
const deck = classicDeck(1);
const take = (ids: string[]) => ids.map((id) => deck.find((c) => c.id === id)!);
s.hands = { A: take(['S4', 'S6', 'D8']), [bot]: take(['H9', 'C3']) };
s.discard = take(['H5']);
s.drawPile = deck.filter((c) => !['S4', 'S6', 'D8', 'H9', 'C3', 'H5'].includes(c.id));
s.current = bot;
s.phase = { kind: 'turn' };
s.pendingAttack = 0;
s.declaredSuit = null;
s.oneCardWindow = null;
room.bots.cancel();
room.scheduleTimer();
for (let k = 0; k < 5 && !(room.game!.state as OneCardState).oneCardWindow; k++) {
h.clock.advance(Math.max(0, (room.bots.dueAt ?? h.clock.now()) - h.clock.now()));
room.bots.fire();
}
let st = room.game!.state as OneCardState;
expect(st.oneCardWindow).toMatchObject({ player: bot, declared: false });
expect(st.current).toBe('A');
const opened = st.oneCardWindow!.openedAt!;
// Planned exactly at its reaction time (not squeezed by the turn clock, no thinking chat).
const at = botReactionAt(room.def, st, bot, room.profile(bot).level) as number;
expect(at).toBeGreaterThanOrEqual(opened + 500);
expect(room.bots.dueAt).toBe(at);
const rejects = () => a.msgs.filter((m) => m.t === 'reject').length;
const before = rejects();
room.act('A', 101, { type: 'declareOneCard' });
expect(rejects()).toBe(before + 1);
if (at > opened + 2000) {
// Slow this time: the person catches it first and the planned call is dropped.
h.clock.advance(opened + 2000 - h.clock.now());
room.act('A', 102, { type: 'declareOneCard' });
st = room.game!.state as OneCardState;
expect(st.oneCardWindow).toBeNull();
expect(st.hands[bot]).toHaveLength(2);
expect(room.bots.dueAt).toBeNull();
} else {
h.clock.advance(at - h.clock.now());
room.bots.fire();
st = room.game!.state as OneCardState;
expect(st.oneCardWindow).toMatchObject({ player: bot, declared: true });
expect(st.hands[bot]).toHaveLength(1);
}
});
});
describe('practice rooms close once nobody is there', () => {
function finishedPractice() {
const h = harness();