우노: 공식 규칙 엔진·컴퓨터 상대·화면·도움말·문서·E2E

- 규칙 모듈 packages/games/src/uno: 108장(원카드 색깔 카드 덱·점수 재사용, 원카드 코드는 그대로),
  7장씩, 공식 시작 카드 처리(드로우4 다시 섞기, 드로우2·스킵·리버스, 와일드는 첫 사람이 색 고르기),
  색·숫자·기호 맞추기, 낼 카드가 있어도 뽑기 + 뽑은 카드 바로 내기, 2명 리버스=스킵,
  와일드 드로우4 도전(공식: 몰래 낼 수 있고 성공 4장/실패 6장, 손패는 도전한 사람만) 또는 쉬운 규칙,
  "우노!" 외치기(내면서 또는 직후, 다음 차례 행동 전까지 누구나 잡기 2장), 공식 점수(한 판/500점),
  하우스 룰(드로우 카드 쌓기, 낼 수 있을 때까지 뽑기, 기본 끄기). 시간 초과는 낼 수 있는 카드 자동
  (와일드는 많이 가진 색), 나가기·자리 비움 처리.
- 컴퓨터 상대(bot.ts): 레벨별 우노 깜빡함·잡기 확률, 드로우 카드 아끼기, 드로우4 거짓말/도전 판단, 색 고르기.
- 테스트: 규칙 시나리오, 무작위 대국(유출·보존·결정성), 컴퓨터, 방에서 사람 1 + 컴퓨터 3 끝까지.
- 화면 apps/web/src/games/uno: 지금 색 링·칩, 방향·다음 사람, 남은 장수, 우노 버튼(준비/외치기),
  잡기 버튼, 도전·시작 색·판 결과 창, 30초 요약, 지금 할 수 있는 것.
- 등록(GAMES, 카탈로그, BOT_GAMES/BOT_STRATEGIES, 화면 레지스트리, 아이콘·카드 탭), docs/games/uno.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:31:32 +09:00
parent cf7523f862
commit 609f458ed2
20 changed files with 3536 additions and 0 deletions

View File

@@ -1141,6 +1141,109 @@ const PLANS: Record<string, Plan> = {
console.log(` one-card: ${turns} turns (${plays} plays, ${draws} draws)${finished ? ', game finished' : ''}`);
},
},
uno: {
// 3 players (PC host + 2 phones), official rules: whoever has the turn picks a start colour, answers a 와일드 드로우4
// (challenges now and then), presses [우노!] before the second-to-last card (or not, to be caught), plays a
// highlighted card (colour sheet for wilds) or draws / passes; a lit catch button is pressed. Until the game ends.
players: 3,
drive: async (pages) => {
const statusOf = (p: Page) => p.locator('.turn-status').innerText().catch(() => '');
const st = { turns: 0, plays: 0, draws: 0, wilds: 0, challenges: 0, armed: 0, missed: 0, unoCalls: 0, catches: 0, startColors: 0 };
const shot = new Set<string>();
const once = async (p: Page, name: string) => {
if (shot.has(name)) return;
shot.add(name);
await p.screenshot({ path: join(SHOTS, `uno-${name}.png`) });
};
let finished = false;
let shots = false;
for (let t = 0; t < 3000 && st.turns < 400; t++) {
if (await pages[0]!.getByRole('dialog', { name: '게임 결과' }).count()) {
finished = true;
break;
}
let acted = false;
for (const p of pages) {
const catchBtn = p.locator('.un-catch');
if ((await catchBtn.count()) && (await catchBtn.isEnabled().catch(() => false))) {
await catchBtn.scrollIntoViewIfNeeded().catch(() => {});
await once(p, 'catch');
if (await catchBtn.click({ timeout: 1000 }).then(() => true, () => false)) st.catches++;
}
// The first missed call is left for the others to catch.
const call = p.locator('.un-unobtn.call');
if (st.catches > 0 && (await call.count()) && (await call.isEnabled().catch(() => false))) {
if (await call.click({ timeout: 1000 }).then(() => true, () => false)) st.unoCalls++;
}
const before = await statusOf(p);
if (!before.includes('내 차례예요')) continue;
const startColor = p.getByRole('group', { name: '시작 색 고르기' }).getByRole('button').first();
const challenge = p.getByRole('button', { name: '도전하기' });
const accept = p.getByRole('button', { name: /^받아들이기/ });
const card = p.locator('button.un-card[data-legal="true"]').first();
if (await startColor.count()) {
await once(p, 'start-color');
await startColor.click();
st.startColors++;
} else if (await accept.count()) {
await once(p, 'challenge');
if (st.challenges < 2) {
await challenge.click();
st.challenges++;
} else await accept.click();
} else if (await card.count()) {
// Two cards left: get "우노!" ready first, except the first time (so somebody can catch it).
const uno = p.locator('.un-unobtn:not(.call)');
if ((await p.locator('button.un-card').count()) === 2 && (await uno.isEnabled().catch(() => false))) {
if (st.missed === 0) st.missed++;
else {
await uno.click();
await p.locator('.un-unobtn[aria-pressed="true"]').waitFor({ timeout: 2000 });
st.armed++;
}
}
await card.click();
await card.click();
const pick = p.locator('.un-pick button').first();
if (await pick.waitFor({ timeout: 400 }).then(() => true, () => false)) {
await pick.click();
st.wilds++;
}
st.plays++;
} else {
const pass = p.getByRole('button', { name: '넘기기' });
if (await pass.count()) await pass.click();
else await p.getByRole('button', { name: /장 뽑기$/ }).first().click();
st.draws++;
}
await p.waitForFunction((s) => document.querySelector('.turn-status')?.textContent?.trim() !== s, before.trim(), { timeout: 5000 }).catch(() => {});
st.turns++;
acted = true;
if (st.turns === 12 && !shots) {
shots = true;
const [host, phone] = pages as [Page, Page];
await host.waitForTimeout(300);
await host.screenshot({ path: join(SHOTS, 'uno-mid-pc.png') });
await phone.screenshot({ path: join(SHOTS, 'uno-mid-phone.png') });
await phone.screenshot({ path: join(SHOTS, 'uno-mid-phone-full.png'), fullPage: true });
await host.emulateMedia({ colorScheme: 'dark' });
await phone.emulateMedia({ colorScheme: 'dark' });
await host.screenshot({ path: join(SHOTS, 'uno-mid-pc-dark.png') });
await phone.screenshot({ path: join(SHOTS, 'uno-mid-phone-dark.png') });
await host.emulateMedia({ colorScheme: 'light' });
await phone.emulateMedia({ colorScheme: 'light' });
}
break;
}
if (!acted) await pages[0]!.waitForTimeout(120);
}
if (!finished) throw new Error(`game did not finish after ${st.turns} turns ${JSON.stringify(st)}`);
await pages[0]!.waitForTimeout(400);
await pages[0]!.screenshot({ path: join(SHOTS, 'uno-result-pc.png') });
await pages[1]!.screenshot({ path: join(SHOTS, 'uno-result-phone.png') });
console.log(` uno: game finished ${JSON.stringify(st)}`);
},
},
'davinci-code': {
// 2 players, default options (choose colours): both pick 2+2 start tiles, then several real turns:
// draw from a pile, tap an opponent's hidden tile, pick a number, confirm; after a hit press "여기서 멈추기".