클루: 규칙·컴퓨터 상대·화면·테스트

- 규칙 모듈 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>
This commit is contained in:
EJClaw
2026-10-12 22:27:42 +09:00
parent b98775b0a6
commit c9f81804cf
21 changed files with 3171 additions and 2 deletions

View File

@@ -904,6 +904,96 @@ async function mafiaShots(pages: Page[], name: string) {
await phone.emulateMedia({ colorScheme: 'light' });
}
/**
* 클루: one UI step for whoever must act on `p` — show a card (refute panel), roll / take the passage, pick a room on the
* map and enter it (or walk towards a far one), suggest (suspect + weapon chips), end the turn; once `accuseAfter`
* suggestions were made, accuse a guess (two-step confirm) so the game ends (right → win, all wrong → nobody wins).
*/
async function clueStep(p: Page, st: Record<string, number>, accuseAfter: number): Promise<string | null> {
const status = await p.locator('.turn-status').innerText().catch(() => '');
if (!status.includes('내 차례예요')) return null;
const refute = p.getByRole('group', { name: '카드 보여 주기' });
if (await refute.count()) {
if (!st[`shot-refute-${tag(p)}`]) {
st[`shot-refute-${tag(p)}`] = 1;
await p.screenshot({ path: join(SHOTS, `clue-refute-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
}
await refute.locator('button.cl-card').first().click({ timeout: 2000 });
st.show = (st.show ?? 0) + 1;
return 'show';
}
const btn = (name: RegExp) => p.locator('.cl-panel').getByRole('button', { name });
const accuse = async () => {
await btn(/고발하기…/).first().click({ timeout: 2000 });
const panel = p.getByRole('group', { name: '고발하기' });
for (const g of ['범인', '흉기', '장소']) await panel.getByRole('group', { name: g }).locator('button:not(.known)').first().click();
await panel.getByRole('button', { name: / 고발$/ }).click();
await panel.getByRole('button', { name: '정말 고발해요 (틀리면 탈락)' }).click({ timeout: 2000 });
st.accuse = (st.accuse ?? 0) + 1;
return 'accuse';
};
const roll = btn(/주사위 굴리기/);
if (await roll.count()) {
if ((st.suggest ?? 0) >= accuseAfter) return accuse();
const pass = btn(/비밀 통로로/);
if ((await pass.count()) && (st.passage ?? 0) === 0) {
await pass.click();
st.passage = 1;
return 'passage';
}
if (tag(p) === 'pc' && !st.keyboard) {
// Keyboard: focus the roll button and press Enter.
await roll.focus();
await p.keyboard.press('Enter');
st.keyboard = 1;
} else await roll.click({ timeout: 2000 });
st.roll = (st.roll ?? 0) + 1;
return 'roll';
}
const rooms = p.locator('.cl-map button.cl-room');
if (await rooms.count()) {
if (!st[`shot-move-${tag(p)}`]) {
st[`shot-move-${tag(p)}`] = 1;
await p.screenshot({ path: join(SHOTS, `clue-move-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
}
const reach = p.locator('.cl-map button.cl-room.reach');
if (await reach.count()) {
await reach.nth((st.roll ?? 0) % (await reach.count())).click();
await btn(/들어가기$/).click({ timeout: 2000 });
st.enter = (st.enter ?? 0) + 1;
return 'enter';
}
await rooms.first().click();
await btn(/쪽으로 걸어가기/).click({ timeout: 2000 });
st.walk = (st.walk ?? 0) + 1;
return 'walk';
}
const sug = p.getByRole('group', { name: '추리하기' });
if (await sug.count()) {
if ((st.suggest ?? 0) >= accuseAfter) return accuse();
const n = st.suggest ?? 0;
for (const g of ['범인', '흉기']) {
const opts = sug.getByRole('group', { name: g }).locator('button:not(.known)');
await opts.nth(n % (await opts.count())).click();
}
await sug.getByRole('button', { name: /^추리하기:/ }).click({ timeout: 2000 });
st.suggest = n + 1;
return 'suggest';
}
const end = btn(/^차례 끝내기$/);
if (await end.count()) {
if (!st[`shot-after-${tag(p)}`]) {
st[`shot-after-${tag(p)}`] = 1;
await p.screenshot({ path: join(SHOTS, `clue-after-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
}
if ((st.suggest ?? 0) >= accuseAfter) return accuse();
await end.click();
st.end = (st.end ?? 0) + 1;
return 'end';
}
return null;
}
const PLANS: Record<string, Plan> = {
rummikub: {
// PC host + phone guest, first meld "없음" so hint plays happen early; 10 real turns through the UI.
@@ -2203,6 +2293,66 @@ const PLANS: Record<string, Plan> = {
const text = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
if (!/사과 \d+개/.test(text)) throw new Error(`no apple scores in the result: ${text.replace(/\n/g, ' ')}`);
console.log(` apple: ${st.pc} mouse + ${st.key} keyboard clears on PC, ${st.phone}+ touch clears on the phone, ${st.miss} miss; final PC ${await appleScore(host)} / phone ${await appleScore(guest)}`);
},
},
clue: {
// PC host + 2 phones, dice movement, 30-second turns. Real turns through the UI: roll (PC once by keyboard), a secret
// passage, rooms picked on the map, suggestions from the chips, cards shown from the refute panel. Only the suggester
// and the refuter see the shown card. After 8 suggestions everybody accuses a guess, so the game ends.
players: 3,
lobby: async (host) => {
await host.getByRole('group', { name: '차례 제한 시간' }).getByRole('button', { name: '30초' }).click();
await host.getByText(/주사위 이동 · 차례 30초/).first().waitFor();
},
drive: async (pages) => {
const [host, guest] = pages as [Page, Page, Page];
const st: Record<string, number> = {};
let actions = 0;
let shot = false;
let privacy = false;
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
const until = Date.now() + 300_000;
while (Date.now() < until && !(await over())) {
let acted = false;
for (const p of pages) {
const did = await clueStep(p, st, 8).catch(() => null);
if (did) {
acted = true;
actions++;
await p.waitForTimeout(250);
break;
}
}
if (!privacy && (st.show ?? 0) >= 1) {
// The first shown card: exactly two pages (suggester, refuter) show it in the log.
privacy = true;
await host.waitForTimeout(400);
const seen = await Promise.all(pages.map((p) => p.locator('.cl-log .cl-shown').count()));
if (seen.filter((n) => n > 0).length !== 2) throw new Error(`shown card visible on ${seen.join('/')} pages`);
}
if (!shot && (st.suggest ?? 0) >= 3) {
shot = true;
await host.waitForTimeout(500);
await host.screenshot({ path: join(SHOTS, 'clue-mid-pc.png') });
await guest.screenshot({ path: join(SHOTS, 'clue-mid-phone.png') });
await guest.screenshot({ path: join(SHOTS, 'clue-mid-phone-full.png'), fullPage: true });
await host.emulateMedia({ colorScheme: 'dark' });
await guest.emulateMedia({ colorScheme: 'dark' });
await host.waitForTimeout(400);
await host.screenshot({ path: join(SHOTS, 'clue-mid-pc-dark.png') });
await guest.screenshot({ path: join(SHOTS, 'clue-mid-phone-dark.png'), fullPage: true });
await host.emulateMedia({ colorScheme: 'light' });
await guest.emulateMedia({ colorScheme: 'light' });
}
if (!acted) await host.waitForTimeout(150);
}
if (!(await over())) throw new Error(`game did not finish (${actions} UI actions: ${JSON.stringify(st)})`);
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor();
await host.waitForTimeout(600);
await host.screenshot({ path: join(SHOTS, 'clue-result-pc.png') });
await guest.screenshot({ path: join(SHOTS, 'clue-result-phone.png') });
if ((st.suggest ?? 0) < 8 || !st.roll || !st.enter || !st.accuse || !privacy) throw new Error(`too few real turns: ${JSON.stringify(st)}`);
console.log(` clue: finished after ${actions} UI actions ${JSON.stringify(Object.fromEntries(Object.entries(st).filter(([k]) => !k.startsWith('shot'))))}`);
},
},
};