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('게임이 끝났어요'); });