새 게임 라이어 게임: 규칙 엔진·말하는 컴퓨터·화면·도움말·문서·E2E

- packages/games/src/liar: 주제 10개 제시어 은행, 설명(두 번째 바퀴 거꾸로)·자유 토론·투표(동점 재투표 한 번, 또 동점이면 라이어 승리)·라이어 정답 맞히기(띄어쓰기·다른 표기 무시), 바보 모드
- 컴퓨터: 마피아처럼 live 전략, 레벨 1~60을 LiveBotInput.level 로 받음(서버 BotDriver 가 넘김), BOT_CHAT_REQUIRED 에 추가
- 웹: 꾹 누르는 제시어 카드, 설명 기록·토론 채팅·투표 화면, 30초 요약, [?] 도움말
- 문서 docs/games/liar.md, 등록(GAMES·CATALOG·BOT_GAMES·registry·아이콘), 서버 방 테스트, E2E(거절 알림이 저절로 사라지는지 확인 포함)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 03:14:39 +09:00
parent bde430f33e
commit 74a7daa4d3
25 changed files with 3569 additions and 12 deletions

View File

@@ -0,0 +1,117 @@
/**
* 라이어 게임 through a real Room with computers: one person and computers play a whole game with the real bot driver
* and the room clock. The person's connection never learns the word (when they are the liar) or who the liar is (when
* they are a citizen) before the reveal, and the room chat stays closed while the game runs.
*/
import { afterEach, describe, expect, test } from 'bun:test';
import { GAMES } from '@bg/games';
import type { LiarState, LiarView } from '@bg/games/liar';
import { botProfile, isBotId, type ServerMessage } from '@bg/shared';
import { openDb } from '../db';
import { RoomManager } from './manager';
import type { Conn, Room } from './room';
import { RoomStore } from './store';
const rooms: Room[] = [];
afterEach(() => {
for (const r of rooms.splice(0)) r.clearTimer();
});
function practice(person = 'A') {
const db = openDb(':memory:');
const store = new RoomStore(db);
let now = 1_000_000;
const clock = { now: () => now, advance: (ms: number) => (now += ms) };
const logs: string[] = [];
const users = { publicUser: (id: string) => botProfile(id) ?? { id, nickname: '철수', avatar: null, kind: 'guest' as const } };
const manager = new RoomManager({ store, games: GAMES, users, now: clock.now, botDelay: () => 0, log: (level, msg) => level !== 'info' && logs.push(msg) });
const room = manager.createPractice(person, 'liar') as Room;
rooms.push(room);
const msgs: ServerMessage[] = [];
const conn: Conn & { msgs: ServerMessage[] } = { userId: person, msgs, send: (m) => msgs.push(m), close: () => {} };
room.join(conn, 'player');
const state = () => room.game!.state as LiarState;
const lastView = () => (msgs.filter((m) => m.t === 'state').at(-1) as Extract<ServerMessage, { t: 'state' }>).view as LiarView;
/** Lets the computers act (their own timers) and the room clock run, until `stop` or the end. */
const run = (stop: () => boolean = () => false, maxSteps = 4000) => {
for (let i = 0; i < maxSteps && !room.game!.finished && !stop(); i++) {
const next = Math.min(room.bots.dueAt ?? Infinity, room.effectiveDeadline() ?? Infinity);
expect(Number.isFinite(next)).toBe(true);
clock.advance(Math.max(0, next - clock.now()));
room.bots.fire();
room.onTimer();
}
};
return { room, clock, msgs, conn, state, lastView, run, logs };
}
describe('라이어 게임 room flow with computers', () => {
test('연습 방은 사람 1 + 컴퓨터 4, 컴퓨터 채팅은 항상 켜짐', () => {
const { room } = practice();
expect(room.seatedIds().filter(isBotId)).toHaveLength(4);
expect(room.start('A')).toBeNull();
expect(room.game!.players).toHaveLength(5);
});
test('사람이 차례에 설명하고 토론·투표하면 컴퓨터와 한 판이 끝까지 가요', () => {
const { room, state, lastView, msgs, run, logs } = practice();
expect(room.start('A')).toBeNull();
expect(room.chat('A', '안녕')).toBe('게임 중에는 게임 화면의 채팅을 써 주세요.');
const s0 = state();
const iAmLiar = s0.liar === 'A';
// Nothing the person receives names the liar or (if they are the liar) the word, until the reveal.
const leaks = () => {
const all = JSON.stringify(msgs.filter((m) => m.t === 'state').map((m) => ({ ...(m as { view: LiarView }).view, final: null, events: [] })));
if (iAmLiar) expect(all).not.toContain(`"${s0.word}"`);
expect(all).not.toContain('"liar":true');
};
let cs = 1;
let described = 0;
// Reveal: the person confirms; the computers confirm on their own.
room.act('A', cs++, { type: 'ready' });
run(() => state().phase.kind !== 'reveal');
expect(state().phase.kind).toBe('describe');
const speaker = () => GAMES.liar!.view(state(), null).phase.speaker;
while (state().phase.kind === 'describe') {
if (speaker() === 'A') {
room.act('A', cs++, { type: 'chat', text: iAmLiar ? '저는 좋아하는 편이에요' : '음 다들 아실 거예요' });
described++;
}
run(() => state().phase.kind !== 'describe' || speaker() === 'A');
}
leaks();
expect(described).toBe(state().options.rounds);
// Every computer described in its turn.
for (const d of state().descriptions) if (d.from !== 'A') expect(d.text).not.toBeNull();
expect(state().phase.kind).toBe('discussion');
room.act('A', cs++, { type: 'chat', text: '누가 라이어일까요' });
room.act('A', cs++, { type: 'ready' });
run(() => state().phase.kind !== 'discussion');
// The computers talked in the discussion.
expect(state().chat.some((m) => isBotId(m.from))).toBe(true);
leaks();
while (state().phase.kind === 'vote') {
const v = lastView();
if (v.my!.voteTargets.length && v.my!.vote === null) room.act('A', cs++, { type: 'vote', target: v.my!.voteTargets[0]! });
run(() => state().phase.kind !== 'vote' || (state().phase.kind === 'vote' && (state().phase as { round: number }).round !== v.phase.voteRound));
}
if (state().phase.kind === 'guess' && state().liar === 'A') room.act('A', cs++, { type: 'guess', text: '모르겠어요' });
run();
expect(room.game!.finished).toBe(true);
const f = state().final!;
expect(f.summary).toMatch(/^(라이어|시민) 승리!/);
const end = lastView();
expect(end.final!.liar).toBe(s0.liar);
expect(end.players.find((p) => p.id === s0.liar)!.liar).toBe(true);
expect(logs).toEqual([]);
});
test('사람이 아무것도 안 해도(시간 초과만) 끝나요', () => {
const { room, run, state, logs } = practice();
room.start('A');
run();
expect(room.game!.finished).toBe(true);
expect(state().descriptions.filter((d) => d.from === 'A').every((d) => d.text === null)).toBe(true);
expect(logs).toEqual([]);
});
});