Files
joke-app/apps/web/src/games/clue/help.test.ts
EJClaw c9f81804cf 클루: 규칙·컴퓨터 상대·화면·테스트
- 규칙 모듈 packages/games/src/clue: 3~6명, 용의자 6·흉기 6·방 9, 봉투 3장, 나머지는 같은 장수로
  나누고 남는 카드는 공개(원작). 9개 방 + 복도를 거리 표로 단순화한 저택(비밀 통로 부엌↔서재,
  온실↔라운지), 주사위 2개 합만큼 이동해 닿는 방에 들어가거나 먼 방 쪽으로 걸어가기, 빠른 이동 옵션.
  추리 시 용의자 말·흉기 이동과 불려 온 사람의 제자리 추리, 다음 사람부터 반증(반증자가 직접 고름,
  보여 준 카드는 두 사람만), 고발(틀리면 탈락하되 반증은 계속, 모두 틀리면 무승부).
  카드 id(card-*)와 추리 이름을 나눠 view 누출 검사가 의미 있게, 이벤트에는 카드 없음.
  시간 초과는 차례를 통째로 자동 진행, 반증은 첫 카드 자동, 나가면 카드 공개.
- 컴퓨터 상대(bot.ts): 소거 노트(내 카드·공개·받은 카드 → 못 보여 준 사람·손패 수 → "셋 중 하나"
  제약·틀린 고발), 단계가 높을수록 깊게, 확실할 때만 고발, 모르는 카드로 추리, 모르는 방으로 이동.
- 화면 apps/web/src/games/clue: 저택 지도(말·흉기·거리·통로), 주사위·방 고르기, 추리/고발 칩,
  반증 카드 고르기, 내 카드·공개 카드, 추리 노트(localStorage, 방 코드+게임 번호), 추리 기록.
- 등록(GAMES, 카탈로그, BOT_GAMES, BOT_STRATEGIES, 화면 레지스트리, 아이콘·분류), 문서
  docs/games/clue.md, E2E 계획(PC 1 + 휴대폰 2, 끝까지).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 03:09:33 +09:00

67 lines
3.6 KiB
TypeScript

import { expect, test } from 'bun:test';
import { applyAction, setupGame, usersOf } from '../help-kit.test-util';
import { GAMES } from '@bg/games';
import { helpNow } from './help';
const ids = ['A', 'B', 'C'];
const users = usersOf(ids);
const view = (s: unknown, who: string | null) => GAMES.clue!.view(s, who) as any;
const nickOf = (id: string) => users[id]!.nickname;
/** A fresh game with the current player standing in the library, ready to suggest. */
function inLibrary() {
const { state } = setupGame('clue', 3);
const cur = state.current as string;
const s = structuredClone(state);
s.pos[s.suspectOf[cur]] = { at: 'library' };
s.phase = { kind: 'suggest', room: 'library' };
return { s, cur };
}
test('클루: 주사위 차례 / 기다리기 / 관전', () => {
const { state } = setupGame('clue', 3);
const cur = state.current as string;
const other = ids.find((p) => p !== cur)!;
expect(helpNow(view(state, cur), cur, users)).toContain('[🎲 주사위 굴리기]');
expect(helpNow(view(state, other), other, users)).toContain(`${nickOf(cur)}님이 이동하는 중이에요`);
expect(helpNow(view(state, null), null, users)).toContain(`${nickOf(cur)}님 차례예요`);
const rolled = applyAction('clue', state, cur, { type: 'roll' });
expect(helpNow(view(rolled, cur), cur, users)).toContain('주사위 합은');
});
test('클루: 추리 → 몰래 보여 주기 (보여 주는 사람 / 추리한 사람 / 다른 사람)', () => {
const { s, cur } = inLibrary();
expect(helpNow(view(s, cur), cur, users)).toContain('[추리하기]');
// Ask about cards the next player surely holds: one of their own.
const order = s.seats as string[];
const next = order[(order.indexOf(cur) + 1) % 3]!;
const third = order.find((p) => p !== cur && p !== next)!;
const theirs: string[] = s.hands[next].map((c: string) => c.slice(5));
const suspect = theirs.find((x) => ['scarlet', 'mustard', 'white', 'green', 'peacock', 'plum'].includes(x)) ?? 'plum';
const weapon = theirs.find((x) => ['candlestick', 'dagger', 'pipe', 'revolver', 'rope', 'wrench'].includes(x)) ?? 'rope';
const t = applyAction('clue', s, cur, { type: 'suggest', suspect, weapon });
if (t.phase.kind === 'refute') {
const r = t.phase.refuter as string;
expect(helpNow(view(t, r), r, users)).toContain('한 장을 보여 줘야 해요');
expect(helpNow(view(t, cur), cur, users)).toContain('나에게 보여 줄 카드를 고르는 중');
const watcher = [next, third].find((p) => p !== r)!;
expect(helpNow(view(t, watcher), watcher, users)).toContain('두 사람만 알아요');
const done = applyAction('clue', t, r, { type: 'show', card: t.hands[r].find((c: string) => [suspect, weapon, 'library'].includes(c.slice(5))) });
expect(helpNow(view(done, cur), cur, users)).toContain('보여 준 카드는 정답이 아니에요');
} else {
expect(helpNow(view(t, cur), cur, users)).toContain('아무도 카드를 보여 주지 못했어요');
}
});
test('클루: 고발이 틀려 탈락 / 게임 끝', () => {
const { state } = setupGame('clue', 3);
const cur = state.current as string;
const sol = state.solution;
const wrong = { type: 'accuse', suspect: sol.suspect === 'plum' ? 'green' : 'plum', weapon: sol.weapon, room: sol.room };
const s = applyAction('clue', state, cur, wrong);
expect(helpNow(view(s, cur), cur, users)).toContain('고발이 틀려서 탈락했어요');
const next = s.current as string;
const end = applyAction('clue', s, next, { type: 'accuse', ...sol });
expect(helpNow(view(end, cur), cur, users)).toContain('게임이 끝났어요');
});