# Conflicts: # apps/web/src/games/help.test.ts # apps/web/src/games/registry.ts # apps/web/src/lib/catalog-ui.ts # docs/games/README.md # packages/games/package.json # packages/games/src/index.ts # packages/shared/src/catalog.ts
3863 lines
214 KiB
TypeScript
3863 lines
214 KiB
TypeScript
/**
|
||
* M2 smoke E2E for every 2-player game (docs/10 §2): PC host creates the room from the game page,
|
||
* a phone friend joins by link, host starts, both see the board, a few legal moves are played via
|
||
* the keyboard (role="grid" boards support arrows + Enter) and reach the opponent.
|
||
* Run: bun e2e/games.e2e.ts [gameId...] (needs apps/web/dist built)
|
||
*/
|
||
import { chromium, type Locator, type Page } from 'playwright-core';
|
||
import { mkdirSync, mkdtempSync } from 'node:fs';
|
||
import { join } from 'node:path';
|
||
import { loadConfig } from '../apps/server/src/config';
|
||
import { startServer } from '../apps/server/src/server';
|
||
import { plan960 } from './chess960-plan';
|
||
|
||
const PORT = Number(process.env.E2E_PORT ?? 4519);
|
||
const ORIGIN = `http://localhost:${PORT}`;
|
||
const SHOTS = process.env.E2E_SHOTS ?? join(import.meta.dir, '../test-results');
|
||
mkdirSync(SHOTS, { recursive: true });
|
||
|
||
/** Per game: key sequences on the grid, in turn order (first mover, second mover, ...). */
|
||
interface Plan {
|
||
/** Game id when the plan key is a variant scenario (e.g. `chess960` → `chess`). */
|
||
game?: string;
|
||
/** Total players including the host (default 2). Extra players join on phones. */
|
||
players?: number;
|
||
/** Host changes room options before starting (inline settings form on PC). */
|
||
lobby?: (host: Page) => Promise<void>;
|
||
/** Steps run before normal moves (e.g. janggi formation choice). */
|
||
setup?: (host: Page, guest: Page) => Promise<void>;
|
||
/** Board games: key sequences on the grid, in turn order. */
|
||
moves?: string[][];
|
||
/** Card games: custom driver over all pages (host first). */
|
||
drive?: (pages: Page[]) => Promise<void>;
|
||
}
|
||
|
||
/** Card games: whoever has the turn presses the first available safe action (check/call/…) until `rounds` actions were taken. */
|
||
async function pressActions(pages: Page[], labels: RegExp, rounds: number) {
|
||
for (let n = 0; n < rounds; n++) {
|
||
let done = false;
|
||
for (let t = 0; t < 150 && !done; t++) {
|
||
for (const p of pages) {
|
||
const btn = p.getByRole('button', { name: labels }).first();
|
||
if ((await btn.count()) && (await btn.isEnabled({ timeout: 200 }).catch(() => false))) {
|
||
if (await btn.click({ timeout: 1000 }).then(() => true, () => false)) {
|
||
done = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (!done) await pages[0]!.waitForTimeout(100);
|
||
}
|
||
if (!done) throw new Error(`no action button matching ${labels} became available (step ${n + 1})`);
|
||
await pages[0]!.waitForTimeout(150);
|
||
}
|
||
}
|
||
|
||
/** Waits until every page shows the hand result, then presses "다음 판으로" where it is offered. */
|
||
async function finishHand(pages: Page[]) {
|
||
for (const p of pages) await p.getByText('이번 판 결과').first().waitFor({ timeout: 10_000 });
|
||
}
|
||
|
||
/**
|
||
* 루미큐브: whoever has the turn tries "도와줘" → places the picked tiles → "완료"; otherwise takes one tile.
|
||
* The first play drags the picked tiles from the rack onto the grid with the mouse, checks that the other player
|
||
* sees them on the table before 완료 (live working table), resets with "되돌리기", then places them with "새 묶음".
|
||
*/
|
||
async function rummikubTurns(pages: Page[], turns: number) {
|
||
const stats = { plays: 0, draws: 0, dragged: false };
|
||
const myTurn = (p: Page) => p.evaluate(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'));
|
||
const bar = (p: Page) => p.getByRole('group', { name: '내 차례 행동' });
|
||
/** Waits until a bar button is enabled / disabled (server answered). */
|
||
const barButton = (p: Page, name: string, enabled: boolean) =>
|
||
p.waitForFunction(
|
||
([n, e]) => [...document.querySelectorAll('.rk-bar button')].some((b) => b.textContent === n && b.hasAttribute('disabled') !== e),
|
||
[name, enabled] as const,
|
||
{ timeout: 5000 },
|
||
);
|
||
for (let n = 0; n < turns; n++) {
|
||
let mover: Page | null = null;
|
||
for (let t = 0; t < 150 && !mover; t++) {
|
||
for (const p of pages) if (!mover && (await myTurn(p))) mover = p;
|
||
if (!mover) await pages[0]!.waitForTimeout(100);
|
||
}
|
||
if (!mover) throw new Error(`nobody has the turn (turn ${n + 1})`);
|
||
const others = pages.filter((p) => p !== mover);
|
||
await bar(mover).waitFor();
|
||
let played = false;
|
||
await bar(mover).getByRole('button', { name: '도와줘' }).click();
|
||
const picked = await mover.locator('.rk-rack button[aria-pressed="true"]').count();
|
||
if (picked > 0) {
|
||
// Tap one picked tile twice (deselect, select again) — the tap-to-select path.
|
||
const first = mover.locator('.rk-rack button[aria-pressed="true"]').first();
|
||
const id = (await first.getAttribute('data-tile'))!;
|
||
await first.click();
|
||
await mover.waitForTimeout(450); // not a double tap
|
||
await mover.locator(`.rk-rack [data-tile="${id}"]`).click();
|
||
if (!stats.dragged) {
|
||
// Drag the picked tiles onto the grid (mouse), row 2, column 2.
|
||
const tile = await mover.locator(`.rk-rack [data-tile="${id}"]`).boundingBox();
|
||
const board = await mover.locator('.rk-board').boundingBox();
|
||
if (!tile || !board) throw new Error('no tile / board box');
|
||
await mover.mouse.move(tile.x + tile.width / 2, tile.y + tile.height / 2);
|
||
await mover.mouse.down();
|
||
const cw = board.width / 20;
|
||
const tx = board.x + cw * 2.5;
|
||
const ty = board.y + cw * 1.36 * 2.5;
|
||
for (let k = 1; k <= 12; k++) await mover.mouse.move(tile.x + ((tx - tile.x) * k) / 12, tile.y + ((ty - tile.y) * k) / 12);
|
||
// While the tiles are still in hand, the others see them moving (drag preview stream, face down from the rack).
|
||
for (const o of others) await o.locator('.rk-ghostrow .rk-back').first().waitFor({ timeout: 5000 });
|
||
// The last position reaches them too (trailing preview), so the ghost row ends up over the board.
|
||
for (const o of others)
|
||
await o.waitForFunction(
|
||
() => {
|
||
const g = document.querySelector('.rk-ghostrow .rk-back')?.getBoundingClientRect();
|
||
const b = document.querySelector('.rk-board')?.getBoundingClientRect();
|
||
return !!g && !!b && g.top < b.top + b.height / 2;
|
||
},
|
||
null,
|
||
{ timeout: 5000 },
|
||
);
|
||
await mover.screenshot({ path: join(SHOTS, 'rummikub-3-dragging.png') });
|
||
await others[0]!.screenshot({ path: join(SHOTS, 'rummikub-4-dragging-seen-by-other.png') });
|
||
await mover.mouse.up();
|
||
await mover.locator(`.rk-board [data-tile="${id}"]`).waitFor({ timeout: 5000 });
|
||
// Everybody else sees the tile on the table right away (before 완료).
|
||
for (const o of others) await o.locator(`.rk-board [data-tile="${id}"]`).waitFor({ timeout: 5000 });
|
||
await barButton(mover, '되돌리기', true);
|
||
await bar(mover).getByRole('button', { name: '되돌리기' }).click();
|
||
await mover.locator(`.rk-rack [data-tile="${id}"]`).waitFor({ timeout: 5000 });
|
||
for (const o of others) await o.locator(`.rk-board [data-tile="${id}"]`).waitFor({ state: 'detached', timeout: 5000 });
|
||
stats.dragged = true;
|
||
await bar(mover).getByRole('button', { name: '도와줘' }).click();
|
||
}
|
||
await bar(mover).getByRole('button', { name: '새 묶음' }).click();
|
||
await mover.locator(`.rk-board [data-tile="${id}"]`).waitFor({ timeout: 5000 });
|
||
const commit = bar(mover).getByRole('button', { name: '완료' });
|
||
await mover
|
||
.waitForFunction(() => [...document.querySelectorAll('.rk-bar button')].some((b) => b.textContent === '완료' && b.classList.contains('btn-primary') && !b.hasAttribute('disabled')), null, { timeout: 5000 })
|
||
.then(
|
||
() => (played = true),
|
||
() => {},
|
||
);
|
||
if (played) {
|
||
await commit.click();
|
||
stats.plays++;
|
||
} else {
|
||
await bar(mover).getByRole('button', { name: '되돌리기' }).click();
|
||
await mover.waitForTimeout(300);
|
||
}
|
||
}
|
||
if (!played) {
|
||
await bar(mover).getByRole('button', { name: /^(한 장 가져오기|넘기기)$/ }).click();
|
||
const sheet = mover.getByRole('button', { name: /^되돌리고/ });
|
||
if (await sheet.count()) await sheet.click();
|
||
stats.draws++;
|
||
}
|
||
await mover.waitForFunction(() => !document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 5000 });
|
||
}
|
||
console.log(` rummikub: ${stats.plays} plays, ${stats.draws} draws, drag ${stats.dragged ? 'used' : 'not used'}`);
|
||
return stats;
|
||
}
|
||
|
||
/**
|
||
* 윷놀이: one UI step for whoever can act on `p` — press the throw button, or pick a result chip →
|
||
* a glowing piece (or the waiting-piece tray) → "이동하기" (the two-step move confirmation).
|
||
*/
|
||
const yutChoiceSeen = new Set<string>();
|
||
async function yutStep(p: Page): Promise<boolean> {
|
||
const throwBtn = p.getByRole('button', { name: /윷 던지기|한 번 더 던지기/ });
|
||
if ((await throwBtn.count()) && (await throwBtn.isEnabled().catch(() => false))) {
|
||
return throwBtn.click({ timeout: 1500 }).then(() => true, () => false);
|
||
}
|
||
const chip = p.locator('.yut-chip:not([disabled])').first();
|
||
if (!(await chip.count())) return false;
|
||
try {
|
||
await chip.click({ timeout: 1500 });
|
||
const src = p.locator('g.yut-hit[tabindex="0"], .yut-tray-btn.can').first();
|
||
await src.waitFor({ timeout: 2000 });
|
||
// Keyboard: Enter on a piece shows where it lands, Enter again on the same piece moves it.
|
||
const h = await src.elementHandle({ timeout: 1000 });
|
||
await h!.focus();
|
||
await p.keyboard.press('Enter');
|
||
await p.getByRole('button', { name: /^이동하기/ }).waitFor({ timeout: 1500 });
|
||
// 지역 룰 choices (갈 길 고르기 / 따로 두기): the first time each shows up, take the other option and save a picture.
|
||
let apart = false;
|
||
for (const [group, tag] of [['갈 길 고르기', 'road'], ['업을지 따로 둘지 고르기', 'apart']] as const) {
|
||
const g = p.getByRole('group', { name: group });
|
||
if (yutChoiceSeen.has(tag) || !(await g.count())) continue;
|
||
yutChoiceSeen.add(tag);
|
||
apart ||= tag === 'apart';
|
||
await g.getByRole('button').nth(1).click();
|
||
await p.waitForTimeout(150);
|
||
await p.screenshot({ path: join(SHOTS, `yut-choice-${tag}-${p.viewportSize()!.width < 600 ? 'phone' : 'pc'}.png`), fullPage: p.viewportSize()!.width < 600 });
|
||
}
|
||
await h!.focus();
|
||
await p.keyboard.press('Enter');
|
||
if (apart) {
|
||
// Two stacks of the same side standing apart on one node are drawn side by side.
|
||
await p.waitForTimeout(1200);
|
||
await p.locator('.yut-board').screenshot({ path: join(SHOTS, 'yut-apart-board.png') });
|
||
}
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 고스톱: one UI step for `p` if it has something to do — answer an open decision sheet (고/스톱: 고 once, then 스톱;
|
||
* choose a floor card; 흔들기/폭탄; 총통 → 그냥 치기; 국진) or play a hand card (green-bordered match first; phones
|
||
* use tap-to-lift, so a lifted card is tapped again). Returns what it did, or null.
|
||
*/
|
||
async function gostopStep(p: Page, state: { go: number; stop: number; picks: number; plays: number; sheets: number }): Promise<string | null> {
|
||
const dialog = p.getByRole('dialog');
|
||
if (await dialog.count()) {
|
||
const name = (await dialog.first().getAttribute('aria-label')) ?? '';
|
||
if (name === '게임 결과') return null;
|
||
if (name === '고 또는 스톱') {
|
||
const goFirst = state.go === 0;
|
||
if (goFirst && state.stop === 0) await p.screenshot({ path: join(SHOTS, 'gostop-gostop-dialog.png') });
|
||
await dialog.getByRole('button', { name: goFirst ? /^고/ : /^스톱/ }).click({ timeout: 1500 });
|
||
if (goFirst) state.go++;
|
||
else state.stop++;
|
||
return goFirst ? 'go' : 'stop';
|
||
}
|
||
if (name === '총통') {
|
||
await dialog.getByRole('button', { name: /^그냥 치기/ }).click({ timeout: 1500 });
|
||
return 'chongtong';
|
||
}
|
||
const pick = dialog.locator('.gs-pick button, .gs-big .btn').first();
|
||
if (await pick.count()) {
|
||
if (state.sheets === 0) await p.screenshot({ path: join(SHOTS, 'gostop-choice-dialog.png') });
|
||
await pick.click({ timeout: 1500 });
|
||
state.sheets++;
|
||
if (name.includes('고르기')) state.picks++;
|
||
return name;
|
||
}
|
||
return null;
|
||
}
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.includes('내 차례예요')) return null;
|
||
const card = p.locator('.gs-hcard[data-match="true"]:not([disabled])').first();
|
||
const any = p.locator('.gs-hcard:not([disabled])').first();
|
||
const target = (await card.count()) ? card : any;
|
||
if (!(await target.count())) {
|
||
const dummy = p.getByRole('button', { name: /^빈패 내기/ });
|
||
if (await dummy.isEnabled().catch(() => false)) {
|
||
await dummy.click({ timeout: 1500 });
|
||
state.plays++;
|
||
return 'dummy';
|
||
}
|
||
return null;
|
||
}
|
||
const label = await target.getAttribute('aria-label');
|
||
await target.click({ timeout: 1500 });
|
||
const lifted = p.locator(`.gs-hcard[data-lifted="true"][aria-label="${label}"]`);
|
||
if (await lifted.count()) await lifted.click({ timeout: 1500 });
|
||
state.plays++;
|
||
return 'play';
|
||
}
|
||
|
||
/** 할리갈리: fruit totals of the face-up tops, read from the seat labels ("펼친 카드 딸기 3개"). */
|
||
async function halliTotals(p: Page): Promise<Record<string, number>> {
|
||
const labels = await p.locator('.hg-seat').evaluateAll((els) => els.map((e) => e.getAttribute('aria-label') ?? ''));
|
||
const t: Record<string, number> = { 딸기: 0, 바나나: 0, 라임: 0, 자두: 0 };
|
||
for (const l of labels) {
|
||
const m = /펼친 카드 (딸기|바나나|라임|자두) (\d)개/.exec(l);
|
||
if (m) t[m[1]!]! += Number(m[2]);
|
||
}
|
||
return t;
|
||
}
|
||
|
||
/**
|
||
* 부루마불: one UI step for whoever can act on `p` — answer a trade, sell, buy/build (or skip),
|
||
* pick a space-travel square on the board, escape the island or roll. Returns the label pressed.
|
||
*/
|
||
const tag = (p: Page) => ((p.viewportSize()?.width ?? 0) < 600 ? 'phone' : 'pc');
|
||
async function marbleStep(p: Page, stats: Record<string, number>): Promise<string | null> {
|
||
const prompt = p.locator('.mb-prompt.mine');
|
||
if (!(await prompt.count())) return null;
|
||
const btn = (name: string | RegExp) => prompt.getByRole('button', { name, exact: typeof name === 'string' });
|
||
const press = async (name: string | RegExp) => {
|
||
const b = btn(name);
|
||
if (!(await b.count()) || !(await b.first().isEnabled().catch(() => false))) return false;
|
||
return b.first().click({ timeout: 1500 }).then(() => true, () => false);
|
||
};
|
||
// Space travel: tap a glowing square on the board, check the preview, fly there.
|
||
if (await btn(/^출발로 가기/).count()) {
|
||
const cell = p.locator('g.mb-cell.pick').nth(5 + (stats.space ?? 0) * 7);
|
||
await cell.click({ timeout: 1500 }).catch(() => {});
|
||
const go = p.getByRole('button', { name: '🚀 여기로 가기' });
|
||
if (await go.waitFor({ timeout: 1500 }).then(() => true, () => false)) {
|
||
await p.getByText('여기로 가면').waitFor({ timeout: 1000 });
|
||
if (!stats.space) await p.screenshot({ path: join(SHOTS, `marble-space-${tag(p)}.png`) });
|
||
await go.click();
|
||
stats.space = (stats.space ?? 0) + 1;
|
||
return 'space';
|
||
}
|
||
return (await press(/^출발로 가기/)) ? 'space-start' : null;
|
||
}
|
||
// First buy prompt on each screen size, for the visual check.
|
||
const shotKey = `shot-${tag(p)}`;
|
||
if (!stats[shotKey] && (await btn('사기').count())) {
|
||
stats[shotKey] = 1;
|
||
await p.screenshot({ path: join(SHOTS, `marble-buy-${tag(p)}.png`) });
|
||
}
|
||
for (const name of ['거절', /^가장 싼 것부터 팔기/, '사기', '짓기', '인수하기', '🎲 탈출 굴리기', '🎲 주사위 굴리기', '🎲 한 번 더 굴리기', '안 사기', '안 짓기', '안 하기'] as const) {
|
||
if (await press(name)) {
|
||
const key = typeof name === 'string' ? name : 'sell';
|
||
stats[key] = (stats[key] ?? 0) + 1;
|
||
return key;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 달무티: one UI step for `p` — confirm the hand, give tax cards back (suggested cards), or on its turn pick a
|
||
* number group (a "광대 필요" group first; leads mix a jester in via the toggle) and press "내기", passing now
|
||
* and then. The host uses the keyboard (focus + Enter) for the group. Returns what it did, or null.
|
||
*/
|
||
async function dalmutiStep(p: Page, isHost: boolean, st: Record<string, number>): Promise<string | null> {
|
||
const enabled = async (l: ReturnType<Page['locator']>) => (await l.count()) > 0 && (await l.first().isEnabled().catch(() => false));
|
||
const confirm = p.getByRole('button', { name: '손패 확인', exact: true });
|
||
if (await enabled(confirm)) {
|
||
await confirm.click({ timeout: 1500 });
|
||
return 'confirm';
|
||
}
|
||
const giveBack = p.getByRole('button', { name: /^돌려주기/ });
|
||
if (await enabled(giveBack)) {
|
||
if (!st[`taxshot-${tag(p)}`] && (await p.getByText('1라운드 결과 → 새 신분').count())) {
|
||
st[`taxshot-${tag(p)}`] = 1;
|
||
await p.screenshot({ path: join(SHOTS, `dalmuti-tax-${tag(p)}.png`) });
|
||
await p.emulateMedia({ colorScheme: 'dark' });
|
||
await p.waitForTimeout(400);
|
||
await p.screenshot({ path: join(SHOTS, `dalmuti-tax-${tag(p)}-dark.png`) });
|
||
await p.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
await giveBack.click({ timeout: 1500 });
|
||
return 'return';
|
||
}
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.includes('내 차례예요')) return null;
|
||
const pass = p.getByRole('button', { name: '패스', exact: true });
|
||
const canPass = await enabled(pass);
|
||
const legal = p.locator('button.dm-group[data-legal="true"]');
|
||
const n = await legal.count();
|
||
if (n === 0 || (canPass && st.turns! % 4 === 3)) {
|
||
if (!canPass) return null;
|
||
await pass.click({ timeout: 1500 });
|
||
st.turns!++;
|
||
st.passes = (st.passes ?? 0) + 1;
|
||
return 'pass';
|
||
}
|
||
const needs = p.locator('button.dm-group[data-legal="true"]', { hasText: '광대 필요' });
|
||
const lead = status.includes('새로 시작');
|
||
const jesterGroup = p.locator('button.dm-group[data-legal="true"][data-n="13"]');
|
||
let target = legal.last();
|
||
if (await needs.count()) target = needs.last();
|
||
else if (lead && (await jesterGroup.count()) && n > 1) target = legal.nth(n - 2);
|
||
if (isHost) {
|
||
await target.focus();
|
||
await p.keyboard.press('Enter');
|
||
st.hostKeys = (st.hostKeys ?? 0) + 1;
|
||
} else await target.click({ timeout: 1500 });
|
||
const toggle = p.locator('.dm-toggle');
|
||
if (lead && (await enabled(toggle)) && (await toggle.getAttribute('aria-pressed')) === 'false') await toggle.click({ timeout: 1500 });
|
||
const play = p.getByRole('button', { name: /^내기 \(/ });
|
||
if (!(await enabled(play))) return null;
|
||
const summary = await p.locator('.dm-pick .small').innerText().catch(() => '');
|
||
if (!st[`pickshot-${tag(p)}`]) {
|
||
st[`pickshot-${tag(p)}`] = 1;
|
||
await p.screenshot({ path: join(SHOTS, `dalmuti-pick-${tag(p)}.png`) });
|
||
}
|
||
if (summary.includes('광대')) st.jesterPlays = (st.jesterPlays ?? 0) + 1;
|
||
await play.click({ timeout: 1500 });
|
||
st.turns!++;
|
||
st.plays = (st.plays ?? 0) + 1;
|
||
return 'play';
|
||
}
|
||
|
||
/**
|
||
* 스플렌더: one UI action for whoever has the turn on `p` — return tokens / choose a noble / pass when
|
||
* asked, otherwise buy a highlighted card, reserve now and then, take 2 of a colour, or 3 different gems.
|
||
* Returns the kind of action or null when it isn't this page's turn.
|
||
*/
|
||
async function splendorStep(p: Page, stats: Record<string, number>, turn: number): Promise<string | null> {
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.startsWith('내 차례예요')) return null;
|
||
const phone = (p.viewportSize()?.width ?? 0) < 600;
|
||
const press = async (l: ReturnType<Page['locator']>) => {
|
||
if (phone) await l.tap({ timeout: 2000 });
|
||
else if (turn % 2 === 0) {
|
||
// Keyboard path on PC every other turn: focus + Enter.
|
||
await l.focus({ timeout: 2000 });
|
||
await p.keyboard.press('Enter');
|
||
} else await l.click({ timeout: 2000 });
|
||
};
|
||
const panel = p.locator('.sp-panel');
|
||
if (status.includes('돌려놓아')) {
|
||
const need = Number(status.match(/(\d+)개를 돌려놓아/)?.[1] ?? 0);
|
||
for (let i = 0; i < need; i++) await press(panel.locator('.sp-basket').first().locator('button.sp-token').first());
|
||
await press(panel.getByRole('button', { name: `돌려놓기 (${need}/${need})` }));
|
||
return 'discard';
|
||
}
|
||
if (status.includes('귀족 중 한 명')) {
|
||
await press(panel.getByRole('button', { name: /이 귀족 고르기$/ }).first());
|
||
return 'noble';
|
||
}
|
||
if (status.includes('넘겨야')) {
|
||
await press(panel.getByRole('button', { name: '차례 넘기기' }));
|
||
const ok = p.getByRole('button', { name: '넘기기', exact: true });
|
||
if (await ok.isVisible({ timeout: 500 }).catch(() => false)) await ok.click();
|
||
return 'pass';
|
||
}
|
||
const affordable = p.locator('.sp-market button.sp-card.can, .sp-market button.sp-card.gold, .sp-mine button.sp-card.can, .sp-mine button.sp-card.gold');
|
||
const reserveTurn = (stats.reserve ?? 0) < 2 && turn >= 2 && turn % 5 === 2;
|
||
// The phone player hoards gems early on (no buying) until it has had to give some back once.
|
||
const hoard = phone && !stats.discard && turn < 30;
|
||
if ((await affordable.count()) && !reserveTurn && !hoard) {
|
||
const card = affordable.first();
|
||
await press(card);
|
||
if ((await p.locator('.sp-card.gold.sel').count()) && !stats.shotPay) {
|
||
stats.shotPay = 1;
|
||
await p.waitForTimeout(250);
|
||
await p.screenshot({ path: join(SHOTS, `splendor-pay-${phone ? 'phone' : 'pc'}.png`), fullPage: phone });
|
||
}
|
||
await press(panel.getByRole('button', { name: '🛒 사기' }));
|
||
return 'buy';
|
||
}
|
||
const reserveBtn = panel.getByRole('button', { name: /^📌 예약/ });
|
||
if (reserveTurn) {
|
||
// Tier 1 open card on even turns, the tier 2 deck (blind) otherwise.
|
||
const target = (stats.reserve ?? 0) === 0 ? p.locator('.sp-market .sp-row').nth(2).locator('button.sp-card').first() : p.locator('.sp-market .sp-row').nth(1).locator('button.sp-deck');
|
||
await press(target);
|
||
if (await reserveBtn.isEnabled({ timeout: 800 }).catch(() => false)) {
|
||
await press(reserveBtn);
|
||
return 'reserve';
|
||
}
|
||
await press(panel.getByRole('button', { name: '닫기' }));
|
||
}
|
||
const tokens = p.locator('.sp-bank button.sp-token:not([disabled])');
|
||
const counts = await tokens.evaluateAll((els) => els.map((e) => Number(e.querySelector('.ct')?.textContent ?? 0)));
|
||
const four = counts.findIndex((n) => n >= 4);
|
||
if ((stats.same ?? 0) < 2 && four >= 0 && turn % 3 === 1) {
|
||
await press(tokens.nth(four));
|
||
await press(tokens.nth(four));
|
||
await press(panel.getByRole('button', { name: '💎 가져오기 (2개)' }));
|
||
return 'same';
|
||
}
|
||
const want = Number((await panel.locator('.sp-basket').innerText()).match(/서로 다른 색 (\d)개/)?.[1] ?? 3);
|
||
let picked = 0;
|
||
for (let i = 0; i < counts.length && picked < want; i++) {
|
||
if (counts[i]! > 0) {
|
||
await press(tokens.nth(i));
|
||
picked++;
|
||
}
|
||
}
|
||
const takeBtn = panel.getByRole('button', { name: /^💎 가져오기/ });
|
||
if (picked > 0 && (await takeBtn.isEnabled().catch(() => false))) {
|
||
await press(takeBtn);
|
||
return 'different';
|
||
}
|
||
// Nothing to take: reserve whatever is first, or buy anything.
|
||
await press(p.locator('.sp-market button.sp-card').first());
|
||
if (await reserveBtn.isEnabled({ timeout: 500 }).catch(() => false)) {
|
||
await press(reserveBtn);
|
||
return 'reserve';
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/** 쿼리도: 판의 data 속성(모델 좌표 a1~i9)을 읽어 PC는 클릭, 휴대폰은 탭으로 조작한다. */
|
||
const qdSvg = (p: Page) => p.locator('svg[data-my-seat]');
|
||
async function qdTap(p: Page, target: ReturnType<Page['locator']>) {
|
||
if (tag(p) === 'phone') await target.tap();
|
||
else await target.click();
|
||
}
|
||
async function qdWaitTurn(p: Page) {
|
||
await p.waitForFunction(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 15_000 });
|
||
}
|
||
/** 벽 세우기 모드에서 앵커를 고르고 방향을 맞춘 뒤 미리보기 값("v:d8" / "h:e7:bad")을 돌려준다. */
|
||
async function qdPreviewWall(p: Page, anchor: string, o: 'h' | 'v'): Promise<string> {
|
||
await qdWaitTurn(p);
|
||
if ((await qdSvg(p).getAttribute('data-mode')) !== 'wall') await qdTap(p, p.getByRole('button', { name: /^🧱 벽 세우기/ }));
|
||
await qdTap(p, p.locator(`[data-anchor="${anchor}"]`));
|
||
for (let k = 0; k < 3; k++) {
|
||
const pv = (await qdSvg(p).getAttribute('data-preview')) ?? '';
|
||
if (pv.startsWith(`${o}:${anchor}`)) return pv;
|
||
await qdTap(p, p.getByRole('button', { name: /벽 방향 바꾸기/ }));
|
||
}
|
||
throw new Error(`wall preview did not become ${o}:${anchor}`);
|
||
}
|
||
async function qdConfirmWall(p: Page) {
|
||
const before = await p.locator('[data-wall]').count();
|
||
await qdTap(p, p.getByRole('button', { name: '벽 세우기 확인' }));
|
||
await p.waitForFunction((n) => document.querySelectorAll('[data-wall]').length > n, before, { timeout: 5000 });
|
||
}
|
||
/** 내 최단 길(data-path)에서 가장 멀리 가는 이동 가능 칸으로 한 수. 점프였으면 true. */
|
||
async function qdStep(p: Page, keyboard: boolean): Promise<boolean> {
|
||
await qdWaitTurn(p);
|
||
if ((await qdSvg(p).getAttribute('data-mode')) !== 'move') await qdTap(p, p.getByRole('button', { name: /말 움직이기/ }));
|
||
const seat = await qdSvg(p).getAttribute('data-my-seat');
|
||
const from = (await p.locator(`[data-pawn="${seat}"]`).getAttribute('data-at'))!;
|
||
const legal = await p.locator('[data-legal]').evaluateAll((els) => els.map((e) => e.getAttribute('data-cell')!));
|
||
const path = ((await qdSvg(p).getAttribute('data-path')) ?? '').split(' ');
|
||
let to = legal[0]!;
|
||
let best = -1;
|
||
for (const c of legal) if (path.indexOf(c) > best) [best, to] = [path.indexOf(c), c];
|
||
if (keyboard && to === path[0]) {
|
||
// 커서는 내 말에서 시작하고 화면 위쪽이 항상 내 목표 방향.
|
||
await keys(p, ['ArrowUp', 'Enter']);
|
||
} else {
|
||
await qdTap(p, p.locator(`[data-cell="${to}"]`));
|
||
const confirm = p.getByRole('button', { name: /으로 이동$/ });
|
||
if (await confirm.count()) await qdTap(p, confirm);
|
||
}
|
||
await p.waitForFunction((t) => document.querySelector(`[data-pawn] [data-at="${t}"], [data-at="${t}"]`) !== null, to, { timeout: 5000 });
|
||
const d = Math.abs(from.charCodeAt(0) - to.charCodeAt(0)) + Math.abs(Number(from.slice(1)) - Number(to.slice(1)));
|
||
return d === 2;
|
||
}
|
||
|
||
/**
|
||
* 라스베가스: one UI step for `p` — press "주사위 굴리기", or pick a number group (every other pick prefers a group
|
||
* marked "동점 주의" so duplicate-tie cancellations really happen) and confirm "N번 카지노에 M개 놓기".
|
||
* The PC host's first pick uses the keyboard, its second one taps the casino card instead of the group.
|
||
*/
|
||
async function lasVegasStep(
|
||
p: Page,
|
||
phone: boolean,
|
||
st: { rolls: number; places: number; keyboard: boolean; casinoPick: boolean; shots: Set<string> },
|
||
): Promise<boolean> {
|
||
const press = (l: ReturnType<Page['locator']>) => (phone ? l.tap({ timeout: 1500 }) : l.click({ timeout: 1500 }));
|
||
const roll = p.getByRole('button', { name: /^🎲 주사위 굴리기/ });
|
||
if ((await roll.count()) && (await roll.isEnabled().catch(() => false))) {
|
||
if (!(await press(roll).then(() => true, () => false))) return false;
|
||
st.rolls++;
|
||
return true;
|
||
}
|
||
const groups = p.locator('.lv-group:not([disabled])');
|
||
if (!(await groups.count())) return false;
|
||
try {
|
||
const tie = p.locator('.lv-group:not([disabled])[data-standing="tie"]');
|
||
const target = st.places % 2 === 1 && (await tie.count()) ? tie.first() : groups.first();
|
||
const confirm = p.getByRole('button', { name: /번 카지노에 \d+개 놓기$/ });
|
||
if (!phone && !st.keyboard) {
|
||
// Keyboard only: Enter on a number group, then Enter on the confirm button.
|
||
await target.focus();
|
||
await p.keyboard.press('Enter');
|
||
await confirm.waitFor({ timeout: 1500 });
|
||
await confirm.focus();
|
||
await p.keyboard.press('Enter');
|
||
st.keyboard = true;
|
||
} else if (!phone && !st.casinoPick) {
|
||
// Choose by tapping the highlighted casino card instead of the group button.
|
||
await p.locator('button.lv-casino').first().click({ timeout: 1500 });
|
||
await confirm.waitFor({ timeout: 1500 });
|
||
st.casinoPick = true;
|
||
await confirm.click({ timeout: 1500 });
|
||
} else {
|
||
await press(target);
|
||
await confirm.waitFor({ timeout: 1500 });
|
||
const tag = phone ? 'phone' : 'pc';
|
||
if (st.places >= 6 && !st.shots.has(tag)) {
|
||
// Mid-game: a number group chosen, casino highlighted with its preview tag, light + dark.
|
||
st.shots.add(tag);
|
||
if (phone) await p.evaluate(() => window.scrollTo(0, 0));
|
||
await p.screenshot({ path: join(SHOTS, `las-vegas-mid-${tag}.png`) });
|
||
if (phone) await p.screenshot({ path: join(SHOTS, `las-vegas-mid-${tag}-full.png`), fullPage: true });
|
||
await p.emulateMedia({ colorScheme: 'dark' });
|
||
await p.waitForTimeout(250);
|
||
await p.screenshot({ path: join(SHOTS, `las-vegas-mid-${tag}-dark.png`) });
|
||
await p.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
await press(confirm);
|
||
}
|
||
st.places++;
|
||
await p.waitForFunction(() => !document.querySelector('.lv-group[aria-pressed="true"]'), null, { timeout: 5000 });
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 바퀴벌레 포커: one UI step for whoever must act on `p` — offer (card → person → claim → confirm), pass after
|
||
* peeking (person → claim → confirm) or answer an offer (진짜!/거짓말!, sometimes 몰래 보고 넘기기).
|
||
*/
|
||
async function cockroachStep(p: Page, stats: Record<string, number>): Promise<string | null> {
|
||
const status = await p.locator('.turn-status').innerText().catch(() => '');
|
||
if (!status.includes('내 차례예요')) return null;
|
||
const panel = p.locator('.cp-panel').first();
|
||
const offering = (await panel.getByText('카드를 건네 주세요', { exact: true }).count()) > 0;
|
||
if (offering || (await panel.getByText('본 카드를 다른 사람에게 넘겨 주세요', { exact: true }).count())) {
|
||
const give = panel.getByRole('button', { name: /(건네기|넘기기)$/ });
|
||
const n = (stats.offer ?? 0) + (stats.pass ?? 0);
|
||
if (offering) {
|
||
const cards = panel.locator('.cp-hand button.cp-pick');
|
||
await cards.nth(n % (await cards.count())).click();
|
||
}
|
||
const targets = panel.locator('button.cp-target:not([disabled])');
|
||
await targets.nth(n % (await targets.count())).click();
|
||
await panel.locator('button.cp-claim').nth((n * 3) % 8).click();
|
||
if (!stats[`shot-give-${tag(p)}`]) {
|
||
stats[`shot-give-${tag(p)}`] = 1;
|
||
await p.screenshot({ path: join(SHOTS, `cockroach-poker-give-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
|
||
}
|
||
await give.click({ timeout: 2000 });
|
||
stats[offering ? 'offer' : 'pass'] = (stats[offering ? 'offer' : 'pass'] ?? 0) + 1;
|
||
return offering ? 'offer' : 'pass';
|
||
}
|
||
const yes = panel.getByRole('button', { name: /^진짜!/ });
|
||
if (await yes.count()) {
|
||
if (!stats[`shot-respond-${tag(p)}`]) {
|
||
stats[`shot-respond-${tag(p)}`] = 1;
|
||
await p.screenshot({ path: join(SHOTS, `cockroach-poker-respond-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
|
||
}
|
||
const peek = panel.getByRole('button', { name: '👁 몰래 보고 넘기기' });
|
||
const calls = (stats.true ?? 0) + (stats.false ?? 0);
|
||
if ((await peek.isEnabled().catch(() => false)) && calls % 3 === 1) {
|
||
await peek.click();
|
||
await panel.getByText('본 카드를 다른 사람에게 넘겨 주세요').waitFor({ timeout: 3000 });
|
||
stats.peek = (stats.peek ?? 0) + 1;
|
||
return 'peek';
|
||
}
|
||
const which = calls % 2 === 0 ? 'true' : 'false';
|
||
await panel.getByRole('button', { name: which === 'true' ? /^진짜!/ : /^거짓말!/ }).click();
|
||
stats[which] = (stats[which] ?? 0) + 1;
|
||
return which;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
const nnShots = new Set<string>();
|
||
/** 구십구: one turn for whoever shows "내 차례예요" — joker via the dial, ± via its buttons, 0, else a number card. */
|
||
async function ninetyNineStep(p: Page, stats: Record<string, number>): Promise<boolean> {
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.includes('내 차례예요')) return false;
|
||
const total = Number(/합계 (\d+)/.exec(status)?.[1] ?? 0);
|
||
const phone = tag(p) === 'phone';
|
||
const press = async (l: ReturnType<Page['locator']>) => (phone ? l.tap() : l.click());
|
||
const cards = p.locator('button.nn-card[data-legal="true"]');
|
||
const n = await cards.count();
|
||
if (!n) return false;
|
||
const info: { i: number; label: string; prev: number }[] = [];
|
||
for (let i = 0; i < n; i++) {
|
||
const label = (await cards.nth(i).getAttribute('aria-label')) ?? '';
|
||
const prev = Number(/→ (\d+)/.exec(await cards.nth(i).locator('.nn-prev').innerText())?.[1] ?? -1);
|
||
info.push({ i, label, prev });
|
||
}
|
||
const joker = info.find((c) => c.label.startsWith('조커'));
|
||
const pm = info.find((c) => c.label.startsWith('±'));
|
||
const zero = info.find((c) => c.label.startsWith('0 카드'));
|
||
const nums = info.filter((c) => c.prev >= 0 && !c.label.startsWith('0 카드')).sort((a, b) => a.prev - b.prev);
|
||
if (joker && (total >= 40 || !nums.length)) {
|
||
await press(cards.nth(joker.i));
|
||
await press(p.getByRole('button', { name: '99', exact: true }));
|
||
if (!nnShots.has(`joker-${tag(p)}`)) {
|
||
nnShots.add(`joker-${tag(p)}`);
|
||
await p.screenshot({ path: join(SHOTS, `ninety-nine-joker-${tag(p)}.png`) });
|
||
}
|
||
await press(p.getByRole('button', { name: '1 작게' }));
|
||
await press(p.getByRole('button', { name: /^조커 내기 → 98$/ }));
|
||
stats.joker = (stats.joker ?? 0) + 1;
|
||
} else if (pm) {
|
||
await press(cards.nth(pm.i));
|
||
if (!nnShots.has(`pm-${tag(p)}`)) {
|
||
nnShots.add(`pm-${tag(p)}`);
|
||
await p.screenshot({ path: join(SHOTS, `ninety-nine-plusminus-${tag(p)}.png`) });
|
||
}
|
||
const plus = p.locator('.nn-pick button', { hasText: /^\+/ });
|
||
const minus = p.locator('.nn-pick button', { hasText: /^−/ });
|
||
const usePlus = (await plus.isEnabled()) && (total < 70 || !(await minus.isEnabled()));
|
||
await press(usePlus ? plus : minus);
|
||
stats[usePlus ? 'plus' : 'minus'] = (stats[usePlus ? 'plus' : 'minus'] ?? 0) + 1;
|
||
} else if (zero && (total >= 60 || !nums.length)) {
|
||
// The 0 card asks whether to keep or reverse the direction: alternate between the two.
|
||
const reverse = (stats.reverse ?? 0) <= (stats.keep ?? 0);
|
||
await press(cards.nth(zero.i));
|
||
await press(p.locator('.nn-pick button', { hasText: reverse ? /^방향 바꾸기/ : /^방향 그대로/ }));
|
||
stats[reverse ? 'reverse' : 'keep'] = (stats[reverse ? 'reverse' : 'keep'] ?? 0) + 1;
|
||
} else {
|
||
// Small cards while the total is low (longer game, more cards seen), then the biggest one.
|
||
const pick = total < 55 ? nums[0]! : nums[nums.length - 1]!;
|
||
const card = cards.nth(pick.i);
|
||
if (phone) {
|
||
await card.tap();
|
||
await card.tap();
|
||
} else {
|
||
await card.focus();
|
||
await p.keyboard.press('Enter');
|
||
await p.keyboard.press('Enter');
|
||
}
|
||
stats.number = (stats.number ?? 0) + 1;
|
||
}
|
||
await p.waitForFunction((s) => document.querySelector('.turn-status')?.textContent?.trim() !== s, status, { timeout: 5000 }).catch(() => {});
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 도둑잡기: whoever shows "내 차례예요" draws one face-down card from the fan. PC: mouse click (one click draws) or now and
|
||
* then the keyboard (focus, → , Enter); phones: tap to pick (the card lifts), tap again to draw (tapConfirm).
|
||
*/
|
||
async function oldMaidStep(p: Page, stats: Record<string, number>): Promise<boolean> {
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.includes('내 차례예요')) return false;
|
||
const cards = p.locator('.om-fan button.om-back');
|
||
const n = await cards.count();
|
||
if (!n) return false;
|
||
const draws = stats.draws ?? 0;
|
||
const card = cards.nth((draws * 7) % n);
|
||
if (tag(p) === 'phone') {
|
||
await card.tap();
|
||
if ((await card.getAttribute('aria-pressed')) === 'true') {
|
||
if (!stats[`shot-pick-${tag(p)}`]) {
|
||
stats[`shot-pick-${tag(p)}`] = 1;
|
||
await p.screenshot({ path: join(SHOTS, 'old-maid-pick-phone.png'), fullPage: true });
|
||
}
|
||
await card.tap();
|
||
stats.confirm = (stats.confirm ?? 0) + 1;
|
||
}
|
||
} else if ((stats.pc = (stats.pc ?? 0) + 1) % 3 === 2 && n > 1) {
|
||
await cards.first().focus();
|
||
await p.keyboard.press('ArrowRight');
|
||
await p.keyboard.press('Enter');
|
||
stats.keyboard = (stats.keyboard ?? 0) + 1;
|
||
} else {
|
||
await card.click();
|
||
stats.click = (stats.click ?? 0) + 1;
|
||
}
|
||
stats.draws = draws + 1;
|
||
await p.waitForFunction((s) => document.querySelector('.turn-status')?.textContent?.trim() !== s, status, { timeout: 5000 }).catch(() => {});
|
||
return true;
|
||
}
|
||
|
||
/** 도둑잡기: a player whose cards are being picked from shuffles them (button), a few times per game. */
|
||
async function oldMaidShuffle(p: Page, stats: Record<string, number>): Promise<boolean> {
|
||
if ((stats.shuffle ?? 0) >= 4) return false;
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.includes('내 카드를 고르는 중')) return false;
|
||
const btn = p.getByRole('button', { name: /^🔀 섞기/ });
|
||
if (!(await btn.isEnabled().catch(() => false))) return false;
|
||
const before = await p.locator('.om-hand').getAttribute('aria-label');
|
||
await btn.click();
|
||
await p.waitForFunction((b) => document.querySelector('.om-hand')?.getAttribute('aria-label') !== b || !document.querySelector('.om-hand'), before, { timeout: 3000 }).catch(() => {});
|
||
stats.shuffle = (stats.shuffle ?? 0) + 1;
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 도블: one real tap on `p`'s own screen. Reads the pictures of the two compared cards from the DOM (data-art), taps the shared one
|
||
* (or, when `wrong`, a picture of my card that is not on the other). PC: focus + Enter, phone: tap. Returns the judgement shown.
|
||
*/
|
||
async function dobbleTap(p: Page, wrong: boolean): Promise<string | null> {
|
||
const arts = (side: string) => p.locator(`[data-card="${side}"] .db-sym`).evaluateAll((els) => els.map((e) => Number(e.getAttribute('data-art'))));
|
||
const mine = p.locator('[data-card="mine"] .db-sym:not([disabled])');
|
||
if ((await mine.count()) === 0) return null;
|
||
const [a, b] = await Promise.all([arts('center'), arts('mine')]);
|
||
const shared = b.filter((x) => a.includes(x));
|
||
if (shared.length !== 1) return null; // the cards changed between the two reads
|
||
const art = wrong ? b.find((x) => x !== shared[0])! : shared[0]!;
|
||
const key = await p.locator('[data-card="center"]').getAttribute('data-key');
|
||
const old = (await p.locator('.db-bubble').getAttribute('data-bubble', { timeout: 100 }).catch(() => null)) ?? '';
|
||
const btn = p.locator(`[data-card="mine"] .db-sym[data-art="${art}"]`);
|
||
if (tag(p) === 'pc') {
|
||
await btn.focus();
|
||
await p.keyboard.press('Enter');
|
||
} else await btn.tap();
|
||
// My own judgement is a new bubble (another one may still be showing).
|
||
const bubble = await p
|
||
.locator(`.db-bubble:not([data-bubble="${old}"])`)
|
||
.first()
|
||
.innerText({ timeout: 1500 })
|
||
.then((t) => t.trim())
|
||
.catch(() => '');
|
||
if (!wrong) await p.waitForFunction((k) => document.querySelector('[data-card="center"]')?.getAttribute('data-key') !== k, key, { timeout: 1500 }).catch(() => {});
|
||
return bubble;
|
||
}
|
||
|
||
/** 사과 게임: my board as the screen draws it (display rows × columns, 0 = empty) and where the SVG sits on the page. */
|
||
async function appleGrid(p: Page) {
|
||
return p.evaluate(() => {
|
||
const svg = document.querySelector('svg.ap-board')!;
|
||
const [, , w, h] = svg.getAttribute('viewBox')!.split(' ').map(Number);
|
||
const dC = w! / 40;
|
||
const dR = h! / 40;
|
||
const grid = Array.from({ length: dR }, () => Array<number>(dC).fill(0));
|
||
for (const g of svg.querySelectorAll(':scope > g[transform]')) {
|
||
const m = /translate\(([\d.]+) ([\d.]+)\)/.exec(g.getAttribute('transform') ?? '');
|
||
if (m) grid[Number(m[2]) / 40]![Number(m[1]) / 40] = Number(g.textContent);
|
||
}
|
||
const b = svg.getBoundingClientRect();
|
||
return { grid, dR, dC, box: { x: b.left, y: b.top, w: b.width, h: b.height } };
|
||
});
|
||
}
|
||
|
||
/** 사과 게임: a rectangle (display cells) whose apples add up to `want` (10, or anything else for a deliberate miss), smallest first. */
|
||
function appleFind(grid: number[][], want: number): [number, number, number, number] | null {
|
||
const R = grid.length;
|
||
const C = grid[0]!.length;
|
||
let best: [number, number, number, number] | null = null;
|
||
let bestArea = Infinity;
|
||
for (let r0 = 0; r0 < R; r0++)
|
||
for (let c0 = 0; c0 < C; c0++)
|
||
for (let r1 = r0; r1 < R; r1++)
|
||
for (let c1 = c0; c1 < C; c1++) {
|
||
const area = (r1 - r0 + 1) * (c1 - c0 + 1);
|
||
if (area >= bestArea || area < 2) continue;
|
||
let sum = 0;
|
||
let n = 0;
|
||
for (let r = r0; r <= r1; r++) for (let c = c0; c <= c1; c++) if (grid[r]![c]) (sum += grid[r]![c]!), n++;
|
||
if (n >= 2 && (want === 10 ? sum === 10 : sum !== 10 && sum < 10)) {
|
||
best = [r0, c0, r1, c1];
|
||
bestArea = area;
|
||
}
|
||
}
|
||
return best;
|
||
}
|
||
|
||
/** 사과 게임: my score from the 🍎 pill. */
|
||
const appleScore = (p: Page) => p.locator('.ap-top .ap-pill', { hasText: '🍎' }).innerText().then((t) => Number(t.replace(/\D/g, '')));
|
||
|
||
/**
|
||
* 사과 게임: one real drag on `p` from display cell (r0, c0) to (r1, c1) — PC: the mouse, phone: touch through CDP (real
|
||
* touch events, so the board gets pointerType "touch"). Moves in a few steps like a finger.
|
||
*/
|
||
async function appleDrag(p: Page, rect: [number, number, number, number], touch: boolean) {
|
||
await p.locator('svg.ap-board').evaluate((el) => el.scrollIntoView({ block: 'nearest' }));
|
||
const { box, dR, dC } = await appleGrid(p);
|
||
const at = (r: number, c: number) => ({ x: box.x + ((c + 0.5) * box.w) / dC, y: box.y + ((r + 0.5) * box.h) / dR });
|
||
const a = at(rect[0], rect[1]);
|
||
const b = at(rect[2], rect[3]);
|
||
const steps = 5;
|
||
if (!touch) {
|
||
await p.mouse.move(a.x, a.y);
|
||
await p.mouse.down();
|
||
await p.mouse.move(b.x, b.y, { steps });
|
||
await p.mouse.up();
|
||
return;
|
||
}
|
||
const cdp = await p.context().newCDPSession(p);
|
||
await cdp.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ x: a.x, y: a.y }] });
|
||
for (let i = 1; i <= steps; i++) {
|
||
await cdp.send('Input.dispatchTouchEvent', { type: 'touchMove', touchPoints: [{ x: a.x + ((b.x - a.x) * i) / steps, y: a.y + ((b.y - a.y) * i) / steps }] });
|
||
}
|
||
await cdp.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] });
|
||
await cdp.detach();
|
||
}
|
||
|
||
/** 그림 맞히기: non-white pixels on a page's drawing canvas (proves streamed strokes were rendered). */
|
||
async function cmInk(p: Page): Promise<number> {
|
||
return p.evaluate(() => {
|
||
const c = document.querySelector<HTMLCanvasElement>('.cm-paper canvas');
|
||
if (!c || !c.width) return 0;
|
||
const data = c.getContext('2d')!.getImageData(0, 0, c.width, c.height).data;
|
||
let n = 0;
|
||
for (let i = 0; i < data.length; i += 16) if (data[i]! < 200 || data[i + 1]! < 200 || data[i + 2]! < 200) n++;
|
||
return n;
|
||
});
|
||
}
|
||
|
||
/** 그림 맞히기: one full turn — the drawer picks a word and draws with the mouse, the other sees it, guesses wrong, close, then right. */
|
||
async function catchmindTurn(pages: Page[], turn: number, shots: boolean): Promise<string> {
|
||
const tag = turn === 1 ? '' : `${turn}`;
|
||
const status = (p: Page) => p.locator('.turn-status').innerText();
|
||
let drawer: Page | null = null;
|
||
for (let t = 0; t < 150 && !drawer; t++) {
|
||
for (const p of pages) if ((await status(p)).includes('그릴 단어를 골라 주세요')) drawer = p;
|
||
if (!drawer) await pages[0]!.waitForTimeout(100);
|
||
}
|
||
if (!drawer) throw new Error(`turn ${turn}: nobody is choosing a word`);
|
||
const guesser = pages.find((p) => p !== drawer)!;
|
||
await guesser.getByText(/단어를 고르고 있어요/).first().waitFor();
|
||
const pick = drawer.locator('.cm-choices button').nth(1);
|
||
const picked = ((await pick.getAttribute('aria-label')) ?? '').split(' (')[0]!;
|
||
await pick.click();
|
||
// The plan reads the answer from the drawer's screen.
|
||
const answer = drawer.locator('.cm-hint .answer');
|
||
await answer.waitFor();
|
||
const word = (await answer.innerText()).replace(/^정답:\s*/, '').trim();
|
||
if (word !== picked) throw new Error(`picked ${picked} but the drawer sees ${word}`);
|
||
const hidden = await guesser.locator('.cm-hint').innerText();
|
||
if (hidden.includes(word)) throw new Error('the guesser sees the answer');
|
||
// Real mouse strokes on the canvas: a red zig-zag, a blue circle-ish, a thick black line.
|
||
const canvas = drawer.locator('.cm-paper canvas');
|
||
const stroke = async (pts: (readonly [number, number])[]) => {
|
||
// Tool buttons may have scrolled the page (phone): measure the canvas right before each stroke.
|
||
await canvas.scrollIntoViewIfNeeded();
|
||
const box = (await canvas.boundingBox())!;
|
||
const at = (fx: number, fy: number) => [box.x + box.width * fx, box.y + box.height * fy] as const;
|
||
await drawer!.mouse.move(...at(...pts[0]!));
|
||
await drawer!.mouse.down();
|
||
for (const pt of pts.slice(1)) await drawer!.mouse.move(...at(...pt), { steps: 6 });
|
||
await drawer!.mouse.up();
|
||
};
|
||
await drawer.getByRole('button', { name: '빨강' }).click();
|
||
await stroke([[0.2, 0.2], [0.35, 0.4], [0.5, 0.2], [0.65, 0.4], [0.8, 0.2]]);
|
||
await drawer.getByRole('button', { name: '파랑' }).click();
|
||
await stroke(Array.from({ length: 13 }, (_, i) => [0.5 + 0.2 * Math.cos((i / 12) * Math.PI * 2), 0.6 + 0.2 * Math.sin((i / 12) * Math.PI * 2)] as const));
|
||
await drawer.getByRole('button', { name: '검정' }).click();
|
||
await drawer.getByRole('button', { name: '굵기 아주 굵게' }).click();
|
||
await stroke([[0.15, 0.9], [0.85, 0.9]]);
|
||
// The guesser's canvas shows the same strokes (stroke count + ink).
|
||
await guesser.waitForFunction(() => Number(document.querySelector('.cm-paper canvas')?.getAttribute('data-strokes')) >= 3, null, { timeout: 8000 });
|
||
const inkD = await cmInk(drawer);
|
||
let inkG = 0;
|
||
for (let t = 0; t < 30 && inkG < 300; t++) {
|
||
inkG = await cmInk(guesser);
|
||
if (inkG < 300) await guesser.waitForTimeout(100);
|
||
}
|
||
if (inkD < 300 || inkG < 300) throw new Error(`turn ${turn}: no ink (drawer ${inkD}, guesser ${inkG})`);
|
||
if (shots) {
|
||
await drawer.waitForTimeout(300);
|
||
for (const [scheme, suffix] of (turn === 1 ? [['light', ''], ['dark', '-dark']] : [['light', '']]) as [string, string][]) {
|
||
await drawer.emulateMedia({ colorScheme: scheme as 'light' | 'dark' });
|
||
await guesser.emulateMedia({ colorScheme: scheme as 'light' | 'dark' });
|
||
await drawer.waitForTimeout(250);
|
||
const [pc, phone] = pages[0] === drawer ? [drawer, guesser] : [guesser, drawer];
|
||
await pc.screenshot({ path: join(SHOTS, `catchmind-draw${tag}-pc${suffix}.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `catchmind-draw${tag}-phone${suffix}.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `catchmind-draw${tag}-phone-full${suffix}.png`), fullPage: true });
|
||
}
|
||
await drawer.emulateMedia({ colorScheme: 'light' });
|
||
await guesser.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
const input = guesser.locator('.cm-form input');
|
||
await guesser.getByLabel('정답', { exact: true }).waitFor();
|
||
const send = async (text: string) => {
|
||
await input.fill(text);
|
||
await input.press('Enter');
|
||
};
|
||
// Wrong guess (with the 맞히기 button; the box keeps the focus): visible to the drawer too.
|
||
await sendByButton(guesser, input, guesser.locator('.cm-form button'), '모르겠어요');
|
||
await drawer.locator('.cm-chat-list').getByText('모르겠어요').first().waitFor();
|
||
// Close guess (last syllable's final consonant changed): "아까워요" for the guesser only.
|
||
const close = await guesser.evaluate((w) => {
|
||
const c = w.charCodeAt(w.length - 1) - 0xac00;
|
||
if (c < 0 || c > 11171) return null;
|
||
const jong = c % 28;
|
||
if ([3, 5, 6, 9, 10, 11, 12, 13, 14, 15, 18].includes(jong)) return null; // double final: distance 2
|
||
return w.slice(0, -1) + String.fromCharCode(0xac00 + (jong === 0 ? c + 4 : c - jong));
|
||
}, word);
|
||
if (close) {
|
||
await guesser.waitForTimeout(400); // per-player limit: 3 guesses a second
|
||
await send(close);
|
||
await guesser.locator('.cm-close').waitFor({ timeout: 5000 });
|
||
if (await drawer.locator('.cm-close').count()) throw new Error('drawer sees the close hint');
|
||
}
|
||
await guesser.waitForTimeout(400);
|
||
await send(`${word}!`);
|
||
await guesser.locator('.cm-pop').waitFor({ timeout: 5000 });
|
||
if ((await input.inputValue()) !== '') throw new Error('the answer stayed in the input box');
|
||
await drawer.locator('.cm-over .word', { hasText: word }).waitFor();
|
||
await guesser.locator('.cm-over .word', { hasText: word }).waitFor();
|
||
if (shots) {
|
||
const [pc, phone] = pages[0] === drawer ? [drawer, guesser] : [guesser, drawer];
|
||
await pc.screenshot({ path: join(SHOTS, `catchmind-reveal${tag}-pc.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `catchmind-reveal${tag}-phone.png`) });
|
||
}
|
||
return word;
|
||
}
|
||
|
||
/** 마피아: nicknames of the E2E pages (host first). */
|
||
const MAFIA_NICKS = ['방장', '친구', '친구2', '친구3'];
|
||
|
||
/** 마피아: the night prompt tells each page its role without holding the role card. */
|
||
async function mafiaRoleOf(p: Page): Promise<'mafia' | 'police' | 'doctor' | 'citizen'> {
|
||
const text = await p.locator('.mf-actions .mf-prompt').first().innerText();
|
||
if (text.includes('마피아가 노릴')) return 'mafia';
|
||
if (text.includes('조사할')) return 'police';
|
||
if (text.includes('지켜 줄')) return 'doctor';
|
||
if (text.includes('기다려')) return 'citizen';
|
||
throw new Error(`unknown night prompt: ${text}`);
|
||
}
|
||
|
||
/** 마피아: picks the highlighted player tile of `nick` (vote / night action). */
|
||
async function mafiaPick(p: Page, nick: string) {
|
||
const tile = p.locator('button.mf-tile[data-target="ok"]', { has: p.locator('.nm', { hasText: new RegExp(`^${nick}( \\(나\\))?$`) }) });
|
||
await tile.click();
|
||
await p.locator('button.mf-tile[aria-pressed="true"]', { has: p.locator('.nm', { hasText: new RegExp(`^${nick}( \\(나\\))?$`) }) }).waitFor({ timeout: 15_000 });
|
||
}
|
||
|
||
/** Game chat box: sends a line with its button (a tap on phones) and checks the box keeps the focus (phone keyboard stays up). */
|
||
async function sendByButton(p: Page, box: Locator, button: Locator, text: string) {
|
||
await box.click();
|
||
await box.fill(text);
|
||
if (await p.evaluate(() => 'ontouchstart' in window)) await button.tap();
|
||
else await button.click();
|
||
await p.waitForFunction((el) => (el as HTMLInputElement).value === '', await box.elementHandle(), { timeout: 5000 });
|
||
await p.waitForTimeout(150);
|
||
if (!(await box.evaluate((el) => el === document.activeElement))) throw new Error(`the chat box lost focus after pressing the send button ("${text}")`);
|
||
}
|
||
|
||
/** 마피아: writes in the selected channel tab and waits until the line shows up. */
|
||
async function mafiaSay(p: Page, channel: '전체' | '마피아' | '죽은 사람', text: string) {
|
||
await p.getByRole('tab', { name: new RegExp(`^${channel} 채팅`) }).click();
|
||
await p.getByLabel(`${channel} 채팅 메시지`).fill(text);
|
||
await p.getByLabel(`${channel} 채팅 메시지`).press('Enter');
|
||
await p.locator('.mf-msgs .mf-msg', { hasText: text }).waitFor({ timeout: 15_000 });
|
||
}
|
||
|
||
async function mafiaBanner(p: Page, phase: string, timeout = 40_000) {
|
||
await p.locator('.mf-banner .mf-ph strong', { hasText: phase }).waitFor({ timeout });
|
||
}
|
||
|
||
async function mafiaShots(pages: Page[], name: string) {
|
||
const [host, phone] = pages as [Page, Page];
|
||
await host.screenshot({ path: join(SHOTS, `mafia-${name}-pc.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `mafia-${name}-phone.png`) });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await phone.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(250);
|
||
await host.screenshot({ path: join(SHOTS, `mafia-${name}-pc-dark.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `mafia-${name}-phone-dark.png`), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
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;
|
||
}
|
||
|
||
/** 라이어 게임: nicknames of the E2E pages (host first). */
|
||
const LIAR_NICKS = ['방장', '친구', '친구2'];
|
||
|
||
/** 라이어 게임: shows the hold-to-see word card (keyboard Enter) and reads it: the word, or null for the liar. */
|
||
async function liarWordOf(p: Page): Promise<string | null> {
|
||
const card = p.locator('.lg-card');
|
||
if (!(await card.getAttribute('aria-label'))!.startsWith('내 제시어 보기')) throw new Error('word card shows the word before it is held');
|
||
await card.focus();
|
||
await p.keyboard.press('Enter');
|
||
const label = (await card.getAttribute('aria-label'))!;
|
||
if (label.startsWith('나는 라이어')) return null;
|
||
const m = /^내 제시어: (.+)\. 주제는/.exec(label);
|
||
if (!m) throw new Error(`unexpected word card: ${label}`);
|
||
return m[1]!;
|
||
}
|
||
|
||
async function liarBanner(p: Page, phase: string | RegExp, timeout = 40_000) {
|
||
await p.locator('.lg-banner .lg-ph strong', { hasText: phase }).waitFor({ timeout });
|
||
}
|
||
|
||
async function liarShots(pages: Page[], name: string, dark = false) {
|
||
const [host, phone] = pages as [Page, Page];
|
||
await host.screenshot({ path: join(SHOTS, `liar-${name}-pc.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `liar-${name}-phone.png`), fullPage: true });
|
||
if (!dark) return;
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await phone.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(250);
|
||
await host.screenshot({ path: join(SHOTS, `liar-${name}-pc-dark.png`) });
|
||
await phone.screenshot({ path: join(SHOTS, `liar-${name}-phone-dark.png`), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await phone.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
|
||
/**
|
||
* 야단법석 달리기: one UI step for `p` — draft a racer card (the PC host's first pick by keyboard), pick racers for the
|
||
* race and press "… 내보내기", or press one of the turn buttons (주사위 굴리기 / 능력 쓰기 / 먼저 갈 선수).
|
||
* Every third turn choice takes the second button so optional powers and "skip" are both used.
|
||
*/
|
||
async function magicalStep(p: Page, phone: boolean, st: { picks: number; selects: number; acts: number; keyboard: boolean; second: number }): Promise<boolean> {
|
||
const press = (l: ReturnType<Page['locator']>) => (phone ? l.tap({ timeout: 1500 }) : l.click({ timeout: 1500 }));
|
||
try {
|
||
const draft = p.locator('section[aria-label="선수 뽑기"] button.ma-card:not([disabled])');
|
||
const nd = await draft.count();
|
||
if (nd) {
|
||
if (!phone && !st.keyboard) {
|
||
await draft.first().focus();
|
||
await p.keyboard.press('Enter');
|
||
st.keyboard = true;
|
||
} else await press(draft.nth(st.picks % nd));
|
||
st.picks++;
|
||
await p.waitForTimeout(120);
|
||
return true;
|
||
}
|
||
const sel = p.locator('section[aria-label="출전 선수 고르기"] button.ma-card:not([disabled])');
|
||
if (await sel.count()) {
|
||
const head = await p.locator('section[aria-label="출전 선수 고르기"] h3').innerText();
|
||
const need = Number(/선수 (\d)명/.exec(head)?.[1] ?? 1);
|
||
// Only press cards that are not chosen yet, so a retry after a slow screen never un-chooses one.
|
||
const chosen = await p.locator('section[aria-label="출전 선수 고르기"] button.ma-card[aria-pressed="true"]').count();
|
||
const free = p.locator('section[aria-label="출전 선수 고르기"] button.ma-card:not([disabled]):not([aria-pressed="true"])');
|
||
for (let k = chosen; k < need; k++) await press(free.first());
|
||
const go = p.getByRole('button', { name: /내보내기$/ });
|
||
await go.waitFor({ timeout: 3000 });
|
||
await press(go);
|
||
st.selects++;
|
||
await p.locator('section[aria-label="출전 선수 고르기"]', { hasText: '내가 고른 선수' }).or(p.locator('section[aria-label="경주로"]')).first().waitFor({ timeout: 5000 });
|
||
return true;
|
||
}
|
||
const opts = p.locator('section[aria-label="내 차례 할 일"] .ma-opts button:not([disabled])');
|
||
const n = await opts.count();
|
||
if (n) {
|
||
const i = st.acts % 3 === 2 && n > 1 ? 1 : 0;
|
||
if (i === 1) st.second++;
|
||
await press(opts.nth(i));
|
||
st.acts++;
|
||
await p.waitForTimeout(150);
|
||
return true;
|
||
}
|
||
} catch {
|
||
return false;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
async function sixStep(p: Page, phone: boolean, st: { selects: number; taps: number; rows: number; spots: number; drafts: number }): Promise<boolean> {
|
||
const press = (l: Locator) => (phone ? l.tap({ timeout: 1500 }) : l.click({ timeout: 1500 }));
|
||
try {
|
||
const take = p.locator('.sx-takebtn:not([disabled])');
|
||
if (await take.count()) {
|
||
await press(take.first());
|
||
st.rows++;
|
||
await p.waitForTimeout(200);
|
||
return true;
|
||
}
|
||
const spot = p.locator('.sx-spot:not([disabled])');
|
||
if (await spot.count()) {
|
||
await press(spot.first());
|
||
st.spots++;
|
||
return true;
|
||
}
|
||
const pool = p.locator('.sx-poolbtn:not([disabled])');
|
||
if (await pool.count()) {
|
||
await press(pool.nth(st.drafts % (await pool.count())));
|
||
st.drafts++;
|
||
return true;
|
||
}
|
||
const cards = p.locator('.sx-hcard:not([disabled])');
|
||
const n = await cards.count();
|
||
if (n && !(await p.locator('.sx-hcard.sent').count())) {
|
||
const card = cards.nth((st.selects * 3) % n);
|
||
if (phone && Math.floor(st.selects / 2) % 2 === 0) {
|
||
// Phone: tap the same card twice to play it.
|
||
await card.tap({ timeout: 1500 });
|
||
await card.tap({ timeout: 1500 });
|
||
st.taps++;
|
||
} else {
|
||
await press(card);
|
||
await press(p.locator('.sx-send'));
|
||
}
|
||
st.selects++;
|
||
await p.locator('.sx-hcard.sent').or(p.locator('.sx-reveal')).first().waitFor({ timeout: 4000 }).catch(() => {});
|
||
return true;
|
||
}
|
||
} catch {
|
||
return false;
|
||
}
|
||
return false;
|
||
|
||
/**
|
||
* 티츄: one UI step for `p` — grand tichu "안 함", the exchange (추천대로 채우기 → 보내기), dragon gift, "폭탄 없음",
|
||
* "다음 라운드", or on its turn: tap a card (phone, leading) / a suggestion chip / the keyboard (PC host) and "내기"
|
||
* (wish sheet → 소원 없음), passing now and then. Returns what it did, or null.
|
||
*/
|
||
async function tichuStep(p: Page, isHost: boolean, st: Record<string, number>): Promise<string | null> {
|
||
const on = async (l: Locator) => (await l.count()) > 0 && (await l.first().isEnabled().catch(() => false));
|
||
const press = async (l: Locator, key: string) => {
|
||
await l.first().click({ timeout: 1500 });
|
||
st[key] = (st[key] ?? 0) + 1;
|
||
return key;
|
||
};
|
||
const btn = (name: string | RegExp) => p.getByRole('button', { name, exact: typeof name === 'string' });
|
||
if (await on(btn('안 함'))) return press(btn('안 함'), 'grand');
|
||
if (await on(btn('추천대로 채우기'))) {
|
||
await btn('추천대로 채우기').first().click();
|
||
if (!st[`xshot-${tag(p)}`]) {
|
||
st[`xshot-${tag(p)}`] = 1;
|
||
await p.screenshot({ path: join(SHOTS, `tichu-exchange-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
|
||
}
|
||
return press(btn('보내기'), 'exchange');
|
||
}
|
||
if (await on(btn(/에게 주기/))) return press(btn(/에게 주기/), 'dragon');
|
||
if (await on(btn('다음 라운드'))) return press(btn('다음 라운드'), 'ready');
|
||
if (await on(btn('소원 없음'))) return press(btn('소원 없음'), 'wish');
|
||
if (await on(btn('폭탄 없음'))) return press(btn('폭탄 없음'), 'noBomb');
|
||
const play = btn('내기');
|
||
if (!(await play.count())) return null;
|
||
const status = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
if (!status.includes('내 차례예요')) return null;
|
||
const pass = btn('패스');
|
||
const leading = status.includes('새 트릭');
|
||
if (!leading && (await on(pass)) && (st.turns ?? 0) % 3 === 2) {
|
||
st.turns = (st.turns ?? 0) + 1;
|
||
return press(pass, 'pass');
|
||
}
|
||
if (leading && tag(p) === 'phone' && !st.tapped) {
|
||
// Tap the lowest card: the live label names it and says it can go.
|
||
await p.locator('.tc-hand button.tc-c').first().click();
|
||
const live = (await p.locator('.tc-live').innerText()).trim();
|
||
if (live.includes('낼 수 있어요')) {
|
||
st.tapped = 1;
|
||
if (!st.liveshot) {
|
||
st.liveshot = 1;
|
||
await p.screenshot({ path: join(SHOTS, 'tichu-pick-phone.png') });
|
||
}
|
||
} else await p.locator('.tc-hand button.tc-c').first().click();
|
||
}
|
||
if (!(await on(play))) {
|
||
const chip = p.locator('.tc-chips button.tc-chip').first();
|
||
if (await chip.count()) {
|
||
if (isHost) {
|
||
await chip.focus();
|
||
await p.keyboard.press('Enter');
|
||
st.keys = (st.keys ?? 0) + 1;
|
||
} else await chip.click();
|
||
}
|
||
}
|
||
if (await on(play)) {
|
||
st.turns = (st.turns ?? 0) + 1;
|
||
return press(play, 'play');
|
||
}
|
||
if (await on(pass)) return press(pass, 'pass');
|
||
return null;
|
||
}
|
||
|
||
const PLANS: Record<string, Plan> = {
|
||
'case-file': {
|
||
// PC host + phone guest, "고른 사람만 읽기": 의뢰 → 반장 돌기(두 번 눌러 고르기) → 단서 읽기(다른 사람은 제목만)
|
||
// → 깊이 보기 → 하루 마치기 → 보고서 → 결과(정답·놓친 단서). Phone screenshots at 390 and 320 px.
|
||
players: 2,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '단서 글 읽기' }).getByRole('button', { name: '고른 사람만 읽기' }).click();
|
||
await host.getByText('한 사람만 읽기').first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const status = (p: Page) => p.locator('.turn-status').innerText();
|
||
const twice = async (p: Page, name: string | RegExp) => {
|
||
await p.getByRole('button', { name }).first().click();
|
||
await p.getByRole('button', { name: '정말 이걸로 해요' }).first().click();
|
||
};
|
||
for (const p of pages) await p.getByRole('button', { name: /수사 시작/ }).click();
|
||
await host.getByRole('tab', { name: '단서' }).waitFor();
|
||
const captain = async () => {
|
||
for (let t = 0; t < 100; t++) {
|
||
for (const p of pages) if ((await status(p)).includes('내가 반장이에요')) return p;
|
||
await host.waitForTimeout(100);
|
||
}
|
||
throw new Error('nobody is captain');
|
||
};
|
||
let reads = 0;
|
||
let deep = false;
|
||
let readerChecked = false;
|
||
for (let round = 0; round < 4; round++) {
|
||
const cap = await captain();
|
||
const other = cap === host ? guest : host;
|
||
if (!deep && (await cap.getByRole('button', { name: /깊이 보기\(돋보기/ }).count())) {
|
||
await cap.getByRole('button', { name: /깊이 보기\(돋보기/ }).click();
|
||
await cap.getByRole('button', { name: '정말 이걸로 해요' }).click();
|
||
await cap.locator('.cf-deep').first().waitFor();
|
||
deep = true;
|
||
}
|
||
if (round === 0) await other.getByRole('button', { name: '👍 추천' }).first().click();
|
||
await twice(cap, '고르기');
|
||
reads++;
|
||
await host.getByRole('tab', { name: `기록 ${reads}` }).waitFor();
|
||
if (!readerChecked) {
|
||
await other.getByText(/님이 읽고 있어요/).first().waitFor();
|
||
await cap.locator('.cf-paper .cf-doc').first().waitFor();
|
||
readerChecked = true;
|
||
}
|
||
}
|
||
await host.screenshot({ path: join(SHOTS, 'case-file-leads-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'case-file-leads-phone.png'), fullPage: true });
|
||
await guest.setViewportSize({ width: 320, height: 700 });
|
||
await guest.waitForTimeout(200);
|
||
await guest.screenshot({ path: join(SHOTS, 'case-file-leads-phone320.png'), fullPage: true });
|
||
const overflow = await guest.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
if (overflow) throw new Error('page overflows horizontally at 320px');
|
||
await guest.getByRole('tab', { name: /기록/ }).click();
|
||
await guest.locator('.cf-log button.cf-row').first().click();
|
||
await guest.getByRole('dialog').locator('.cf-paper').waitFor();
|
||
await guest.waitForTimeout(600);
|
||
await guest.screenshot({ path: join(SHOTS, 'case-file-reading-phone320.png') });
|
||
await guest.getByRole('button', { name: '닫기' }).last().click();
|
||
await guest.getByRole('tab', { name: '단서' }).click();
|
||
let cap = await captain();
|
||
await twice(cap, /하루 마치기/);
|
||
await host.getByText(/2일째 09:00/).first().waitFor();
|
||
cap = await captain();
|
||
await twice(cap, '📝 보고서 쓰기');
|
||
for (const p of pages) {
|
||
await p.getByRole('button', { name: '📝 보고서 내기' }).waitFor();
|
||
const groups = p.locator('.cf-choices');
|
||
const n = await groups.count();
|
||
for (let i = 0; i < n; i++) await groups.nth(i).getByRole('button').first().click();
|
||
}
|
||
await guest.screenshot({ path: join(SHOTS, 'case-file-report-phone320.png'), fullPage: true });
|
||
for (const p of pages) {
|
||
await p.getByRole('button', { name: '📝 보고서 내기' }).click();
|
||
await p.getByRole('button', { name: /정말 낼까요/ }).click();
|
||
}
|
||
await host.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'case-file-result-dialog-pc.png') });
|
||
await host.keyboard.press('Escape');
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await guest.keyboard.press('Escape');
|
||
await host.getByText('정답과 풀이').waitFor();
|
||
await host.getByRole('button', { name: /놓친 단서 보기/ }).click();
|
||
await host.screenshot({ path: join(SHOTS, 'case-file-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'case-file-result-phone320.png'), fullPage: true });
|
||
console.log(` case-file: ${reads} leads read, deep look ${deep ? 'used' : 'not offered'}, reader mode secret checked`);
|
||
},
|
||
},
|
||
blackjack: {
|
||
// PC host + phone guest. Each hand: bet the minimum, stand (decline insurance), then press 다음 판, until the
|
||
// session ends (10 hands). Smoke test only — the rules are covered by the engine tests.
|
||
players: 2,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '판 수' }).getByRole('button', { name: '5판' }).click();
|
||
await host.getByText('5판').first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
let finished = false;
|
||
let hands = 0;
|
||
for (let t = 0; t < 2000 && !finished; t++) {
|
||
if (await pages[0]!.getByRole('dialog', { name: '게임 결과' }).count()) {
|
||
finished = true;
|
||
break;
|
||
}
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
const labels: (RegExp | string)[] = [/베팅$/, '스탠드', '안 함', '다음 판'];
|
||
for (const name of labels) {
|
||
const btn = p.getByRole('button', { name }).first();
|
||
if ((await btn.count()) && (await btn.isEnabled({ timeout: 150 }).catch(() => false))) {
|
||
if (name === '다음 판') hands++;
|
||
await btn.click({ timeout: 1000 }).catch(() => {});
|
||
acted = true;
|
||
break;
|
||
}
|
||
}
|
||
if (acted) break;
|
||
}
|
||
if (!acted) await pages[0]!.waitForTimeout(120);
|
||
}
|
||
if (!finished) throw new Error(`blackjack did not finish (${hands} hands advanced)`);
|
||
await pages[0]!.screenshot({ path: join(SHOTS, 'blackjack-result-pc.png') });
|
||
console.log(` blackjack: finished after ${hands} hands`);
|
||
},
|
||
},
|
||
rummikub: {
|
||
// PC host + phone guest, first meld "없음" so hint plays happen early; 10 real turns through the UI.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '첫 등록 최소 점수' }).getByRole('button', { name: '없음' }).click();
|
||
await host.getByText('첫 등록 점수 없음').first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const stats = await rummikubTurns(pages, 10);
|
||
if (stats.plays + stats.draws < 10) throw new Error('not enough turns');
|
||
},
|
||
},
|
||
yut: {
|
||
// 말 2개로 줄이고 지역 룰(업기 고르기·갈림길 고르기)을 켠 뒤, PC 방장 + 휴대폰 친구가 실제 화면 조작으로 끝까지 둔다.
|
||
// 옵션 화면(PC 방장 / 휴대폰 친구 보기 전용 320px·다크)과 중간 화면도 저장.
|
||
lobby: async (host) => {
|
||
await host.getByRole('button', { name: '2개', exact: true }).click();
|
||
await host.getByText(/말 2개/).first().waitFor();
|
||
await host.getByRole('button', { name: /지역 룰/ }).click();
|
||
await host.getByRole('button', { name: '업을지 고르기' }).click();
|
||
await host.getByRole('button', { name: '갈 길 고르기' }).click();
|
||
await host.getByText(/업기 고르기 · 갈림길 고르기/).first().waitFor();
|
||
await host.locator('#yut-house-rules').scrollIntoViewIfNeeded();
|
||
await host.screenshot({ path: join(SHOTS, 'yut-options-pc.png') });
|
||
// The phone friend only sees the options (read-only), but can open the 지역 룰 box.
|
||
const guest = host.context().browser()!.contexts().at(-1)!.pages()[0]!; // this game's guest = newest context (earlier games' contexts stay open)
|
||
await guest.getByText(/업기 고르기 · 갈림길 고르기/).first().waitFor();
|
||
await guest.getByRole('button', { name: '설정 보기' }).click();
|
||
const sheet = guest.getByRole('dialog', { name: '게임 설정' });
|
||
await sheet.getByRole('button', { name: /지역 룰/ }).click();
|
||
if (await sheet.getByRole('button', { name: '업을지 고르기' }).isEnabled()) throw new Error('guest can change options');
|
||
await guest.screenshot({ path: join(SHOTS, 'yut-options-phone.png') });
|
||
await guest.setViewportSize({ width: 320, height: 640 });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await sheet.getByText('말 움직이기').scrollIntoViewIfNeeded();
|
||
await guest.screenshot({ path: join(SHOTS, 'yut-options-phone-320-dark.png') });
|
||
const wide = await guest.evaluate(() => {
|
||
const sh = document.querySelector('.sheet');
|
||
return document.documentElement.scrollWidth > window.innerWidth + 1 || (!!sh && sh.scrollWidth > sh.clientWidth + 1);
|
||
});
|
||
if (wide) throw new Error('options overflow at 320px');
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
await sheet.getByRole('button', { name: '닫기', exact: true }).click();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
let actions = 0;
|
||
let shot = false;
|
||
const until = Date.now() + 300_000;
|
||
const over = () => host.getByText(/이겼어요|아쉽게 졌어요/).count();
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
if (await yutStep(p)) {
|
||
acted = true;
|
||
actions++;
|
||
break;
|
||
}
|
||
}
|
||
if (actions >= 16 && !shot) {
|
||
shot = true;
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'yut-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'yut-mid-phone.png'), fullPage: true });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.screenshot({ path: join(SHOTS, 'yut-mid-phone-dark.png') });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!acted) await host.waitForTimeout(120);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${actions} UI actions)`);
|
||
await guest.getByText(/이겼어요|아쉽게 졌어요/).waitFor();
|
||
console.log(` yut: finished after ${actions} UI actions (지역 룰 choices used: ${[...yutChoiceSeen].join(', ') || 'none'})`);
|
||
},
|
||
},
|
||
'one-card': {
|
||
// 3 players, default 원카드: whoever has the turn plays a highlighted card (tap to lift, tap again to play,
|
||
// pick a suit for 7) or draws; the 원카드 button is pressed whenever it lights up. 60 turns or until the game ends.
|
||
// Checks on the way: playing down to one card never calls by itself (the separate round button is still lit for
|
||
// the owner, the others count down "잡기 N초" first), cards fly from the deck when someone draws.
|
||
players: 3,
|
||
drive: async (pages) => {
|
||
const statusOf = (p: Page) => p.locator('.turn-status').innerText().catch(() => '');
|
||
const handCount = (p: Page) => p.locator('.oc-hand button.oc-card').count();
|
||
const shot = (p: Page, name: string) => p.screenshot({ path: join(SHOTS, `one-card-${name}-${tag(p)}.png`), fullPage: tag(p) === 'phone' });
|
||
let turns = 0;
|
||
let plays = 0;
|
||
let draws = 0;
|
||
let flown = 0;
|
||
let separateCall = 0;
|
||
let finished = false;
|
||
for (let t = 0; t < 600 && turns < 60; t++) {
|
||
if (await pages[0]!.getByRole('dialog', { name: '게임 결과' }).count()) {
|
||
finished = true;
|
||
break;
|
||
}
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
const one = p.locator('.oc-onebtn');
|
||
if ((await one.count()) && (await one.isEnabled().catch(() => false))) await one.click({ timeout: 1000 }).catch(() => {});
|
||
const before = await statusOf(p);
|
||
if (!before.includes('내 차례예요')) continue;
|
||
const accept = p.getByRole('button', { name: /^받아들이기/ });
|
||
const card = p.locator('button.oc-card[data-legal="true"]').first();
|
||
if (await accept.count()) await accept.click();
|
||
else if (await card.count()) {
|
||
const leavesOne = (await handCount(p)) === 2;
|
||
await card.click();
|
||
if (leavesOne && !separateCall) {
|
||
await p.getByText('낸 다음 [원카드!]를 따로 눌러요').waitFor({ timeout: 2000 });
|
||
await shot(p, 'before-last');
|
||
}
|
||
await card.click();
|
||
const pick = p.locator('.oc-pick button').first();
|
||
if (await pick.waitFor({ timeout: 400 }).then(() => true, () => false)) await pick.click();
|
||
plays++;
|
||
if (leavesOne && !separateCall && (await p.locator('.oc-onebtn.urgent').waitFor({ timeout: 3000 }).then(() => true, () => false))) {
|
||
// Not called by the play: the owner's button pulses, another player waits out the protection time.
|
||
const other = pages.find((q) => q !== p)!;
|
||
await other.locator('.oc-onebtn.wait').waitFor({ timeout: 2000 });
|
||
if (!(await other.locator('.oc-onebtn').isDisabled())) throw new Error('catch button lit during the protection time');
|
||
await shot(p, 'call');
|
||
await shot(other, 'catch-wait');
|
||
await p.emulateMedia({ colorScheme: 'dark' });
|
||
await p.waitForTimeout(300);
|
||
await shot(p, 'call-dark');
|
||
await p.emulateMedia({ colorScheme: 'light' });
|
||
separateCall++;
|
||
}
|
||
} else {
|
||
const pass = p.getByRole('button', { name: '넘기기' });
|
||
if (await pass.count()) await pass.click();
|
||
else await p.getByRole('button', { name: /장 먹기$/ }).first().click();
|
||
draws++;
|
||
// Cards fly from the deck to whoever draws, on every screen.
|
||
const watcher = pages.find((q) => q !== p)!;
|
||
if (flown < 2 && (await watcher.locator('.oc-fly').first().waitFor({ timeout: 1500 }).then(() => true, () => false))) {
|
||
flown++;
|
||
if (flown === 1) {
|
||
await shot(watcher, 'draw-fly');
|
||
await shot(p, 'draw-fly');
|
||
}
|
||
}
|
||
}
|
||
await p.waitForFunction((s) => document.querySelector('.turn-status')?.textContent?.trim() !== s, before.trim(), { timeout: 5000 }).catch(() => {});
|
||
turns++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
if (!acted) await pages[0]!.waitForTimeout(150);
|
||
}
|
||
if (!finished && turns < 30) throw new Error(`only ${turns} turns were played`);
|
||
if (finished) await pages[0]!.screenshot({ path: join(SHOTS, 'one-card-3-result-pc.png') });
|
||
if (draws > 0 && !flown) throw new Error('no flying cards seen when someone drew');
|
||
console.log(` one-card: ${turns} turns (${plays} plays, ${draws} draws, separate 원카드 checked ${separateCall}×, draw flights seen ${flown}×)${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 "여기서 멈추기".
|
||
drive: async (pages) => {
|
||
for (const p of pages) {
|
||
await p.getByRole('button', { name: '검정 2개 · 흰색 2개' }).click();
|
||
await p.getByRole('button', { name: '이렇게 받기' }).click();
|
||
}
|
||
const myTurn = (p: Page) => p.evaluate(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'));
|
||
for (let turn = 0; turn < 5; turn++) {
|
||
let mover: Page | null = null;
|
||
for (let t = 0; t < 100 && !mover; t++) {
|
||
for (const p of pages) if (!mover && (await myTurn(p))) mover = p;
|
||
if (!mover) await pages[0]!.waitForTimeout(100);
|
||
}
|
||
if (!mover) throw new Error(`turn ${turn + 1}: nobody has the turn`);
|
||
const pile = mover.getByRole('button', { name: turn % 2 ? /^흰색 타일 가져오기/ : /^검은색 타일 가져오기/ });
|
||
await pile.click();
|
||
await mover.getByText('맞힐 상대 타일을 눌러 주세요.').waitFor();
|
||
await mover.locator('.dv-opps .dv-pick.can').nth(turn % 3).click();
|
||
await mover.getByRole('button', { name: String((turn * 5) % 12), exact: true }).click();
|
||
if (turn < 2) await mover.screenshot({ path: join(SHOTS, `davinci-code-3-pad-${mover === pages[0] ? 'pc' : 'phone'}.png`), fullPage: true });
|
||
await mover.getByRole('button', { name: /이 숫자!$/ }).click();
|
||
// A hit → stop (the drawn tile goes in hidden); a miss ends the turn by itself.
|
||
for (let t = 0; t < 60; t++) {
|
||
const stop = mover.getByRole('button', { name: '여기서 멈추기' });
|
||
if (await stop.isVisible().catch(() => false)) await stop.click().catch(() => {});
|
||
if (!(await myTurn(mover))) break;
|
||
await mover.waitForTimeout(100);
|
||
}
|
||
if (await myTurn(mover)) throw new Error(`turn ${turn + 1}: turn did not pass`);
|
||
}
|
||
// Both screens show the guess log with every guess.
|
||
for (const p of pages) await p.getByText('추리 기록 (5)').waitFor();
|
||
},
|
||
},
|
||
yacht: {
|
||
// PC host + phone guest play a whole 12-round game through the UI: roll, sometimes hold + re-roll, then
|
||
// write the best open category (phone uses touch taps, so the confirm sheet path is exercised too).
|
||
drive: async (pages) => {
|
||
const myTurn = (p: Page) => p.evaluate(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'));
|
||
const shot = new Set<string>();
|
||
for (let turn = 0; turn < 24; turn++) {
|
||
let mover: Page | null = null;
|
||
for (let t = 0; t < 150 && !mover; t++) {
|
||
for (const p of pages) if (!mover && (await myTurn(p))) mover = p;
|
||
if (!mover) await pages[0]!.waitForTimeout(100);
|
||
}
|
||
if (!mover) throw new Error(`nobody has the turn (turn ${turn + 1})`);
|
||
const phone = mover !== pages[0];
|
||
const press = (l: ReturnType<Page['locator']>) => (phone ? l.tap() : l.click());
|
||
await press(mover.getByRole('button', { name: /^🎲 굴리기/ }));
|
||
await mover.locator('.yt-die[aria-pressed]').first().waitFor();
|
||
if (turn % 3 !== 2) {
|
||
// Hold the first die, check it shows as held, then roll the rest again.
|
||
await press(mover.locator('.yt-die').first());
|
||
await mover.locator('.yt-die').first().and(mover.locator('[aria-pressed="true"]')).waitFor();
|
||
await press(mover.getByRole('button', { name: /^🎲 굴리기 \(남은 2번\)/ }));
|
||
await mover.getByRole('button', { name: /^🎲 굴리기 \(남은 1번\)/ }).waitFor();
|
||
await mover.waitForTimeout(700); // roll animation
|
||
}
|
||
const cells = mover.locator('button.yt-cell:not([disabled])');
|
||
await cells.first().waitFor();
|
||
// Mid-game screenshots of a turn in progress (held die + preview cells), light and dark.
|
||
const tag = phone ? 'phone' : 'pc';
|
||
if (turn >= 8 && !shot.has(tag)) {
|
||
shot.add(tag);
|
||
await mover.screenshot({ path: join(SHOTS, `yacht-mid-${tag}.png`), fullPage: phone });
|
||
await mover.emulateMedia({ colorScheme: 'dark' });
|
||
await mover.waitForTimeout(200);
|
||
await mover.screenshot({ path: join(SHOTS, `yacht-mid-${tag}-dark.png`), fullPage: phone });
|
||
await mover.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
const values = await cells.allInnerTexts();
|
||
let best = 0;
|
||
values.forEach((v, i) => Number(v) > Number(values[best]) && (best = i));
|
||
await press(cells.nth(best));
|
||
const confirm = mover.getByRole('button', { name: '기록하기', exact: true });
|
||
if (await confirm.isVisible({ timeout: 600 }).catch(() => false)) await confirm.click();
|
||
await mover.waitForFunction(() => !document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 5000 });
|
||
}
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
const sheet = await pages[0]!.locator('.yt-table tr.yt-total').innerText();
|
||
if (!/\d/.test(sheet)) throw new Error('no totals on the score sheet');
|
||
},
|
||
},
|
||
seotda: {
|
||
// 3 players, default 2장 섯다 (2장 한 번에, 베팅 1번): whoever acts first bets 하프 (coins fly to the 판돈),
|
||
// the others call → showdown. A tie (or 구사) starts a 재경기 with the same 판돈, so keep calling/checking
|
||
// until the hand result shows up. Screenshots: mid-hand PC/phone (light + dark) and the result.
|
||
players: 3,
|
||
drive: async (pages) => {
|
||
await pressActions(pages, /^하프/, 1);
|
||
await pages[0]!.waitForTimeout(700);
|
||
for (const p of pages.slice(0, 2)) {
|
||
const tag = (p.viewportSize()?.width ?? 0) < 600 ? 'phone' : 'pc';
|
||
await p.screenshot({ path: join(SHOTS, `seotda-mid-${tag}.png`), fullPage: tag === 'phone' });
|
||
await p.emulateMedia({ colorScheme: 'dark' });
|
||
await p.waitForTimeout(150);
|
||
await p.screenshot({ path: join(SHOTS, `seotda-mid-${tag}-dark.png`), fullPage: tag === 'phone' });
|
||
await p.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
await pressActions(pages, /^(체크|콜)/, 2);
|
||
for (let extra = 0; extra < 30 && !(await pages[0]!.getByText('이번 판 결과').count()); extra++) {
|
||
await pressActions(pages, /^(체크|콜)/, 1).catch(() => {});
|
||
}
|
||
await finishHand(pages);
|
||
await pages[0]!.waitForTimeout(600);
|
||
await pages[0]!.screenshot({ path: join(SHOTS, 'seotda-result-pc.png') });
|
||
await pages[1]!.screenshot({ path: join(SHOTS, 'seotda-result-phone.png'), fullPage: true });
|
||
},
|
||
},
|
||
seotda3: {
|
||
// 3장 섯다 (한게임): 2장 → 각자 공개패 1장 고르기(다른 사람 화면에 앞면) → 1구 베팅 → 1장 더 → 2구 베팅 →
|
||
// 3장 중 2장 고르기 → 공개. Everyone opens, checks/calls through both rounds and picks the recommended pair.
|
||
game: 'seotda',
|
||
players: 3,
|
||
lobby: async (host) => {
|
||
await host.getByRole('button', { name: /^3장 섯다/ }).first().click();
|
||
},
|
||
drive: async (pages) => {
|
||
for (const p of pages) {
|
||
const box = p.getByRole('group', { name: '공개패 고르기' });
|
||
await box.waitFor({ timeout: 10_000 });
|
||
await box.locator('button, [role="button"]').first().click();
|
||
await p.getByRole('button', { name: /패 공개하기$/ }).click();
|
||
}
|
||
// The others now see one face-up card of each player.
|
||
await pages[0]!.waitForFunction(() => document.querySelectorAll('.sd-seat .sd-cards img, .sd-seat .sd-cards svg').length > 0, null, { timeout: 5000 }).catch(() => {});
|
||
await pages[0]!.screenshot({ path: join(SHOTS, 'seotda3-open-pc.png') });
|
||
for (let n = 0; n < 40 && !(await pages[0]!.getByRole('button', { name: /정하기$|두 장을 고르세요/ }).count()) && !(await pages[0]!.getByText('이번 판 결과').count()); n++) {
|
||
// Nobody raises, so every action is a 체크 (콜 stays disabled and would hide it from pressActions).
|
||
await pressActions(pages, /^체크/, 1).catch(() => {});
|
||
}
|
||
await pages[0]!.screenshot({ path: join(SHOTS, 'seotda3-choose-pc.png') });
|
||
if (await pages[0]!.getByText('자리 비움').count()) throw new Error('someone timed out (the plan should act for everybody)');
|
||
for (const p of pages) {
|
||
const rec = p.getByRole('button', { name: /\(추천\)$/ });
|
||
if (await rec.count()) {
|
||
await rec.first().click();
|
||
await p.getByRole('button', { name: /정하기$/ }).click();
|
||
}
|
||
}
|
||
await finishHand(pages);
|
||
await pages[1]!.screenshot({ path: join(SHOTS, 'seotda3-result-phone.png'), fullPage: true });
|
||
},
|
||
},
|
||
seotdaFold: {
|
||
// 2026-10-14: the first actor bets 하프, the other two 다이 → the one left chooses [카드 공개]; everyone then sees
|
||
// the cards and "패를 공개했어요" in the result.
|
||
game: 'seotda',
|
||
players: 3,
|
||
drive: async (pages) => {
|
||
await pressActions(pages, /^하프/, 1);
|
||
await pressActions(pages, /^다이/, 2);
|
||
let winner: Page | null = null;
|
||
for (let t = 0; t < 50 && !winner; t++) {
|
||
for (const p of pages) if (await p.getByRole('group', { name: '카드 공개' }).count()) winner = p;
|
||
if (!winner) await pages[0]!.waitForTimeout(100);
|
||
}
|
||
if (!winner) throw new Error('nobody was asked to show the cards');
|
||
for (const p of pages) if (p !== winner) await p.getByText(/카드 공개 여부를 고르는 중이에요/).first().waitFor({ timeout: 5000 });
|
||
await winner.screenshot({ path: join(SHOTS, 'seotda-fold-reveal-ask.png') });
|
||
await winner.getByRole('button', { name: '카드 공개', exact: true }).click();
|
||
for (const p of pages) await p.getByText(/패를 공개했어요/).first().waitFor({ timeout: 10_000 });
|
||
await pages[0]!.waitForTimeout(1500); // the flip
|
||
await pages.find((p) => p !== winner)!.screenshot({ path: join(SHOTS, 'seotda-fold-revealed-other.png') });
|
||
},
|
||
},
|
||
poker: {
|
||
// 3 players, default 7포커: 초이스 (discard 1st card, open 2nd), then everyone checks 4 streets → showdown.
|
||
players: 3,
|
||
drive: async (pages) => {
|
||
for (const p of pages) {
|
||
const cards = p.locator('.pk-mine button');
|
||
await cards.first().waitFor();
|
||
await cards.nth(0).click();
|
||
await cards.nth(1).click();
|
||
await p.getByRole('button', { name: '확인', exact: true }).click();
|
||
}
|
||
await pressActions(pages, /^체크/, 12);
|
||
await finishHand(pages);
|
||
},
|
||
},
|
||
omok: {
|
||
// cursor starts at the centre: black plays there, white one point to the left (the full omok flow is e2e/omok.e2e.ts)
|
||
moves: [['Enter'], ['ArrowLeft', 'Enter']],
|
||
},
|
||
othello: {
|
||
// cursor starts at d4 (3,3): black d3 = up; then white c3 = up, left
|
||
moves: [['ArrowUp', 'Enter'], ['ArrowUp', 'ArrowLeft', 'Enter']],
|
||
},
|
||
'connect-four': {
|
||
// 방장(PC, 빨강, 먼저)은 키보드(Home → 오른쪽 화살표 → Enter)로, 친구(휴대폰, 노랑)는 열을 직접 눌러서 둔다.
|
||
// 1열을 끝까지 채운 뒤 친구가 꽉 찬 1열을 눌러도 아무 일이 없는지 보고, 빨강이 맨 아래 줄 다섯 개(1~5열)로 이긴다.
|
||
lobby: async (host) => {
|
||
await host.getByRole('button', { name: '방장이 먼저', exact: true }).click();
|
||
await host.getByText(/방장 먼저/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const grid = (p: Page) => p.locator('svg[role="grid"]').first();
|
||
await grid(host).waitFor();
|
||
await grid(guest).waitFor();
|
||
const discs = (p: Page) => p.locator('svg[role="grid"] circle[r="0.41"]').count();
|
||
const myTurn = (p: Page) => p.waitForFunction(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 10_000 });
|
||
const waitDiscs = async (n: number) => {
|
||
for (const p of pages) await p.waitForFunction((k) => document.querySelectorAll('svg[role="grid"] circle[r="0.41"]').length >= k, n, { timeout: 10_000 });
|
||
};
|
||
const hostDrop = async (col: number) => {
|
||
await myTurn(host);
|
||
await grid(host).focus();
|
||
await host.keyboard.press('Home');
|
||
for (let i = 0; i < col; i++) await host.keyboard.press('ArrowRight');
|
||
await host.keyboard.press('Enter');
|
||
};
|
||
const guestDrop = async (col: number) => {
|
||
await myTurn(guest);
|
||
await guest.locator(`svg[role="grid"] rect[data-col="${col}"]`).tap();
|
||
const confirm = guest.getByRole('button', { name: `${col + 1}열에 넣기` });
|
||
if (await confirm.isVisible().catch(() => false)) await confirm.click();
|
||
};
|
||
// 0-based columns: red 0, yellow 0, … fills column 1 (빨노빨노빨노), then the bottom-row fight.
|
||
const plan: ['h' | 'g', number][] = [['h', 0], ['g', 0], ['h', 0], ['g', 0], ['h', 0], ['g', 0], ['h', 3], ['g', 3], ['h', 2], ['g', 2], ['h', 4], ['g', 4], ['h', 1]];
|
||
let n = 0;
|
||
for (const [who, col] of plan) {
|
||
if (who === 'g' && n === 7) {
|
||
// Column 1 is full: tapping it does nothing (still the guest's turn, same number of discs).
|
||
await myTurn(guest);
|
||
await guest.locator('svg[role="grid"] rect[data-col="0"]').tap();
|
||
await guest.waitForTimeout(400);
|
||
if ((await discs(guest)) !== 7) throw new Error('a disc went into the full column');
|
||
if (!(await guest.locator('.turn-status').innerText()).includes('내 차례예요')) throw new Error('turn passed after tapping a full column');
|
||
}
|
||
await (who === 'h' ? hostDrop(col) : guestDrop(col));
|
||
n++;
|
||
await waitDiscs(n);
|
||
if (n === 10) {
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'connect-four-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'connect-four-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'connect-four-mid-phone-full.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'connect-four-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'connect-four-mid-phone-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
}
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
const rings = await host.locator('svg[role="grid"] circle.c4-win').count();
|
||
if (rings !== 5) throw new Error(`expected the 5-disc line lit, got ${rings}`);
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'connect-four-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'connect-four-result-phone.png') });
|
||
const summary = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||
if (!summary.includes('빨강 승 (5개 연결, 13수)')) throw new Error(`unexpected result: ${summary.slice(0, 120)}`);
|
||
// Close the result to look at the lit line.
|
||
await host.keyboard.press('Escape');
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'connect-four-final-board-pc.png') });
|
||
console.log(` connect-four: ${n} drops (keyboard + taps), full column refused, ${summary.split('\n').find((l) => l.includes('빨강 승'))}`);
|
||
},
|
||
},
|
||
chess: {
|
||
// cursor starts on the e-file pawn of whoever is at the bottom: white e2-e4, black d7-d5 (board flipped)
|
||
moves: [['Enter', 'ArrowUp', 'ArrowUp', 'Enter'], ['Enter', 'ArrowUp', 'ArrowUp', 'Enter']],
|
||
},
|
||
chess960: {
|
||
// Chess960 via the lobby option, host = white. Reads the start number from the side panel, then plays a line from
|
||
// e2e/chess960-plan.ts by clicking squares (black shuffles a knight, white clears its back rank) up to white
|
||
// castling, entered by tapping the king and then its own rook (the 960 way). Checks the castling hints on the way.
|
||
game: 'chess',
|
||
lobby: async (host) => {
|
||
await host.getByRole('button', { name: '체스960 (첫 줄 무작위)' }).click();
|
||
await host.getByRole('button', { name: '방장이 백', exact: true }).click();
|
||
await host.getByText(/체스960 · /).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const tap = async (p: Page, sq: string, bottom: 'white' | 'black') => {
|
||
const board = p.locator('svg[role="grid"]').first();
|
||
await board.scrollIntoViewIfNeeded();
|
||
const box = (await board.boundingBox())!;
|
||
const f = sq.charCodeAt(0) - 97;
|
||
const r = Number(sq[1]) - 1;
|
||
const [x, y] = bottom === 'white' ? [f, 7 - r] : [7 - f, r];
|
||
await p.mouse.click(box.x + ((x + 0.52) / 8.04) * box.width, box.y + ((y + 0.52) / 8.04) * box.height);
|
||
};
|
||
const myTurn = (p: Page) => p.waitForFunction(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 10_000 });
|
||
const label = (await host.getByText(/시작 배치 \d+번/).first().innerText()).match(/시작 배치 (\d+)번/)!;
|
||
const index = Number(label[1]);
|
||
await guest.getByText(`시작 배치 ${index}번`).first().waitFor();
|
||
const plies = plan960(index);
|
||
for (const [n, ply] of plies.entries()) {
|
||
const white = n % 2 === 0;
|
||
const p = white ? host : guest;
|
||
const bottom = white ? 'white' : 'black';
|
||
await myTurn(p);
|
||
const [from, to] = [ply.uci.slice(0, 2), ply.uci.slice(2, 4)];
|
||
if (ply.castle) {
|
||
await p.getByRole('button', { name: /^캐슬링: / }).first().waitFor();
|
||
await tap(p, from, bottom);
|
||
await p.getByText(/노란 테두리 칸/).waitFor();
|
||
await p.locator('svg[role="grid"] text', { hasText: '캐슬링' }).first().waitFor();
|
||
await p.screenshot({ path: join(SHOTS, 'chess960-castle-hint-pc.png') });
|
||
} else await tap(p, from, bottom);
|
||
await tap(p, to, bottom);
|
||
await p.waitForFunction(() => !document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 5000 });
|
||
}
|
||
const last = plies[plies.length - 1]!;
|
||
if (!last.castle) throw new Error('plan did not end with castling');
|
||
for (const p of pages) await p.getByText(last.san, { exact: true }).first().waitFor();
|
||
console.log(` chess960: #${index}, ${plies.map((x) => x.san).join(' ')}`);
|
||
},
|
||
},
|
||
baduk: {
|
||
// cursor starts at 천원: black plays there, white plays one point to the left
|
||
moves: [['Enter'], ['ArrowLeft', 'Enter']],
|
||
},
|
||
janggi: {
|
||
// Both sides pick 안상차림 (order may be han-first), then each pushes the centre 졸 one step.
|
||
setup: async (host, guest) => {
|
||
for (let round = 0; round < 20; round++) {
|
||
let picked = false;
|
||
for (const p of [host, guest]) {
|
||
const btn = p.getByRole('button', { name: /^안상차림/ });
|
||
// The card list disappears right after choosing, so every probe must be short and tolerant.
|
||
if ((await btn.count()) && (await btn.isEnabled({ timeout: 500 }).catch(() => false))) {
|
||
picked = await btn
|
||
.click({ timeout: 1000 })
|
||
.then(() => true)
|
||
.catch(() => false);
|
||
}
|
||
}
|
||
if (await host.evaluate(() => !document.body.innerText.includes('상차림을 골라'))) {
|
||
if (await guest.evaluate(() => !document.body.innerText.includes('상차림을 골라'))) return;
|
||
}
|
||
if (!picked) await host.waitForTimeout(200);
|
||
}
|
||
throw new Error('상차림 단계가 끝나지 않음');
|
||
},
|
||
moves: [
|
||
['ArrowUp', 'ArrowUp', 'Enter', 'ArrowUp', 'Enter'],
|
||
['ArrowUp', 'ArrowUp', 'Enter', 'ArrowUp', 'Enter'],
|
||
],
|
||
},
|
||
mahjong: {
|
||
// 4인 리치 마작 (PC host + 3 phones): whoever has the turn taps the right-most legal tile (lift) and presses
|
||
// the "… 버리기" button; claim windows are answered with 패스 (론/쯔모 when offered). Plays until the first hand
|
||
// ends (win or exhaustive draw, ~70 discards), checks the result screen on every device and confirms it.
|
||
players: 4,
|
||
drive: async (pages) => {
|
||
const statusOf = (p: Page) => p.locator('.turn-status').innerText().catch(() => '');
|
||
let discards = 0;
|
||
let passes = 0;
|
||
let wins = 0;
|
||
let results = 0;
|
||
const shotClaim = new Set<string>();
|
||
for (let t = 0; t < 4000 && discards < 100 && results < 1; t++) {
|
||
let acted = false;
|
||
for (const [pi, p] of pages.entries()) {
|
||
const status = await statusOf(p);
|
||
const win = p.getByRole('button', { name: /^(쯔모|론)!$/ });
|
||
if ((await win.count()) && (await win.first().isEnabled().catch(() => false))) {
|
||
await win.first().click({ timeout: 1000 }).catch(() => {});
|
||
wins++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
const pass = p.getByRole('group', { name: '울기·론 선택' }).getByRole('button', { name: '패스' });
|
||
if (await pass.count()) {
|
||
const dev = pi === 0 ? 'pc' : 'phone';
|
||
if (!shotClaim.has(dev)) {
|
||
await p.screenshot({ path: join(SHOTS, `mahjong-3-claim-${dev}.png`) });
|
||
shotClaim.add(dev);
|
||
}
|
||
await pass.click({ timeout: 1000 }).catch(() => {});
|
||
passes++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
const next = p.getByRole('button', { name: /^(다음 국으로|최종 결과 보기)$/ });
|
||
if ((await next.count()) && (await next.isEnabled().catch(() => false))) {
|
||
// The hand is over: every device shows the result, then everyone confirms → the next hand starts.
|
||
await pages[0]!.screenshot({ path: join(SHOTS, 'mahjong-4-result-pc.png') });
|
||
await pages[1]!.screenshot({ path: join(SHOTS, 'mahjong-4-result-phone.png'), fullPage: true });
|
||
for (const q of pages) {
|
||
await q.getByRole('region', { name: /결과$/ }).waitFor({ timeout: 5000 });
|
||
const b = q.getByRole('button', { name: /^(다음 국으로|최종 결과 보기)$/ });
|
||
if (await b.isEnabled().catch(() => false)) await b.click({ timeout: 1000 }).catch(() => {});
|
||
}
|
||
await pages[0]!.getByText(/^동1국|^동2국/).first().waitFor({ timeout: 10_000 });
|
||
results++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
if (!status.includes('내 차례예요')) continue;
|
||
const tiles = p.locator('button.mj-htile[data-legal="true"]');
|
||
const n = await tiles.count();
|
||
if (!n) continue;
|
||
const tile = tiles.nth(n - 1);
|
||
await tile.click({ timeout: 1000 }).catch(() => {});
|
||
if (discards === 4 && pi > 0) await p.screenshot({ path: join(SHOTS, 'mahjong-2-selected-phone.png') });
|
||
const send = p.getByRole('button', { name: /버리기$/ });
|
||
if ((await send.count()) && (await send.isEnabled().catch(() => false))) await send.click({ timeout: 1000 }).catch(() => {});
|
||
await p.waitForFunction((s) => document.querySelector('.turn-status')?.textContent?.trim() !== s, status.trim(), { timeout: 5000 }).catch(() => {});
|
||
discards++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
if (!acted) await pages[0]!.waitForTimeout(120);
|
||
}
|
||
if (results === 0) throw new Error(`no hand finished after ${discards} discards`);
|
||
// The next hand has started: the table and my hand are back on every screen.
|
||
for (const q of pages) await q.locator('.mj-table').waitFor({ timeout: 10_000 });
|
||
console.log(` mahjong: ${discards} discards, ${passes} passes, ${wins} wins, ${results} hand finished → next hand started`);
|
||
},
|
||
},
|
||
gostop: {
|
||
// 맞고: PC host + phone guest, 1판. Real turns through the UI — hand cards (tap twice on the phone), floor-card choices,
|
||
// 흔들기/폭탄 sheets, one 고 and then 스톱 — until the hand ends (스톱 or 나가리) and the game result shows.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '판 수' }).getByRole('button', { name: '1판', exact: true }).click();
|
||
await host.getByText(/^1판 · /).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const state = { go: 0, stop: 0, picks: 0, plays: 0, sheets: 0 };
|
||
let shot = false;
|
||
const until = Date.now() + 240_000;
|
||
const over = async () => (await host.getByRole('dialog', { name: '게임 결과' }).count()) > 0;
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
const did = await gostopStep(p, state).catch(() => null);
|
||
if (did) {
|
||
acted = true;
|
||
await p.waitForTimeout(250);
|
||
break;
|
||
}
|
||
}
|
||
if (state.plays >= 8 && !shot) {
|
||
shot = true;
|
||
await host.waitForTimeout(1500);
|
||
await host.screenshot({ path: join(SHOTS, 'gostop-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'gostop-mid-phone.png'), fullPage: true });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.screenshot({ path: join(SHOTS, 'gostop-mid-phone-dark.png'), fullPage: true });
|
||
await host.screenshot({ path: join(SHOTS, 'gostop-mid-pc-dark.png') });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!acted) await host.waitForTimeout(150);
|
||
}
|
||
if (!(await over())) throw new Error(`hand did not end (${JSON.stringify(state)})`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'gostop-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'gostop-result-phone.png') });
|
||
// Close the result sheet to see the round breakdown underneath.
|
||
await host.keyboard.press('Escape');
|
||
await host.getByText(/1판 결과/).first().waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'gostop-breakdown-pc.png') });
|
||
if (state.plays < 10) throw new Error(`only ${state.plays} cards were played`);
|
||
console.log(` gostop: ${state.plays} plays, ${state.sheets} choice sheets (${state.picks} card picks), 고 ${state.go}, 스톱 ${state.stop}`);
|
||
},
|
||
},
|
||
bang: {
|
||
// PC host + 3 phone guests, reaction time 25s: real turns through the UI — draw, play usable cards
|
||
// (뱅! at a highlighted target → confirm, other untargeted cards by double tap), answer reaction
|
||
// sheets (빗나감!/맥주/결투/인디언!/잡화점), discard down to the hand limit, end the turn.
|
||
players: 4,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '반응 제한 시간' }).getByRole('button', { name: '25초' }).click();
|
||
await host.getByText(/반응 25초/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const stats = { turns: 0, bangs: 0, plays: 0, reactions: 0, discards: 0 };
|
||
let finished = false;
|
||
let shot = false;
|
||
let midShot = false;
|
||
const tryClick = (l: ReturnType<Page['locator']>) => l.click({ timeout: 1500 }).then(() => true, () => false);
|
||
/** One UI step on this page; true when something was pressed. */
|
||
const step = async (p: Page): Promise<boolean> => {
|
||
const modal = p.locator('.bg-modal');
|
||
if (await modal.count()) {
|
||
const store = modal.locator('button.bg-card');
|
||
const title = (await modal.locator('h2').innerText().catch(() => '')).trim();
|
||
if (title.startsWith('3장 중')) {
|
||
await store.nth(0).click();
|
||
await store.nth(1).click();
|
||
await modal.getByRole('button', { name: '이 2장 받기' }).click();
|
||
} else if (title.startsWith('잡화점')) await store.first().click();
|
||
else {
|
||
const use = modal.getByRole('button', { name: /(내기|마시기)$/ });
|
||
if (!(await use.count()) || !(await tryClick(use.first()))) {
|
||
if (!(await tryClick(modal.getByRole('button', { name: /^(포기하고 맞기|맞기|쓰러지기)/ }).first()))) return false;
|
||
}
|
||
}
|
||
stats.reactions++;
|
||
return true;
|
||
}
|
||
const draw = p.getByRole('button', { name: '카드 더미에서 2장 받기' });
|
||
if (await draw.count()) return tryClick(draw);
|
||
const discardBtn = p.getByRole('button', { name: /장 버리기$/ });
|
||
if (await discardBtn.count()) {
|
||
const need = Number((await p.locator('.bg-actions').innerText()).match(/버릴 카드 (\d+)장/)?.[1] ?? 0);
|
||
const cards = p.locator('.bg-me .bg-hand button.bg-card');
|
||
for (let i = 0; i < need; i++) await cards.nth(i).click();
|
||
await discardBtn.click();
|
||
stats.discards++;
|
||
return true;
|
||
}
|
||
const end = p.getByRole('button', { name: '턴 마치기' });
|
||
if (!(await end.count()) || !(await end.isEnabled())) return false;
|
||
// Shoot first (once per turn is enough), then other untargeted cards, then end the turn.
|
||
const bang = p.locator('.bg-me button.bg-card[data-kind="bang"][data-ok="true"]').first();
|
||
if (await bang.count()) {
|
||
await bang.click();
|
||
const target = p.locator('button.bg-seat[data-target="ok"]').first();
|
||
await target.waitFor({ timeout: 2000 });
|
||
await target.click();
|
||
const fire = p.getByRole('button', { name: /님에게 뱅!$/ });
|
||
await fire.click();
|
||
stats.bangs++;
|
||
if (!shot) {
|
||
shot = true;
|
||
await p.waitForTimeout(400);
|
||
for (const [i, q] of pages.entries()) await q.screenshot({ path: join(SHOTS, `bang-3-shot-${i === 0 ? 'pc' : `phone${i}`}.png`) });
|
||
}
|
||
return true;
|
||
}
|
||
const simple = ['beer', 'stagecoach', 'wellsFargo', 'saloon', 'barrel', 'mustang', 'scope', 'schofield', 'remington', 'carabine', 'winchester', 'volcanic', 'indians', 'gatling', 'generalStore'];
|
||
for (const k of simple) {
|
||
const c = p.locator(`.bg-me button.bg-card[data-kind="${k}"][data-ok="true"]`).first();
|
||
if (!(await c.count())) continue;
|
||
await c.click();
|
||
await c.click();
|
||
stats.plays++;
|
||
return true;
|
||
}
|
||
await end.click();
|
||
stats.turns++;
|
||
return true;
|
||
};
|
||
const until = Date.now() + 240_000;
|
||
while (Date.now() < until && stats.turns < 10) {
|
||
if (await pages[0]!.getByRole('dialog', { name: '게임 결과' }).count()) {
|
||
finished = true;
|
||
break;
|
||
}
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
if (await step(p)) {
|
||
acted = true;
|
||
await p.waitForTimeout(250);
|
||
break;
|
||
}
|
||
}
|
||
if (stats.turns >= 4 && !midShot) {
|
||
midShot = true;
|
||
await pages[0]!.screenshot({ path: join(SHOTS, 'bang-4-mid-pc.png') });
|
||
await pages[1]!.screenshot({ path: join(SHOTS, 'bang-4-mid-phone.png'), fullPage: true });
|
||
await pages[1]!.emulateMedia({ colorScheme: 'dark' });
|
||
await pages[1]!.screenshot({ path: join(SHOTS, 'bang-4-mid-phone-dark.png') });
|
||
await pages[1]!.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!acted) await pages[0]!.waitForTimeout(150);
|
||
}
|
||
console.log(` bang: ${stats.turns} turns, ${stats.bangs} 뱅!, ${stats.plays} other cards, ${stats.reactions} reactions, ${stats.discards} discards${finished ? ', game finished' : ''}`);
|
||
if (!finished && stats.turns < 8) throw new Error(`only ${stats.turns} turns were played`);
|
||
if (stats.bangs < 1) throw new Error('no 뱅! was played');
|
||
},
|
||
},
|
||
'halli-galli': {
|
||
// PC host + 2 phones. Real flips (Enter on PC, taps on phones); whenever some fruit totals exactly five a player
|
||
// rings the bell (PC: Space, phone: tap), plus at least one deliberate wrong bell. 24+ flips through the UI.
|
||
players: 3,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '뒤집기 제한 시간' }).getByRole('button', { name: '5초', exact: true }).click();
|
||
await host.getByText(/뒤집기 5초/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page, Page];
|
||
const myTurn = (p: Page) => p.evaluate(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'));
|
||
const ended = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
await host.locator('.hg-seat').first().waitFor();
|
||
// 3-second countdown first.
|
||
await host.waitForFunction(() => !document.querySelector('.hg-count'), null, { timeout: 8000 });
|
||
let flips = 0;
|
||
let rights = 0;
|
||
let wrongs = 0;
|
||
let lates = 0;
|
||
let shots = 0;
|
||
let ringer = 0;
|
||
const until = Date.now() + 150_000;
|
||
const bubble = (p: Page) => p.locator('.hg-bubble').first().innerText({ timeout: 2500 }).catch(() => '');
|
||
while (Date.now() < until && !(await ended()) && (flips < 24 || rights < 1 || wrongs < 1)) {
|
||
const totals = await halliTotals(host);
|
||
const five = Object.values(totals).includes(5);
|
||
const wantWrong = !five && wrongs === 0 && flips >= 4 && Object.values(totals).some((n) => n > 0);
|
||
if (five || wantWrong) {
|
||
const p = pages[ringer++ % pages.length]!;
|
||
const bell = p.locator('.hg-bell');
|
||
if (await bell.isEnabled().catch(() => false)) {
|
||
if (p === host) {
|
||
await host.evaluate(() => (document.activeElement as HTMLElement | null)?.blur());
|
||
await host.keyboard.press('Space');
|
||
} else await bell.tap();
|
||
const text = await bubble(p);
|
||
if (text.includes('땡')) rights++;
|
||
else if (text.includes('삐')) wrongs++;
|
||
else if (text.includes('늦었어요')) lates++;
|
||
if (shots === 0 && text) {
|
||
shots++;
|
||
await host.screenshot({ path: join(SHOTS, 'halli-galli-bell-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'halli-galli-bell-phone.png') });
|
||
}
|
||
await host.waitForTimeout(400);
|
||
continue;
|
||
}
|
||
}
|
||
let flipped = false;
|
||
for (const p of pages) {
|
||
if (!(await myTurn(p))) continue;
|
||
const btn = p.getByRole('button', { name: '뒤집기', exact: true });
|
||
if (!(await btn.isEnabled().catch(() => false))) break;
|
||
const before = await p.locator('.hg-seat[data-me="true"] .hg-meta').innerText();
|
||
if (p === host) {
|
||
await host.evaluate(() => (document.activeElement as HTMLElement | null)?.blur());
|
||
await host.keyboard.press('Enter');
|
||
} else await btn.tap();
|
||
await p.waitForFunction((b) => document.querySelector('.hg-seat[data-me="true"] .hg-meta')?.textContent !== b, before, { timeout: 3000 }).catch(() => {});
|
||
flips++;
|
||
flipped = true;
|
||
break;
|
||
}
|
||
if (flips === 12 && flipped && shots < 2) {
|
||
shots = 2;
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'halli-galli-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'halli-galli-mid-phone.png') });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.waitForTimeout(400); // let the theme transition finish
|
||
await guest.screenshot({ path: join(SHOTS, 'halli-galli-mid-phone-dark.png') });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'halli-galli-mid-pc-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
await host.waitForTimeout(flipped ? 650 : 120);
|
||
}
|
||
console.log(` halli-galli: ${flips} UI flips, ${rights} correct bells, ${wrongs} wrong bells, ${lates} late`);
|
||
if (!(await ended()) && (flips < 20 || wrongs < 1)) throw new Error('not enough flips / bells');
|
||
if (rights < 1 && !(await ended())) throw new Error('no correct bell happened');
|
||
},
|
||
},
|
||
marble: {
|
||
// PC host + phone guest, 15 rounds (shortest limit) played through the UI to the result: roll, buy or
|
||
// build (skip when short), pay tolls, sell when short, space travel via a board square. Mid-game shots.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '라운드 제한' }).getByRole('button', { name: '15라운드' }).click();
|
||
await host.getByRole('group', { name: '시작 포인트' }).getByRole('button', { name: '200P' }).click();
|
||
await host.getByText(/^15라운드 · 시작 200P/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const stats: Record<string, number> = {};
|
||
let actions = 0;
|
||
let shot = false;
|
||
const until = Date.now() + 420_000;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
if (await marbleStep(p, stats)) {
|
||
acted = true;
|
||
actions++;
|
||
await p.waitForTimeout(80);
|
||
break;
|
||
}
|
||
}
|
||
if (actions >= 40 && !shot && (stats['사기'] ?? 0) >= 3) {
|
||
shot = true;
|
||
await host.waitForTimeout(1300);
|
||
await host.screenshot({ path: join(SHOTS, 'marble-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'marble-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'marble-mid-phone-full.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(400); // let the button colour transitions settle
|
||
await host.screenshot({ path: join(SHOTS, 'marble-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'marble-mid-phone-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (acted && !stats.toll && (await host.locator('.mb-log li', { hasText: /→.*통행료/ }).count())) stats.toll = 1;
|
||
if (!acted) await host.waitForTimeout(120);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${actions} UI actions: ${JSON.stringify(stats)})`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600); // result dialog fade-in
|
||
await host.screenshot({ path: join(SHOTS, 'marble-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'marble-result-phone.png') });
|
||
const rolls = (stats['🎲 주사위 굴리기'] ?? 0) + (stats['🎲 한 번 더 굴리기'] ?? 0) + (stats['🎲 탈출 굴리기'] ?? 0);
|
||
if (rolls < 15 || !stats['사기']) throw new Error(`too few real turns: ${JSON.stringify(stats)}`);
|
||
console.log(` marble: finished after ${actions} UI actions ${JSON.stringify(stats)}`);
|
||
},
|
||
},
|
||
dalmuti: {
|
||
// PC host + 3 phone guests, 9~12 removed (38 cards) for a shorter round: real turns through the UI (sets with
|
||
// jesters, passes) until round 1 ends, then the round-2 hand check and the tax exchange (세금 카드 교환) screen.
|
||
players: 4,
|
||
lobby: async (host) => {
|
||
await host.getByRole('button', { name: '▼ 자세한 설정' }).click();
|
||
await host.getByRole('group', { name: '9~12 카드 빼기' }).getByRole('button', { name: '켜기' }).click();
|
||
await host.getByRole('group', { name: '한 턴 제한 시간' }).getByRole('button', { name: '45초' }).click();
|
||
await host.getByText(/9~12 빼기/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st: Record<string, number> = { turns: 0 };
|
||
let actions = 0;
|
||
let midShot = false;
|
||
let round2 = false;
|
||
const until = Date.now() + 300_000;
|
||
const playingAgain = () => host.locator('.dm-table').count();
|
||
while (Date.now() < until) {
|
||
let acted = false;
|
||
for (const [i, p] of pages.entries()) {
|
||
if (await dalmutiStep(p, i === 0, st)) {
|
||
acted = true;
|
||
actions++;
|
||
await p.waitForTimeout(120);
|
||
break;
|
||
}
|
||
}
|
||
if (!midShot && (st.plays ?? 0) >= 6 && (await host.locator('.dm-set.top').count())) {
|
||
midShot = true;
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'dalmuti-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dalmuti-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dalmuti-mid-phone-full.png'), fullPage: true });
|
||
for (const p of [host, guest]) await p.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'dalmuti-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dalmuti-mid-phone-dark.png') });
|
||
for (const p of [host, guest]) await p.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!round2 && (await host.getByText('1라운드 결과 → 새 신분').count())) {
|
||
round2 = true;
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'dalmuti-round2-check-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dalmuti-round2-check-phone.png'), fullPage: true });
|
||
}
|
||
if (round2 && st.taxDone === undefined && (await host.getByRole('heading', { name: '세금 카드 교환' }).count())) {
|
||
st.taxDone = 0;
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'dalmuti-round2-tax-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dalmuti-round2-tax-phone.png'), fullPage: true });
|
||
}
|
||
// Done: round 2's tax exchange happened (or a revolution skipped it) and the table is back, with a jester set seen.
|
||
if (round2 && (await playingAgain()) && (st.jesterPlays ?? 0) > 0) break;
|
||
if (!acted) await host.waitForTimeout(120);
|
||
}
|
||
if (!round2) throw new Error(`round 1 did not finish (${actions} UI actions: ${JSON.stringify(st)})`);
|
||
if (!(await playingAgain())) throw new Error(`round 2 did not start playing (${JSON.stringify(st)})`);
|
||
if (!st.passes || (st.plays ?? 0) < 8 || !st.jesterPlays) throw new Error(`too few real turns / no jester set: ${JSON.stringify(st)}`);
|
||
await host.screenshot({ path: join(SHOTS, 'dalmuti-round2-pc.png') });
|
||
console.log(` dalmuti: ${actions} UI actions ${JSON.stringify(st)}${st.taxDone === 0 ? ', tax screen shown' : ', revolution (no tax)'}`);
|
||
},
|
||
},
|
||
splendor: {
|
||
// PC host + phone guest, short game (10 points) through the UI to the result: 3 different gems, 2 of a
|
||
// colour, reserve an open card and a blind deck card (gold), buy highlighted cards (with gold too),
|
||
// return tokens over 10 and choose nobles when it happens. Mid-game shots in light and dark.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '끝나는 점수' }).getByRole('button', { name: '10점(짧은 판)' }).click();
|
||
await host.getByText(/^10점 · 한 차례 60초/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const stats: Record<string, number> = {};
|
||
let turns = 0;
|
||
let shot = false;
|
||
const until = Date.now() + 480_000;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted: string | null = null;
|
||
for (const p of pages) {
|
||
const before = (await p.locator('.turn-status').innerText().catch(() => '')).trim();
|
||
acted = await splendorStep(p, stats, turns);
|
||
if (acted) {
|
||
stats[acted] = (stats[acted] ?? 0) + 1;
|
||
turns++;
|
||
// Wait until the server answered (status or log changed).
|
||
await p
|
||
.waitForFunction((b) => (document.querySelector('.turn-status')?.textContent ?? '').trim() !== b || !!document.querySelector('[role="dialog"]'), before, { timeout: 5000 })
|
||
.catch(() => {});
|
||
break;
|
||
}
|
||
}
|
||
if (turns >= 14 && !shot) {
|
||
shot = true;
|
||
await host.waitForTimeout(700);
|
||
await host.screenshot({ path: join(SHOTS, 'splendor-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'splendor-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'splendor-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, 'splendor-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'splendor-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 (${turns} UI turns: ${JSON.stringify(stats)})`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'splendor-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'splendor-result-phone.png') });
|
||
if (turns < 15 || !stats.buy || !stats.reserve || !stats.different || !stats.same || !stats.discard) throw new Error(`too few kinds of turns: ${JSON.stringify(stats)}`);
|
||
console.log(` splendor: finished after ${turns} UI turns ${JSON.stringify(stats)}`);
|
||
},
|
||
},
|
||
quoridor: {
|
||
// PC 방장 + 휴대폰 친구(2인, 자리는 무작위). 남: 세로벽 d8 → 북: 세로벽 e8(북이 e8·e9 상자 안) → 남: 가로벽 e7은
|
||
// 북의 길을 완전히 막으므로 빨간 미리보기·이유와 함께 거부 → 다른 가로벽 a3. 그 뒤 둘 다 e열 최단 길로 달려
|
||
// 마주치면 뛰어넘고, 먼저 끝줄에 닿은 쪽이 이긴다(첫 이동은 키보드 ↑+Enter).
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
await qdSvg(host).waitFor();
|
||
await qdSvg(guest).waitFor();
|
||
const south = (await qdSvg(host).getAttribute('data-my-seat')) === 'S' ? host : guest;
|
||
const north = south === host ? guest : host;
|
||
if ((await qdSvg(north).getAttribute('data-my-seat')) !== 'N') throw new Error('seats are not S/N');
|
||
await qdPreviewWall(south, 'd8', 'v');
|
||
await qdConfirmWall(south);
|
||
await qdPreviewWall(north, 'e8', 'v');
|
||
await north.waitForTimeout(200);
|
||
await north.screenshot({ path: join(SHOTS, `quoridor-wall-preview-${tag(north)}.png`) });
|
||
await qdConfirmWall(north);
|
||
const bad = await qdPreviewWall(south, 'e7', 'h');
|
||
if (!bad.endsWith(':bad')) throw new Error(`blocking wall was not refused (${bad})`);
|
||
await south.getByText('누군가의 길을 완전히 막을 수 없어요').first().waitFor();
|
||
if (await south.getByRole('button', { name: '벽 세우기 확인' }).isEnabled()) throw new Error('confirm enabled for an illegal wall');
|
||
await south.waitForTimeout(300);
|
||
await south.screenshot({ path: join(SHOTS, `quoridor-illegal-wall-${tag(south)}.png`) });
|
||
if ((await south.locator('[data-wall]').count()) !== 2) throw new Error('illegal wall was placed');
|
||
await qdPreviewWall(south, 'a3', 'h');
|
||
await qdConfirmWall(south);
|
||
let jumps = 0;
|
||
let steps = 0;
|
||
let shot = false;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
const first = new Set<Page>();
|
||
for (let turn = 0; turn < 40 && !(await over()); turn++) {
|
||
const mover = turn % 2 === 0 ? north : south;
|
||
const useKeys = mover === host && !first.has(mover);
|
||
first.add(mover);
|
||
if (await qdStep(mover, useKeys)) jumps++;
|
||
steps++;
|
||
if (steps === 6 && !shot) {
|
||
shot = true;
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'quoridor-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'quoridor-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'quoridor-mid-phone-full.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'quoridor-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'quoridor-mid-phone-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
await host.waitForTimeout(150);
|
||
}
|
||
await host.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'quoridor-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'quoridor-result-phone.png') });
|
||
const summary = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||
if (!/승리 — \d+수 만에 도착/.test(summary)) throw new Error(`unexpected result: ${summary.slice(0, 80)}`);
|
||
if (jumps < 1) throw new Error('no jump happened');
|
||
console.log(` quoridor: 3 walls + 1 refused wall, ${steps} pawn moves (${jumps} jump), ${summary.split('\n').find((l) => l.includes('승리'))}`);
|
||
},
|
||
},
|
||
'las-vegas': {
|
||
// PC host + phone guest (2 players → 4 white dice each), 3 rounds via the lobby: real rolls and placements
|
||
// through the UI until round settlements (with a duplicate-tie cancellation) and the final result appear.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '라운드 수' }).getByRole('button', { name: '3라운드' }).click();
|
||
await host.getByText(/^3라운드 · 흰 주사위 자동/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st = { rolls: 0, places: 0, keyboard: false, casinoPick: false, shots: new Set<string>() };
|
||
let tieSeen = false;
|
||
let settleShot = 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 [i, p] of pages.entries()) {
|
||
if (await lasVegasStep(p, i > 0, st)) {
|
||
acted = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!settleShot && (await host.locator('section[aria-label="1라운드 정산"]').count())) {
|
||
settleShot = true;
|
||
await host.waitForTimeout(700);
|
||
await host.screenshot({ path: join(SHOTS, 'las-vegas-settle-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'las-vegas-settle-phone.png'), fullPage: true });
|
||
}
|
||
if (!tieSeen && (await host.locator('.lv-settle .lv-tieout').count())) tieSeen = true;
|
||
if (!acted) await host.waitForTimeout(150);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${JSON.stringify({ ...st, shots: [...st.shots] })})`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
if (!tieSeen && (await host.locator('.lv-settle .lv-tieout').count())) tieSeen = true;
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'las-vegas-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'las-vegas-result-phone.png') });
|
||
// Close the result sheet to look at the final table on the board.
|
||
await host.keyboard.press('Escape');
|
||
await host.locator('section[aria-label="최종 결과"]').waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'las-vegas-final-pc.png') });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(250);
|
||
await host.screenshot({ path: join(SHOTS, 'las-vegas-final-pc-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
if (!(await host.locator('section[aria-label="3라운드 정산"]').count())) throw new Error('no settlement for round 3');
|
||
if (!tieSeen) throw new Error('no duplicate-tie cancellation appeared in any settlement');
|
||
if (st.rolls < 10 || st.places < 10 || !st.keyboard || !st.casinoPick) throw new Error(`too few real turns: ${JSON.stringify({ ...st, shots: [...st.shots] })}`);
|
||
console.log(` las-vegas: ${st.rolls} rolls, ${st.places} placements, tie cancellation seen`);
|
||
},
|
||
},
|
||
'cockroach-poker': {
|
||
// PC host + 2 phones, "같은 벌레 3장" for a shorter game. Real turns through the UI until someone loses:
|
||
// offer a face-down card with a claim, the target calls 진짜!/거짓말! or peeks and passes; the card goes face-up.
|
||
players: 3,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '같은 벌레 몇 장이면 패배' }).getByRole('button', { name: '3장(짧게)' }).click();
|
||
await host.getByRole('group', { name: '건네기·판정 제한 시간' }).getByRole('button', { name: '무제한' }).click();
|
||
await host.getByText(/같은 벌레 3장이면 패배.*시간 무제한/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page, Page];
|
||
const stats: Record<string, number> = {};
|
||
let actions = 0;
|
||
let shot = false;
|
||
const until = Date.now() + 300_000;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
const did = await cockroachStep(p, stats);
|
||
if (did) {
|
||
acted = true;
|
||
actions++;
|
||
// Wait for the server to move on before looking again.
|
||
await p.waitForFunction(() => !document.querySelector('.turn-status')?.textContent?.includes('내 차례예요') || !!document.querySelector('.cp-panel button.cp-target'), null, { timeout: 4000 }).catch(() => {});
|
||
await p.waitForTimeout(120);
|
||
break;
|
||
}
|
||
}
|
||
if (!shot && (stats.true ?? 0) + (stats.false ?? 0) >= 4 && (await host.locator('.cp-chip').count()) >= 3) {
|
||
shot = true;
|
||
await host.waitForTimeout(800);
|
||
await host.screenshot({ path: join(SHOTS, 'cockroach-poker-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'cockroach-poker-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'cockroach-poker-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, 'cockroach-poker-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'cockroach-poker-mid-phone-dark.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!acted) await host.waitForTimeout(120);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${actions} UI actions: ${JSON.stringify(stats)})`);
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'cockroach-poker-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'cockroach-poker-result-phone.png') });
|
||
const calls = (stats.true ?? 0) + (stats.false ?? 0);
|
||
if (!stats.offer || calls < 3) throw new Error(`too few real turns: ${JSON.stringify(stats)}`);
|
||
console.log(` cockroach-poker: finished after ${actions} UI actions ${JSON.stringify(Object.fromEntries(Object.entries(stats).filter(([k]) => !k.startsWith('shot'))))}`);
|
||
},
|
||
},
|
||
'ninety-nine': {
|
||
// PC host + 2 phones, 전용 카드 with 6 of each special card and no turn clock (무제한: no timer anywhere). Real turns through the UI until the
|
||
// game ends: joker via the number dial (quick 99, then −1), ± cards via their +/− buttons, 0 with its keep/reverse
|
||
// direction buttons, otherwise a number card (PC: keyboard Enter twice, phones: tap twice). 3 players start at 20
|
||
// with 5 cards each (official rules). Players run out of cards and are eliminated.
|
||
players: 3,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '한 턴 제한 시간' }).getByRole('button', { name: '무제한' }).click();
|
||
await host.getByRole('button', { name: '▼ 자세한 설정' }).click();
|
||
await host.getByRole('group', { name: '특수 카드 장수' }).getByRole('button', { name: '6장' }).click();
|
||
await host.getByText(/^전용 카드 · 손패 5장 · 목숨 없음 · 시간 무제한/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page, Page];
|
||
const stats: Record<string, number> = {};
|
||
let turns = 0;
|
||
let shot = false;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
const until = Date.now() + 240_000;
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
if (await ninetyNineStep(p, stats)) {
|
||
acted = true;
|
||
turns++;
|
||
break;
|
||
}
|
||
}
|
||
if (!shot && turns >= 5) {
|
||
shot = true;
|
||
await host.waitForTimeout(500);
|
||
for (const p of pages) if (await p.getByRole('timer').count()) throw new Error('무제한 room still shows a turn timer');
|
||
await host.screenshot({ path: join(SHOTS, 'ninety-nine-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'ninety-nine-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'ninety-nine-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, 'ninety-nine-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'ninety-nine-mid-phone-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!acted) await host.waitForTimeout(120);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${turns} turns: ${JSON.stringify(stats)})`);
|
||
const outs = await host.locator('.nn-log li', { hasText: '탈락했어요' }).count();
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'ninety-nine-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'ninety-nine-result-phone.png') });
|
||
const specials = (stats.joker ?? 0) + (stats.plus ?? 0) + (stats.minus ?? 0) + (stats.reverse ?? 0) + (stats.keep ?? 0);
|
||
if (turns < 6 || specials < 1 || outs < 1) throw new Error(`too few real turns / special cards / eliminations: ${turns} ${JSON.stringify(stats)} outs=${outs}`);
|
||
console.log(` ninety-nine: finished after ${turns} UI turns ${JSON.stringify(stats)}, ${outs} eliminations in the log`);
|
||
},
|
||
},
|
||
'old-maid': {
|
||
// PC host + 2 phones, real draws through the UI until only the joker is left: PC clicks (sometimes keyboard), phones tap
|
||
// twice (pick, then draw). Whoever is being drawn from sometimes shuffles their hand. Screens: mid-game (light/dark), result.
|
||
players: 3,
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page, Page];
|
||
const stats: Record<string, number> = {};
|
||
let shot = false;
|
||
const until = Date.now() + 300_000;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) if (await oldMaidShuffle(p, stats)) acted = true;
|
||
for (const p of pages) {
|
||
if (await oldMaidStep(p, stats)) {
|
||
acted = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!shot && (stats.draws ?? 0) >= 6) {
|
||
shot = true;
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'old-maid-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'old-maid-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'old-maid-mid-phone-full.png'), fullPage: true });
|
||
// Narrowest supported phone.
|
||
await guest.setViewportSize({ width: 320, height: 700 });
|
||
await guest.waitForTimeout(300);
|
||
await guest.screenshot({ path: join(SHOTS, 'old-maid-mid-phone-320.png'), fullPage: true });
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'old-maid-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'old-maid-mid-phone-dark.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!acted) await host.waitForTimeout(120);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${JSON.stringify(stats)})`);
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
const dialog = host.getByRole('dialog', { name: '게임 결과' });
|
||
await dialog.getByText('🃏 도둑').first().waitFor({ timeout: 3000 });
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'old-maid-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'old-maid-result-phone.png') });
|
||
if ((stats.draws ?? 0) < 6 || !stats.confirm || !stats.click || !stats.keyboard) throw new Error(`too few real turns: ${JSON.stringify(stats)}`);
|
||
console.log(` old-maid: finished after ${JSON.stringify(Object.fromEntries(Object.entries(stats).filter(([k]) => !k.startsWith('shot'))))}`);
|
||
},
|
||
},
|
||
dobble: {
|
||
// PC host + phone guest, 탑 쌓기 with the 55-card deck and a 1-second lock. Both players find the shared picture of their own card and the centre
|
||
// card on their own screen (PC: keyboard focus + Enter, phone: tap), one deliberate wrong tap (shake + lock), until the draw pile runs out.
|
||
lobby: async (host) => {
|
||
await host.getByRole('button', { name: '▼ 자세한 설정' }).click();
|
||
await host.getByRole('group', { name: '카드 장수' }).getByRole('button', { name: '55장' }).click();
|
||
await host.getByText(/^탑 쌓기 · 55장 · 틀리면 1초 잠금/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
await host.locator('[data-card="mine"] .db-sym:not([disabled])').first().waitFor({ timeout: 10_000 });
|
||
const st = { ok: 0, wrong: 0, late: 0, other: 0 };
|
||
let n = 0;
|
||
let shots = 0;
|
||
const until = Date.now() + 180_000;
|
||
while (Date.now() < until && !(await over())) {
|
||
const p = pages[n++ % pages.length]!;
|
||
const wantWrong = st.wrong === 0 && st.ok >= 3 && p === guest;
|
||
const text = await dobbleTap(p, wantWrong);
|
||
if (text === null) {
|
||
await host.waitForTimeout(150);
|
||
continue;
|
||
}
|
||
if (text.startsWith('찾았어요')) st.ok++;
|
||
else if (text.includes('틀렸어요')) {
|
||
st.wrong++;
|
||
await guest.screenshot({ path: join(SHOTS, 'dobble-wrong-phone.png') });
|
||
if (!(await guest.locator('.db-lock').count())) throw new Error('no lock after a wrong tap');
|
||
} else if (text.includes('늦었어요')) st.late++;
|
||
else {
|
||
st.other++;
|
||
if (st.other <= 3) console.log(` dobble: other judgement ${JSON.stringify(text)}`);
|
||
}
|
||
// Human pace: a tap right after the cards changed counts as aimed at the old card (the screen drops it as late).
|
||
await host.waitForTimeout(300);
|
||
if (shots === 0 && st.ok >= 6) {
|
||
shots = 1;
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'dobble-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dobble-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dobble-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, 'dobble-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dobble-mid-phone-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish ${JSON.stringify(st)}`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'dobble-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'dobble-result-phone.png') });
|
||
if (st.ok < 20 || st.wrong < 1) throw new Error(`too few real finds / wrong taps: ${JSON.stringify(st)}`);
|
||
console.log(` dobble: finished after ${st.ok} correct taps, ${st.wrong} wrong, ${st.late} late, ${st.other} other`);
|
||
},
|
||
},
|
||
catchmind: {
|
||
// PC host + phone guest, 1 round with no drawing time limit (무제한): each player draws once with real mouse strokes; the other sees the strokes
|
||
// (stroke count + pixels), guesses wrong, gets "아까워요" for a near miss, then the right answer; scores update.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '라운드 수' }).getByRole('button', { name: '1라운드' }).click();
|
||
await host.getByRole('group', { name: '그리기 시간' }).getByRole('button', { name: '무제한' }).click();
|
||
await host.getByText(/^여러 명 맞히기 · 1라운드 · 그리기 무제한/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const words: string[] = [];
|
||
for (let turn = 1; turn <= 2; turn++) {
|
||
words.push(await catchmindTurn(pages, turn, true));
|
||
// Multi mode: 1st solver 10 points, drawer 2 per solver.
|
||
const scores = await host.locator('.cm-score').innerText();
|
||
if (turn === 1 && !(/10점/.test(scores) && /2점/.test(scores))) throw new Error(`scores not updated: ${scores.replace(/\n/g, ' ')}`);
|
||
}
|
||
await host.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'catchmind-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'catchmind-result-phone.png') });
|
||
const final = await host.locator('.cm-score').innerText();
|
||
if ((final.match(/12점/g) ?? []).length !== 2) throw new Error(`unexpected final scores: ${final.replace(/\n/g, ' ')}`);
|
||
console.log(` catchmind: drew and guessed ${words.join(', ')}; both 12 points (10 + 2)`);
|
||
},
|
||
},
|
||
liar: {
|
||
// PC host + 2 phone guests, one round of descriptions. Real flow through the UI: hold-to-see word card (the liar
|
||
// sees only "나는 라이어"), confirm, each describes in turn (a citizen saying the word is refused), discussion chat,
|
||
// "토론 끝내기", the citizens vote the liar out, the liar names the word with spaces in it and wins.
|
||
// Checks: the liar's screen never shows the word, the room chat is closed during the game.
|
||
players: 3,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '설명 바퀴 수' }).getByRole('button', { name: '한 바퀴' }).click();
|
||
// Every phase without a clock (무제한): the flow below only moves on by what people do.
|
||
await host.getByRole('button', { name: '▼ 자세한 설정' }).click();
|
||
for (const g of ['설명 시간', '토론 시간', '투표 시간', '정답 맞히기 시간']) await host.getByRole('group', { name: g }).getByRole('button', { name: '무제한' }).click();
|
||
await host.getByText(/한 바퀴 · 설명 무제한 · 토론 무제한/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, phone] = pages as [Page, Page, Page];
|
||
for (const p of pages) await liarBanner(p, '제시어 확인');
|
||
if (await host.locator('.chat-panel').count()) throw new Error('room chat panel is visible during the game');
|
||
if (await phone.getByRole('button', { name: /^채팅/ }).count()) throw new Error('room chat button is visible on the phone during the game');
|
||
const words = await Promise.all(pages.map(liarWordOf));
|
||
const L = words.indexOf(null);
|
||
const word = words.find((w) => w !== null)!;
|
||
if (L < 0 || words.filter((w) => w === null).length !== 1 || words.some((w) => w !== null && w !== word)) throw new Error(`unexpected words ${words.join(',')}`);
|
||
console.log(` liar: word ${word}, liar ${LIAR_NICKS[L]}`);
|
||
const liarClean = async (when: string) => {
|
||
if ((await pages[L]!.content()).includes(word)) throw new Error(`the liar's screen shows the word (${when})`);
|
||
};
|
||
await liarClean('reveal');
|
||
await liarShots(pages, '1-reveal');
|
||
// The card hides again by itself (2.5 s after the key press).
|
||
await host.waitForFunction(() => document.querySelector('.lg-card')?.getAttribute('aria-label')?.startsWith('내 제시어 보기'), null, { timeout: 5000 });
|
||
for (const p of pages) await p.getByRole('button', { name: /^확인했어요/ }).click();
|
||
|
||
for (const p of pages) await liarBanner(p, '한 사람씩 설명');
|
||
let refused = -1;
|
||
for (let turn = 0; turn < 3; turn++) {
|
||
let speaker = -1;
|
||
for (let t = 0; t < 100 && speaker < 0; t++) {
|
||
for (const [i, p] of pages.entries()) if (await p.getByLabel('내 설명 (한 문장)').count()) speaker = i;
|
||
if (speaker < 0) await host.waitForTimeout(100);
|
||
}
|
||
if (speaker < 0) throw new Error(`nobody can describe (turn ${turn + 1})`);
|
||
const p = pages[speaker]!;
|
||
const input = p.getByLabel('내 설명 (한 문장)');
|
||
if (refused < 0 && speaker !== L) {
|
||
await input.fill(`${[...word].join(' ')} 맞죠`);
|
||
await input.press('Enter');
|
||
await p.getByText('제시어를 직접 말하면 안 돼요.').first().waitFor({ timeout: 10_000 });
|
||
refused = speaker;
|
||
}
|
||
const text = speaker === L ? '저는 좋아하는 편이에요' : `${LIAR_NICKS[speaker]}의 설명이에요`;
|
||
if (turn === 1) await liarShots(pages, '2-describe', true);
|
||
await input.fill(text);
|
||
await input.press('Enter');
|
||
for (const q of pages) await q.locator('.lg-desc li', { hasText: text }).waitFor({ timeout: 15_000 });
|
||
}
|
||
if (refused < 0) throw new Error('saying the word was never tried');
|
||
// The refusal toast goes away by itself (3 s).
|
||
await pages[refused]!.locator('.toast', { hasText: '제시어를 직접 말하면 안 돼요.' }).waitFor({ state: 'detached', timeout: 6000 });
|
||
await liarClean('describe');
|
||
for (const [i, p] of pages.entries()) {
|
||
const hidden = await p
|
||
.waitForFunction(() => document.querySelector('.lg-card')?.getAttribute('aria-label')?.startsWith('내 제시어 보기'), null, { timeout: 4000 })
|
||
.then(() => true, () => false);
|
||
if (!hidden) throw new Error(`${LIAR_NICKS[i]}: word card stays open after the descriptions`);
|
||
}
|
||
|
||
for (const p of pages) await liarBanner(p, '자유 토론');
|
||
const citizen = (L + 1) % 3;
|
||
await pages[citizen]!.getByLabel('토론 채팅 메시지').fill(`${LIAR_NICKS[L]}님이 수상해요`);
|
||
await pages[citizen]!.getByLabel('토론 채팅 메시지').press('Enter');
|
||
for (const p of pages) await p.locator('.lg-msgs .lg-msg', { hasText: '님이 수상해요' }).waitFor({ timeout: 15_000 });
|
||
{
|
||
const ph = pages[citizen === 1 ? 2 : 1]!; // a phone
|
||
await sendByButton(ph, ph.getByLabel('토론 채팅 메시지'), ph.locator('.lg-form').getByRole('button', { name: '보내기' }), '버튼으로 보낸 말');
|
||
for (const p of pages) await p.locator('.lg-msgs .lg-msg', { hasText: '버튼으로 보낸 말' }).waitFor({ timeout: 15_000 });
|
||
}
|
||
await liarShots(pages, '3-discussion', true);
|
||
await liarClean('discussion');
|
||
for (const p of pages) await p.getByRole('button', { name: /^토론 끝내기/ }).click();
|
||
|
||
for (const p of pages) await liarBanner(p, '라이어 지목 투표', 15_000);
|
||
const pickTile = async (p: Page, nick: string) => {
|
||
const name = p.locator('.nm', { hasText: new RegExp(`^${nick}( \\(나\\))?$`) });
|
||
await p.locator('button.lg-tile[data-target="ok"]', { has: name }).click();
|
||
};
|
||
await liarShots(pages, '4-vote');
|
||
for (const [i, p] of pages.entries()) await pickTile(p, LIAR_NICKS[i === L ? (L + 1) % 3 : L]!);
|
||
|
||
await liarBanner(pages[L]!, '라이어의 정답 맞히기', 15_000);
|
||
for (const p of pages) await p.locator('.lg-news', { hasText: '라이어가 맞아요!' }).waitFor();
|
||
await pages[citizen]!.locator('.lg-tag.liar').first().waitFor();
|
||
await liarShots(pages, '5-guess');
|
||
const guess = pages[L]!.getByLabel('제시어 맞히기');
|
||
await guess.fill(` ${[...word].join(' ')} `);
|
||
await guess.press('Enter');
|
||
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||
for (const p of pages) await p.locator('.lg-final', { hasText: '라이어 승리' }).waitFor();
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'liar-6-result-pc.png') });
|
||
await phone.screenshot({ path: join(SHOTS, 'liar-6-result-phone.png') });
|
||
console.log(' liar: describe (word refused) → discussion → vote → liar caught → named the word → liar won');
|
||
},
|
||
},
|
||
mafia: {
|
||
// PC host + 3 phone guests (마피아·경찰·의사·시민), short phases via the lobby. Real flow through the UI: role card,
|
||
// greeting chat in 전체, night (mafia chat + target, police investigates the mafia, doctor guards themself), the
|
||
// morning news, dead chat, discussion → vote → last defense → 찬반 → the mafia is voted out and the town wins.
|
||
// Channel checks: mafia and dead messages never reach other screens; the room chat is closed during the game.
|
||
players: 4,
|
||
lobby: async (host) => {
|
||
// Night cannot end early (only its clock advances it), so give the night's chat+3 picks ample room under load.
|
||
await host.getByRole('group', { name: '밤 시간' }).getByRole('button', { name: '45초' }).click();
|
||
await host.getByRole('button', { name: '▼ 자세한 설정' }).click();
|
||
// 지목 투표·찬반 투표 무제한: they end as soon as everybody alive has voted.
|
||
await host.getByRole('group', { name: '지목 투표 시간' }).getByRole('button', { name: '무제한' }).click();
|
||
await host.getByRole('group', { name: '최후의 반론 시간' }).getByRole('button', { name: '10초', exact: true }).click();
|
||
await host.getByRole('group', { name: '찬반 투표 시간' }).getByRole('button', { name: '무제한' }).click();
|
||
await host.getByText(/밤 45초 · 투표 무제한/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, phone] = pages as [Page, Page, Page, Page];
|
||
for (const p of pages) await p.locator('.mf-banner').waitFor();
|
||
// Hold-to-see role card (keyboard: Enter shows it for a moment).
|
||
const card = host.locator('.mf-rolecard');
|
||
if (!(await card.getAttribute('aria-label'))!.startsWith('내 직업 보기')) throw new Error('role card shows the role before it is held');
|
||
await card.focus();
|
||
await host.keyboard.press('Enter');
|
||
if (!(await card.getAttribute('aria-label'))!.startsWith('내 직업:')) throw new Error('role card did not reveal on Enter');
|
||
await host.screenshot({ path: join(SHOTS, 'mafia-1-role-pc.png') });
|
||
// Room chat is closed while the game runs (the board has its own chat).
|
||
if (await host.locator('.chat-panel').count()) throw new Error('room chat panel is visible during the game');
|
||
if (await phone.getByRole('button', { name: /^채팅/ }).count()) throw new Error('room chat button is visible on the phone during the game');
|
||
|
||
await mafiaBanner(host, '인사 시간');
|
||
await mafiaSay(phone, '전체', '안녕하세요 반가워요');
|
||
await sendByButton(phone, phone.getByLabel('전체 채팅 메시지'), phone.locator('.mf-form').getByRole('button', { name: '보내기' }), '버튼으로 보낸 인사');
|
||
for (const p of pages) await p.locator('.mf-msgs .mf-msg', { hasText: '버튼으로 보낸 인사' }).waitFor({ timeout: 15_000 });
|
||
for (const p of pages) await p.locator('.mf-msgs .mf-msg', { hasText: '안녕하세요 반가워요' }).waitFor({ timeout: 15_000 });
|
||
// No chat pace limit: 15 lines typed back to back all show up right away, in order, on every screen.
|
||
{
|
||
const box = phone.getByLabel('전체 채팅 메시지');
|
||
const t0 = performance.now();
|
||
for (let i = 1; i <= 15; i++) {
|
||
await box.fill(`연타 ${i}`);
|
||
await box.press('Enter');
|
||
}
|
||
for (const p of pages) await p.locator('.mf-msgs .mf-msg', { hasText: /연타 15$/ }).waitFor({ timeout: 15_000 });
|
||
const ms = performance.now() - t0;
|
||
if (ms > 3000) throw new Error(`15 quick mafia chat lines took ${Math.round(ms)}ms`);
|
||
const got = (await host.locator('.mf-msgs .mf-msg', { hasText: /연타 \d+$/ }).allInnerTexts()).map((t) => t.match(/연타 \d+$/)![0]);
|
||
if (got.join(',') !== Array.from({ length: 15 }, (_, i) => `연타 ${i + 1}`).join(',')) throw new Error(`mafia chat order/lost: ${got.join(',')}`);
|
||
console.log(` mafia: 15 quick chat lines on every screen in ${Math.round(ms)}ms`);
|
||
}
|
||
for (const p of pages) await p.getByRole('button', { name: /^인사 끝내기/ }).click();
|
||
|
||
for (const p of pages) await mafiaBanner(p, '밤');
|
||
const roles = await Promise.all(pages.map(mafiaRoleOf));
|
||
const at = (r: string) => roles.indexOf(r as (typeof roles)[number]);
|
||
const [M, P, D, C] = [at('mafia'), at('police'), at('doctor'), at('citizen')];
|
||
if ([M, P, D, C].some((i) => i < 0)) throw new Error(`unexpected roles ${roles.join(',')}`);
|
||
console.log(` mafia: roles ${roles.map((r, i) => `${MAFIA_NICKS[i]}=${r}`).join(' ')}`);
|
||
// Same night layout for everyone; only the mafia has the 마피아 tab.
|
||
for (const [i, p] of pages.entries()) {
|
||
if ((await p.getByRole('tab', { name: /^마피아 채팅/ }).count()) !== (i === M ? 1 : 0)) throw new Error(`${MAFIA_NICKS[i]}: wrong 마피아 tab`);
|
||
if (!(await p.locator('.mf-actions').count())) throw new Error('night panel missing');
|
||
}
|
||
if (await pages[C]!.getByLabel('전체 채팅 메시지').count()) throw new Error('day chat open at night');
|
||
await mafiaSay(pages[M]!, '마피아', 'MAFIA-SECRET 오늘은 조용히');
|
||
await mafiaPick(pages[M]!, MAFIA_NICKS[C]!);
|
||
await mafiaPick(pages[P]!, MAFIA_NICKS[M]!);
|
||
await mafiaPick(pages[D]!, MAFIA_NICKS[D]!);
|
||
await pages[0]!.waitForTimeout(300);
|
||
for (const [i, p] of pages.entries()) {
|
||
if (i !== M && (await p.content()).includes('MAFIA-SECRET')) throw new Error(`mafia chat leaked to ${MAFIA_NICKS[i]}`);
|
||
}
|
||
await mafiaShots(pages, '2-night');
|
||
|
||
for (const p of pages) await mafiaBanner(p, '낮 토론', 60_000);
|
||
for (const p of pages) await p.locator('.mf-news', { hasText: '아침 발표' }).waitFor();
|
||
await pages[C]!.locator('.mf-news', { hasText: '탈락했어요' }).waitFor();
|
||
await pages[P]!.locator('.mf-results', { hasText: '마피아예요!' }).waitFor();
|
||
for (const [i, p] of pages.entries()) if (i !== P && (await p.locator('.mf-results').count())) throw new Error('police result shown to someone else');
|
||
// The dead citizen: no day chat, writes in 죽은 사람 only — nobody alive sees it.
|
||
await pages[C]!.getByRole('tab', { name: /^전체 채팅/ }).click();
|
||
if (await pages[C]!.getByLabel('전체 채팅 메시지').count()) throw new Error('dead player can write in day chat');
|
||
await mafiaSay(pages[C]!, '죽은 사람', 'DEAD-SECRET 저 시민이었어요');
|
||
await mafiaSay(pages[P]!, '전체', `${MAFIA_NICKS[M]}님이 마피아예요`);
|
||
await pages[0]!.waitForTimeout(300);
|
||
for (const [i, p] of pages.entries()) {
|
||
if (i !== C && (await p.content()).includes('DEAD-SECRET')) throw new Error(`dead chat leaked to ${MAFIA_NICKS[i]}`);
|
||
if (i !== M && (await p.content()).includes('MAFIA-SECRET')) throw new Error(`mafia chat leaked to ${MAFIA_NICKS[i]} by day`);
|
||
}
|
||
await mafiaShots(pages, '3-day');
|
||
for (const i of [M, P, D]) await pages[i]!.getByRole('button', { name: /^토론 끝내기/ }).click();
|
||
|
||
for (const i of [M, P, D]) await mafiaBanner(pages[i]!, '지목 투표', 15_000);
|
||
await mafiaPick(pages[P]!, MAFIA_NICKS[M]!);
|
||
await pages[P]!.getByRole('timer', { name: '시간 제한 없음' }).waitFor();
|
||
await mafiaShots(pages, '3b-vote-unlimited');
|
||
await mafiaPick(pages[D]!, MAFIA_NICKS[M]!);
|
||
// The last vote ends the 무제한 vote at once (no pressed state to wait for).
|
||
await pages[M]!.locator('button.mf-tile[data-target="ok"]', { has: pages[M]!.locator('.nm', { hasText: new RegExp(`^${MAFIA_NICKS[P]}( \\(나\\))?$`) }) }).click();
|
||
await mafiaBanner(host, '최후의 반론', 20_000);
|
||
await pages[M]!.locator('.mf-news', { hasText: '지목 투표 결과' }).waitFor();
|
||
if (await pages[P]!.getByLabel('전체 채팅 메시지').count()) throw new Error('others can talk during the last defense');
|
||
await mafiaSay(pages[M]!, '전체', '저는 진짜 시민이에요');
|
||
await pages[P]!.locator('.mf-msgs .mf-msg', { hasText: '저는 진짜 시민이에요' }).waitFor({ timeout: 15_000 });
|
||
await mafiaShots(pages, '4-defense');
|
||
await mafiaBanner(pages[P]!, '찬반 투표', 20_000);
|
||
await pages[P]!.getByRole('button', { name: '찬성 (탈락)' }).click();
|
||
await pages[P]!.getByRole('button', { name: '찬성 (탈락)', pressed: true }).waitFor();
|
||
await pages[D]!.getByRole('button', { name: '찬성 (탈락)' }).click();
|
||
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||
for (const p of pages) await p.locator('.mf-final', { hasText: '시민 팀 승리' }).waitFor();
|
||
// After the end every channel is revealed (revealChatsAtEnd).
|
||
await pages[C]!.getByRole('tab', { name: /^마피아 채팅/ }).waitFor();
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'mafia-5-result-pc.png') });
|
||
await phone.screenshot({ path: join(SHOTS, 'mafia-5-result-phone.png') });
|
||
console.log(' mafia: night kill, police result, dead chat, vote → defense → 찬반 → town won');
|
||
},
|
||
},
|
||
apple: {
|
||
// PC host + phone guest, 1-minute race on the same board. Real drags: PC with the mouse (+ one clear with the keyboard:
|
||
// arrows + Space for both corners), phone with touch on the turned 17×10 board; one deliberate miss (sum ≠ 10, no
|
||
// change); scores reach the other screen; the server clock ends the game and the result shows apples per player.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '제한 시간' }).getByRole('button', { name: '1분', exact: true }).click();
|
||
await host.getByText(/제한 시간 1분/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
for (const p of pages) await p.locator('svg.ap-board').waitFor();
|
||
for (const p of pages) await p.waitForFunction(() => !document.querySelector('.ap-over.count') && document.querySelector('svg.ap-board > g[transform]'), null, { timeout: 10_000 });
|
||
const phoneGrid = await appleGrid(guest);
|
||
const pcGrid = await appleGrid(host);
|
||
if (phoneGrid.dR !== 17 || phoneGrid.dC !== 10 || pcGrid.dR !== 10 || pcGrid.dC !== 17) throw new Error(`board shape pc ${pcGrid.dR}×${pcGrid.dC}, phone ${phoneGrid.dR}×${phoneGrid.dC}`);
|
||
// Same board for both: the phone's is the PC's turned a quarter clockwise.
|
||
const same = pcGrid.grid.every((row, r) => row.every((n, c) => phoneGrid.grid[c]![9 - r] === n));
|
||
if (!same) throw new Error('the phone does not show the same board turned');
|
||
const st = { pc: 0, phone: 0, key: 0, miss: 0 };
|
||
const clear = async (p: Page, how: 'mouse' | 'touch' | 'key') => {
|
||
const { grid } = await appleGrid(p);
|
||
const rect = appleFind(grid, 10);
|
||
if (!rect) throw new Error('no rectangle adds up to 10');
|
||
const before = await appleScore(p);
|
||
if (how === 'key') {
|
||
const board = p.locator('svg.ap-board');
|
||
await board.focus();
|
||
// To the top-left cell first (the cursor follows the last drag), then to the rectangle.
|
||
for (let i = 0; i < 17; i++) await p.keyboard.press('ArrowUp');
|
||
for (let i = 0; i < 17; i++) await p.keyboard.press('ArrowLeft');
|
||
for (let i = 0; i < rect[0]; i++) await p.keyboard.press('ArrowDown');
|
||
for (let i = 0; i < rect[1]; i++) await p.keyboard.press('ArrowRight');
|
||
await p.keyboard.press('Space');
|
||
for (let i = rect[0]; i < rect[2]; i++) await p.keyboard.press('ArrowDown');
|
||
for (let i = rect[1]; i < rect[3]; i++) await p.keyboard.press('ArrowRight');
|
||
await p.locator('.ap-pill.sum[data-s="ok"]').waitFor({ timeout: 2000 });
|
||
await p.keyboard.press('Space');
|
||
await board.blur();
|
||
} else await appleDrag(p, rect, how === 'touch');
|
||
await p.waitForFunction((b) => Number(document.querySelector('.ap-top')?.textContent?.match(/🍎\s*(\d+)/)?.[1] ?? -1) > b, before, { timeout: 3000 });
|
||
};
|
||
// A drag that does not add up to 10: nothing happens (no penalty).
|
||
const miss = appleFind((await appleGrid(host)).grid, 7);
|
||
if (miss) {
|
||
const before = await appleScore(host);
|
||
await appleDrag(host, miss, false);
|
||
await host.locator('.ap-flash.bad').waitFor({ timeout: 2000 });
|
||
if ((await appleScore(host)) !== before) throw new Error('a miss changed the score');
|
||
st.miss++;
|
||
}
|
||
for (let i = 0; i < 6; i++) {
|
||
await clear(host, 'mouse');
|
||
st.pc++;
|
||
await clear(guest, 'touch');
|
||
st.phone++;
|
||
await host.waitForTimeout(250);
|
||
}
|
||
await host.locator('svg.ap-board').evaluate((el) => (el as SVGElement).focus());
|
||
await clear(host, 'key');
|
||
st.key++;
|
||
// The other screen sees my score.
|
||
const hs = await appleScore(host);
|
||
const gs = await appleScore(guest);
|
||
const seen = (p: Page, who: string, n: number) =>
|
||
p.waitForFunction(([w, k]) => [...document.querySelectorAll('.ap-others li')].some((li) => li.textContent?.includes(w as string) && li.querySelector('b')?.textContent === String(k)), [who, n] as const, { timeout: 3000 });
|
||
await seen(guest, '방장', hs);
|
||
await seen(host, '친구', gs);
|
||
// Mid-game shots (one drag held on the phone so the live sum shows).
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'apple-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'apple-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'apple-mid-phone-full.png'), fullPage: true });
|
||
const held = appleFind((await appleGrid(host)).grid, 10)!;
|
||
{
|
||
const { box, dR, dC } = await appleGrid(host);
|
||
const at = (r: number, c: number) => ({ x: box.x + ((c + 0.5) * box.w) / dC, y: box.y + ((r + 0.5) * box.h) / dR });
|
||
await host.mouse.move(at(held[0], held[1]).x, at(held[0], held[1]).y);
|
||
await host.mouse.down();
|
||
await host.mouse.move(at(held[2], held[3]).x, at(held[2], held[3]).y, { steps: 3 });
|
||
await host.locator('.ap-pill.sum[data-s="ok"]').waitFor({ timeout: 2000 });
|
||
await host.screenshot({ path: join(SHOTS, 'apple-drag-pc.png') });
|
||
await host.mouse.up();
|
||
}
|
||
// The smallest phone (320 px wide): the turned board still fits the width.
|
||
await guest.setViewportSize({ width: 320, height: 640 });
|
||
await guest.waitForTimeout(300);
|
||
await guest.screenshot({ path: join(SHOTS, 'apple-mid-phone-320.png') });
|
||
const w320 = (await appleGrid(guest)).box;
|
||
if (w320.x < 0 || w320.x + w320.w > 320 || w320.w / 10 < 26) throw new Error(`320px board: ${JSON.stringify(w320)}`);
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'apple-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'apple-mid-phone-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
// Keep playing until the 1-minute clock runs out on the server.
|
||
const until = Date.now() + 75_000;
|
||
while (Date.now() < until && !(await host.getByRole('dialog', { name: '게임 결과' }).count())) {
|
||
await clear(guest, 'touch').catch(() => {});
|
||
await host.waitForTimeout(1500);
|
||
}
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 20_000 });
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'apple-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'apple-result-phone.png') });
|
||
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)}`);
|
||
},
|
||
},
|
||
appleUnlimited: {
|
||
// 2026-10-14: 무제한 — the stopwatch runs (tenths) and stops when I finish; 💡 힌트 shows a glowing box that adds up
|
||
// to 10 (button off while it shows), using it clears the box; the result shows 걸린 시간 and 힌트 N번.
|
||
game: 'apple',
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '제한 시간' }).getByRole('button', { name: '무제한', exact: true }).click();
|
||
await host.getByText(/제한 시간 무제한/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
for (const p of pages) await p.waitForFunction(() => !document.querySelector('.ap-over.count') && document.querySelector('svg.ap-board > g[transform]'), null, { timeout: 10_000 });
|
||
const watchText = () => host.locator('.ap-top .ap-pill').first().innerText();
|
||
const w1 = await watchText();
|
||
await host.waitForTimeout(1200);
|
||
const w2 = await watchText();
|
||
if (!/⏱\s*\d+:\d\d\.\d/.test(w2) || w1 === w2) throw new Error(`stopwatch not running: "${w1}" → "${w2}"`);
|
||
const hintBtn = host.getByRole('button', { name: /^💡 힌트/ });
|
||
await hintBtn.click();
|
||
const box = host.locator('svg.ap-board rect[data-hint]');
|
||
await box.waitFor({ timeout: 3000 });
|
||
if (await hintBtn.isEnabled()) throw new Error('hint button should be off while a hint shows');
|
||
if (await guest.locator('svg.ap-board rect[data-hint]').count()) throw new Error('the other player sees my hint');
|
||
await host.screenshot({ path: join(SHOTS, 'apple-hint-pc.png') });
|
||
const r = await box.evaluate((el) => ['x', 'y', 'width', 'height'].map((k) => Number(el.getAttribute(k))));
|
||
const rect: [number, number, number, number] = [Math.floor(r[1]! / 40), Math.floor(r[0]! / 40), Math.floor((r[1]! + r[3]!) / 40), Math.floor((r[0]! + r[2]!) / 40)];
|
||
const before = await appleScore(host);
|
||
await appleDrag(host, rect, false);
|
||
await host.waitForFunction((b) => Number(document.querySelector('.ap-top')?.textContent?.match(/🍎\s*(\d+)/)?.[1] ?? -1) > b, before, { timeout: 3000 });
|
||
await box.waitFor({ state: 'detached', timeout: 3000 });
|
||
await host.getByRole('button', { name: '💡 힌트 (1번 받음)' }).waitFor();
|
||
// 여기까지 (two presses): my stopwatch stops.
|
||
for (const p of pages) {
|
||
await p.getByRole('button', { name: /^여기까지 할래요/ }).click();
|
||
await p.getByRole('button', { name: '한 번 더 누르면 여기까지 해요' }).click();
|
||
await host.waitForTimeout(300);
|
||
}
|
||
for (const p of pages) await p.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'apple-unlimited-result-pc.png') });
|
||
const text = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||
if (!/사과 \d+개 · 걸린 시간 [\d분 .]+초 · 힌트 1번/.test(text)) throw new Error(`no time / hints in the result: ${text.replace(/\n/g, ' ')}`);
|
||
if (!/사과 0개 · 걸린 시간 [\d분 .]+초(?! · 힌트)/.test(text)) throw new Error(`guest line: ${text.replace(/\n/g, ' ')}`);
|
||
console.log(` apple 무제한: stopwatch ${w1} → ${w2}; result: ${text.replace(/\n/g, ' ').slice(0, 160)}`);
|
||
},
|
||
},
|
||
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: '무제한' }).click();
|
||
await host.getByText(/주사위 이동 · 차례 시간 무제한/).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'))))}`);
|
||
},
|
||
},
|
||
'magical-athlete': {
|
||
// PC host + phone guest: 2 players → 8 racers each (snake draft ×4), two racers per race. Real draft, secret picks,
|
||
// rolls and power choices through the UI until all four races are over (2nd and 4th on the wild track).
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st = { picks: 0, selects: 0, acts: 0, keyboard: false, second: 0 };
|
||
const shots = new Set<string>();
|
||
let power = false;
|
||
let wild = false;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
const until = Date.now() + 420_000;
|
||
while (Date.now() < until && !(await over())) {
|
||
if (!shots.has('draft') && (await host.locator('section[aria-label="선수 뽑기"]').count()) && st.picks >= 3) {
|
||
shots.add('draft');
|
||
await host.screenshot({ path: join(SHOTS, 'magical-athlete-draft-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-draft-phone.png'), fullPage: true });
|
||
}
|
||
if (!shots.has('select') && (await guest.locator('section[aria-label="출전 선수 고르기"] button.ma-card:not([disabled])').count())) {
|
||
shots.add('select');
|
||
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-select-phone.png'), fullPage: true });
|
||
}
|
||
let acted = false;
|
||
for (const [i, p] of pages.entries()) {
|
||
if (await magicalStep(p, i > 0, st)) {
|
||
acted = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!power && (await host.locator('.ma-log li.power').count())) power = true;
|
||
if (!wild && (await host.locator('.ma-side-tag.wild').count())) wild = true;
|
||
if (!shots.has('race') && st.acts >= 20 && (await host.locator('section[aria-label="경주로"]').count())) {
|
||
shots.add('race');
|
||
await host.screenshot({ path: join(SHOTS, 'magical-athlete-race-pc.png') });
|
||
await guest.evaluate(() => window.scrollTo(0, 0));
|
||
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-race-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-race-phone-full.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(250);
|
||
await host.screenshot({ path: join(SHOTS, 'magical-athlete-race-pc-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (wild && !shots.has('wild') && (await host.locator('section[aria-label="경주로"]').count())) {
|
||
shots.add('wild');
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'magical-athlete-wild-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-wild-phone.png') });
|
||
}
|
||
if (!acted) await host.waitForTimeout(150);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${JSON.stringify(st)})`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'magical-athlete-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'magical-athlete-result-phone.png') });
|
||
await host.keyboard.press('Escape');
|
||
await host.locator('section[aria-label="최종 결과"]').waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'magical-athlete-final-pc.png'), fullPage: true });
|
||
const rows = await host.locator('section[aria-label="경주 결과"] tbody tr').count();
|
||
if (rows !== 4) throw new Error(`expected 4 race results, saw ${rows}`);
|
||
if (!power) throw new Error('no racer power was logged');
|
||
if (!wild) throw new Error('never raced on the wild track');
|
||
if (st.picks !== 16 || st.selects < 6 || st.acts < 40 || !st.keyboard || st.second < 5) throw new Error(`too few real steps: ${JSON.stringify(st)}`);
|
||
console.log(` magical-athlete: ${st.picks} picks, ${st.selects} race picks, ${st.acts} turn choices (${st.second} second options), powers + wild track seen`);
|
||
},
|
||
},
|
||
'six-nimmt': {
|
||
// PC host + phone guest, two rounds by round count. Real secret picks (PC: card + [이 카드 내기]; phone: also a double
|
||
// tap), too-low cards take a row through the row buttons, until the game ends. Rules are covered by the engine tests.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '끝나는 조건' }).getByRole('button', { name: '라운드 수' }).click();
|
||
await host.getByRole('group', { name: '라운드 수' }).getByRole('button', { name: '2라운드' }).click();
|
||
await host.getByText('2라운드').first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st = { selects: 0, taps: 0, rows: 0, spots: 0, drafts: 0 };
|
||
const shots = new Set<string>();
|
||
let roundBox = false;
|
||
let revealSeen = false;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
const until = Date.now() + 300_000;
|
||
while (Date.now() < until && !(await over())) {
|
||
for (const [i, p] of pages.entries()) {
|
||
if (!shots.has(`choose${i}`) && (await p.locator('.sx-takebtn:not([disabled])').count())) {
|
||
shots.add(`choose${i}`);
|
||
await p.screenshot({ path: join(SHOTS, `six-nimmt-choose-${i ? 'phone' : 'pc'}.png`), fullPage: i > 0 });
|
||
}
|
||
}
|
||
let acted = false;
|
||
for (const [i, p] of pages.entries()) {
|
||
if (await sixStep(p, i > 0, st)) {
|
||
'hot-streak': {
|
||
// PC host + phone guest, one race (so it is also the last one: 두 배 티켓), cards every 1.2 s. Real draft (one risky
|
||
// face), secret cards (2 each with 2 players), a few cards flipped by the server clock, then both press 빨리 보기,
|
||
// payout table, final result. The put-in cards stay private.
|
||
players: 2,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '경주 수' }).getByRole('button', { name: '1번(맛보기)' }).click();
|
||
await host.getByRole('group', { name: '카드 넘기는 간격' }).getByRole('button', { name: '1.2초' }).click();
|
||
await host.getByText('경주 1번').first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st = { drafts: 0, risky: 0, doubles: 0, puts: 0, flips: 0, hurried: false, payout: false };
|
||
const shots = new Set<string>();
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
const shot = async (name: string) => {
|
||
if (shots.has(name)) return;
|
||
shots.add(name);
|
||
await host.screenshot({ path: join(SHOTS, `hot-streak-${name}-pc.png`) });
|
||
await guest.screenshot({ path: join(SHOTS, `hot-streak-${name}-phone.png`), fullPage: true });
|
||
await guest.setViewportSize({ width: 320, height: 720 });
|
||
await guest.waitForTimeout(300);
|
||
await guest.screenshot({ path: join(SHOTS, `hot-streak-${name}-phone320.png`), fullPage: true });
|
||
const wide = await guest.evaluate(() => document.documentElement.scrollWidth);
|
||
if (wide > 322) throw new Error(`hot-streak ${name}: page is ${wide}px wide at 320px`);
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
};
|
||
const tryClick = (l: Locator) => l.click({ timeout: 2000 }).then(() => true, () => false);
|
||
const until = Date.now() + 240_000;
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const p of pages) {
|
||
const stack = p.locator('section[aria-label="티켓 뽑기"] button.hs-stack:not([disabled])').first();
|
||
if (await stack.count()) {
|
||
if (st.drafts === 1) await shot('draft');
|
||
if (!(await stack.click({ timeout: 2000 }).then(() => true, () => false))) continue;
|
||
const risky = st.risky === 0;
|
||
if (!(await tryClick(p.getByRole('button', { name: risky ? /위험으로/ : /안전으로/ }).first()))) continue;
|
||
st.drafts++;
|
||
if (risky) st.risky++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
const dbl = p.locator('section[aria-label="두 배 티켓 고르기"] button.btn:not([disabled])').first();
|
||
// The panel goes away once the server answers: a click that finds nothing is just retried next round.
|
||
if ((await dbl.count()) && (await dbl.click({ timeout: 2000 }).then(() => true, () => false))) {
|
||
st.doubles++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
const cards = p.locator('section[aria-label="비밀 카드 넣기"] button.hs-hcard:not([disabled])');
|
||
if ((await cards.count()) && (await p.getByRole('button', { name: /몰래 넣기/ }).count())) {
|
||
await shot('submit');
|
||
if (!(await tryClick(cards.nth(0))) || !(await tryClick(cards.nth(1))) || !(await tryClick(p.getByRole('button', { name: /몰래 넣기/ })))) continue;
|
||
// The first one sees their own card while waiting; the last one starts the race at once.
|
||
if (st.puts === 0) await p.getByText('넣은 카드:').waitFor({ timeout: 5000 });
|
||
st.puts++;
|
||
acted = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!revealSeen && (await host.locator('.sx-reveal').count())) revealSeen = true;
|
||
if (!roundBox && (await host.locator('.sx-round').count())) {
|
||
roundBox = true;
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-round-pc.png') });
|
||
}
|
||
if (!shots.has('mid') && st.selects >= 7) {
|
||
shots.add('mid');
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'six-nimmt-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'six-nimmt-mid-phone-full.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'six-nimmt-mid-phone-dark.png'), fullPage: true });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!shots.has('narrow') && st.selects >= 12) {
|
||
shots.add('narrow');
|
||
await guest.setViewportSize({ width: 320, height: 700 });
|
||
await guest.waitForTimeout(300);
|
||
await guest.screenshot({ path: join(SHOTS, 'six-nimmt-320-phone.png'), fullPage: true });
|
||
const wide = await guest.evaluate(() => document.documentElement.scrollWidth);
|
||
if (wide > 322) throw new Error(`page is ${wide}px wide at 320px`);
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
const flips = await host.locator('.hs-flipped .hs-card').count();
|
||
st.flips = Math.max(st.flips, flips);
|
||
if (flips >= 3 && !shots.has('race')) {
|
||
await shot('race');
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(250);
|
||
await host.screenshot({ path: join(SHOTS, 'hot-streak-race-pc-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
// Secret cards: each sees only their own.
|
||
const mineH = await host.getByText('넣은 카드:').count();
|
||
const mineG = await guest.getByText('넣은 카드:').count();
|
||
if (mineH || mineG) throw new Error('put-in cards still shown during the race');
|
||
}
|
||
if (shots.has('race') && !st.hurried) {
|
||
for (const p of pages) await p.getByRole('button', { name: /빨리 보기/ }).click();
|
||
st.hurried = true;
|
||
}
|
||
const next = host.getByRole('button', { name: /최종 결과 보기|다음 경주로/ });
|
||
if (await next.count()) {
|
||
st.payout = true;
|
||
await host.waitForTimeout(300);
|
||
await shot('payout');
|
||
acted = await tryClick(next);
|
||
}
|
||
if (!acted) await host.waitForTimeout(150);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${JSON.stringify(st)})`);
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor();
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'six-nimmt-result-phone.png') });
|
||
await host.keyboard.press('Escape');
|
||
await host.locator('section[aria-label="최종 결과"]').waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-final-pc.png'), fullPage: true });
|
||
const cols = await host.locator('section[aria-label="최종 결과"] thead th').count();
|
||
if (cols !== 5) throw new Error(`expected 2 round columns in the final table, saw ${cols - 3}`);
|
||
if (st.selects < 38 || !st.taps || !revealSeen) throw new Error(`too few real steps: ${JSON.stringify(st)} reveal=${revealSeen}`);
|
||
console.log(` six-nimmt: ${st.selects} picks (${st.taps} double taps), ${st.rows} row choices, round box ${roundBox ? 'seen' : 'missed'}`);
|
||
},
|
||
},
|
||
'six-nimmt-pro': {
|
||
// Variant smoke test: the pro draft (2 players → 1~24 face up, ten picks each) and both-ends placement, one round.
|
||
game: 'six-nimmt',
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '카드 구성' }).getByRole('button', { name: '펼쳐 골라 가기' }).click();
|
||
await host.getByRole('group', { name: '줄에 붙이는 곳' }).getByRole('button', { name: '양쪽 끝' }).click();
|
||
await host.getByRole('group', { name: '끝나는 조건' }).getByRole('button', { name: '라운드 수' }).click();
|
||
await host.getByRole('group', { name: '라운드 수' }).getByRole('button', { name: '1라운드' }).click();
|
||
await host.getByText('펼쳐 골라 가기').first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st = { selects: 0, taps: 0, rows: 0, spots: 0, drafts: 0 };
|
||
let draftShot = false;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
const until = Date.now() + 240_000;
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const [i, p] of pages.entries()) {
|
||
if (await sixStep(p, i > 0, st)) {
|
||
acted = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!draftShot && st.drafts >= 5) {
|
||
draftShot = true;
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-pro-draft-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'six-nimmt-pro-draft-phone.png'), fullPage: true });
|
||
}
|
||
if (!acted) await host.waitForTimeout(150);
|
||
}
|
||
if (!(await over())) throw new Error(`game did not finish (${JSON.stringify(st)})`);
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'six-nimmt-pro-result-pc.png') });
|
||
if (st.drafts !== 20 || st.selects < 19) throw new Error(`too few real steps: ${JSON.stringify(st)}`);
|
||
console.log(` six-nimmt-pro: ${st.drafts} draft picks, ${st.selects} card picks, ${st.rows} row choices, ${st.spots} spot choices`);
|
||
gemblo: {
|
||
// PC 방장 + 휴대폰 친구(2명 → 2색씩, 4인 구역). PC 첫 수는 키보드(N으로 이음점의 놓는 방법 → Enter), 그다음은 마우스로
|
||
// 이음점 누르기 → [놓기]. 휴대폰은 블록 고르기 → 칸 누르기(안 되는 자리는 빨간 미리보기·이유, [놓기] 꺼짐) → 이음점을 두 번
|
||
// 눌러 다음 방법으로 바꾸기 → [놓기]. 16수 뒤 320px 화면·어두운 화면 확인, 휴대폰 쪽이 기권해 결과까지.
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '시간' }).getByRole('button', { name: '시간 제한 없음' }).click();
|
||
await host.getByText(/^시간 제한 없음/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const svg = (p: Page) => p.locator('svg.gm-board');
|
||
await svg(host).waitFor();
|
||
await svg(guest).waitFor();
|
||
const placed = async (p: Page) => Number(await svg(p).getAttribute('data-placements'));
|
||
const mine = async (p: Page) => (await svg(p).getAttribute('data-my-turn')) === '1';
|
||
const center = async (p: Page, sel: string) => {
|
||
const b = await p.locator(sel).first().boundingBox();
|
||
if (!b) throw new Error(`no box for ${sel}`);
|
||
return { x: b.x + b.width / 2, y: b.y + b.height / 2 };
|
||
};
|
||
const tapAt = async (p: Page, sel: string) => {
|
||
const { x, y } = await center(p, sel);
|
||
if (tag(p) === 'phone') await p.touchscreen.tap(x, y);
|
||
else await p.mouse.click(x, y);
|
||
};
|
||
const st = { keyboard: false, mouse: 0, phone: 0, refused: false, cycled: false };
|
||
let turns = 0;
|
||
for (let t = 0; t < 400 && turns < 16; t++) {
|
||
const p = (await mine(host)) ? host : (await mine(guest)) ? guest : null;
|
||
if (!p) {
|
||
await host.waitForTimeout(150);
|
||
continue;
|
||
}
|
||
const before = await placed(p);
|
||
if (p === host && !st.keyboard) {
|
||
await keys(host, ['n']);
|
||
await host.waitForFunction(() => document.querySelector('svg.gm-board')?.getAttribute('data-preview') === 'ok', null, { timeout: 5000 });
|
||
await host.screenshot({ path: join(SHOTS, 'gemblo-preview-pc.png') });
|
||
await host.keyboard.press('Enter');
|
||
st.keyboard = true;
|
||
} else if (p === host) {
|
||
if (st.mouse === 1) {
|
||
// A spot that doesn't work: red preview with the reason while hovering.
|
||
await host.locator('.gm-tray [data-piece]:not([disabled]):not([data-locked])').first().click();
|
||
// Over my own block: "다른 블록과 겹쳐요".
|
||
const { x, y } = await center(host, `[data-block][data-color="${await host.locator('[data-chip].turn, .gm-chip.turn').first().getAttribute('data-chip')}"] polygon`);
|
||
await host.mouse.move(x, y);
|
||
await host.waitForFunction(() => document.querySelector('svg.gm-board')?.getAttribute('data-preview') === 'bad', null, { timeout: 5000 });
|
||
await host.screenshot({ path: join(SHOTS, 'gemblo-refused-pc.png') });
|
||
await host.keyboard.press('Escape');
|
||
await svg(host).focus();
|
||
await host.keyboard.press('Escape');
|
||
await host.mouse.move(5, 5);
|
||
}
|
||
await tapAt(host, '[data-link]');
|
||
await host.waitForFunction(() => document.querySelector('svg.gm-board')?.getAttribute('data-preview') === 'ok', null, { timeout: 5000 });
|
||
await host.getByRole('button', { name: /^놓기 · / }).click();
|
||
st.mouse++;
|
||
} else {
|
||
if (!st.refused) {
|
||
// Pick a block, tap a cell next to my own colour (or anywhere that doesn't work): red preview, [놓기] off.
|
||
await guest.locator('.gm-tray [data-piece]:not([disabled])').first().tap();
|
||
const cells = await guest.locator('polygon[data-free]').evaluateAll((els) => els.map((e) => e.getAttribute('data-cell')!));
|
||
for (const c of cells.slice(0, 40)) {
|
||
const box = await guest.locator(`[data-cell="${c}"]`).boundingBox();
|
||
if (!box || box.y < 0) continue;
|
||
await guest.touchscreen.tap(box.x + box.width / 2, box.y + box.height / 2);
|
||
if ((await svg(guest).getAttribute('data-preview')) === 'bad') break;
|
||
}
|
||
if ((await svg(guest).getAttribute('data-preview')) !== 'bad') throw new Error('no refused preview on the phone');
|
||
if (await guest.getByRole('button', { name: /^놓기/ }).isEnabled()) throw new Error('[놓기] enabled for a refused spot');
|
||
await guest.waitForTimeout(300);
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-refused-phone.png') });
|
||
await guest.getByRole('button', { name: '취소' }).tap();
|
||
st.refused = true;
|
||
}
|
||
await tapAt(guest, '[data-link]');
|
||
await guest.waitForFunction(() => document.querySelector('svg.gm-board')?.getAttribute('data-preview') === 'ok', null, { timeout: 5000 });
|
||
const first = await svg(guest).locator('[data-preview-cells]').getAttribute('data-preview-cells');
|
||
await tapAt(guest, '[data-link]');
|
||
await guest.waitForTimeout(150);
|
||
const second = await svg(guest).locator('[data-preview-cells]').getAttribute('data-preview-cells');
|
||
if (first !== second) st.cycled = true;
|
||
if (st.phone === 0) await guest.screenshot({ path: join(SHOTS, 'gemblo-cycle-phone.png') });
|
||
await guest.getByRole('button', { name: /^놓기 · / }).tap();
|
||
st.phone++;
|
||
}
|
||
await p.waitForFunction((n) => Number(document.querySelector('svg.gm-board')?.getAttribute('data-placements')) > n, before, { timeout: 5000 });
|
||
turns++;
|
||
await host.waitForTimeout(120);
|
||
}
|
||
if (turns < 16) throw new Error(`only ${turns} turns (${JSON.stringify(st)})`);
|
||
if (!st.cycled) throw new Error('tapping the same link point twice never changed the placement');
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'gemblo-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-mid-phone-full.png'), fullPage: true });
|
||
await guest.setViewportSize({ width: 320, height: 640 });
|
||
await guest.waitForTimeout(400);
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-mid-phone-320.png'), fullPage: true });
|
||
const wide = await guest.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
if (wide) throw new Error('board screen overflows at 320px');
|
||
await host.emulateMedia({ colorScheme: 'dark' });
|
||
await guest.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'gemblo-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-mid-phone-320-dark.png') });
|
||
await host.emulateMedia({ colorScheme: 'light' });
|
||
await guest.emulateMedia({ colorScheme: 'light' });
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
// Zoom in and back (phone).
|
||
await guest.getByRole('button', { name: '내 블록 근처 확대' }).tap();
|
||
if (Number(await svg(guest).getAttribute('data-zoom')) <= 1) throw new Error('zoom did not change');
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-zoom-phone.png') });
|
||
await guest.getByRole('button', { name: '판 전체 보기' }).tap();
|
||
await guest.getByRole('button', { name: '🏳 기권' }).tap();
|
||
await guest.getByRole('button', { name: '기권하기' }).tap();
|
||
await host.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
await guest.getByRole('dialog', { name: '게임 결과' }).waitFor({ timeout: 10_000 });
|
||
await host.waitForTimeout(600);
|
||
await host.screenshot({ path: join(SHOTS, 'gemblo-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'gemblo-result-phone.png') });
|
||
const summary = await host.getByRole('dialog', { name: '게임 결과' }).innerText();
|
||
if (!/기권으로 .+ 승리/.test(summary)) throw new Error(`unexpected result: ${summary.slice(0, 120)}`);
|
||
await host.keyboard.press('Escape');
|
||
await host.locator('section[aria-label="남은 블록"]').waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'gemblo-final-pc.png'), fullPage: true });
|
||
console.log(` gemblo: ${turns} placements ${JSON.stringify(st)}, ${summary.split('\n').find((l) => l.includes('승리'))}`);
|
||
await host.waitForTimeout(500);
|
||
await host.screenshot({ path: join(SHOTS, 'hot-streak-result-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'hot-streak-result-phone.png') });
|
||
await host.keyboard.press('Escape');
|
||
await host.locator('section[aria-label="최종 결과"]').waitFor();
|
||
await host.screenshot({ path: join(SHOTS, 'hot-streak-final-pc.png'), fullPage: true });
|
||
if (st.drafts !== 6 || st.doubles !== 2 || st.puts !== 2 || st.flips < 3 || !st.hurried || !st.payout) throw new Error(`too few real steps: ${JSON.stringify(st)}`);
|
||
console.log(` hot-streak: ${st.drafts} tickets (${st.risky} risky), ${st.doubles} doubles, ${st.puts} secret puts, ${st.flips}+ cards flipped on the clock, 빨리 보기, payout`);
|
||
tichu: {
|
||
// PC host + 3 phone guests, 4인 팀전 to 300 points with 45-second turns: real grand / exchange / plays (card taps,
|
||
// suggestion chips, keyboard on PC) through the UI until round 1 is scored and round 2 is being played.
|
||
players: 4,
|
||
lobby: async (host) => {
|
||
await host.getByRole('group', { name: '목표 점수' }).getByRole('button', { name: '300', exact: true }).click();
|
||
await host.getByRole('group', { name: '한 턴 제한 시간' }).getByRole('button', { name: '45초' }).click();
|
||
await host.getByText(/300점/).first().waitFor();
|
||
},
|
||
drive: async (pages) => {
|
||
const [host, guest] = pages as [Page, Page];
|
||
const st: Record<string, number> = {};
|
||
let midShot = false;
|
||
let roundShot = false;
|
||
const until = Date.now() + 360_000;
|
||
const over = () => host.getByRole('dialog', { name: '게임 결과' }).count();
|
||
while (Date.now() < until && !(await over())) {
|
||
let acted = false;
|
||
for (const [i, p] of pages.entries()) {
|
||
if (await tichuStep(p, i === 0, st).catch(() => null)) {
|
||
acted = true;
|
||
await p.waitForTimeout(150);
|
||
break;
|
||
}
|
||
}
|
||
if (!midShot && (st.play ?? 0) >= 8 && (await host.locator('.tc-set').count())) {
|
||
midShot = true;
|
||
await host.waitForTimeout(400);
|
||
await host.screenshot({ path: join(SHOTS, 'tichu-mid-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'tichu-mid-phone.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'tichu-mid-phone-full.png'), fullPage: true });
|
||
await guest.setViewportSize({ width: 320, height: 720 });
|
||
await guest.waitForTimeout(300);
|
||
await guest.screenshot({ path: join(SHOTS, 'tichu-mid-phone-320.png'), fullPage: true });
|
||
const overflow = await guest.evaluate(() => document.documentElement.scrollWidth - window.innerWidth);
|
||
if (overflow > 1) throw new Error(`320px: page is ${overflow}px too wide`);
|
||
await guest.setViewportSize({ width: 390, height: 844 });
|
||
for (const p of [host, guest]) await p.emulateMedia({ colorScheme: 'dark' });
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'tichu-mid-pc-dark.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'tichu-mid-phone-dark.png') });
|
||
for (const p of [host, guest]) await p.emulateMedia({ colorScheme: 'light' });
|
||
}
|
||
if (!roundShot && (await host.getByRole('heading', { name: /라운드 결과/ }).count())) {
|
||
roundShot = true;
|
||
await host.waitForTimeout(300);
|
||
await host.screenshot({ path: join(SHOTS, 'tichu-round-pc.png') });
|
||
await guest.screenshot({ path: join(SHOTS, 'tichu-round-phone.png'), fullPage: true });
|
||
}
|
||
if (roundShot && (st.ready ?? 0) >= 4 && (st.exchange ?? 0) >= 8 && (await host.locator('.tc-hand-wrap').count())) break;
|
||
if (!acted) await host.waitForTimeout(150);
|
||
}
|
||
if (!roundShot && !(await over())) throw new Error(`round 1 did not finish (${JSON.stringify(st)})`);
|
||
if ((st.play ?? 0) < 10 || !st.exchange || !st.grand || !st.tapped || !st.keys) throw new Error(`too few real steps: ${JSON.stringify(st)}`);
|
||
await host.screenshot({ path: join(SHOTS, 'tichu-round2-pc.png') });
|
||
console.log(` tichu: ${JSON.stringify(Object.fromEntries(Object.entries(st).filter(([k]) => !k.includes('shot'))))}`);
|
||
},
|
||
},
|
||
};
|
||
|
||
const games = process.argv.slice(2).length ? process.argv.slice(2) : Object.keys(PLANS);
|
||
const app = startServer({
|
||
config: loadConfig({ PORT: String(PORT), DB_PATH: join(mkdtempSync(join(process.env.TMPDIR ?? '/tmp', 'bg-e2e-')), 'app.db'), PUBLIC_ORIGIN: ORIGIN }),
|
||
log: () => {},
|
||
staticDir: join(import.meta.dir, '../apps/web/dist'),
|
||
});
|
||
const browser = await chromium.launch({ executablePath: process.env.CHROME ?? '/usr/bin/google-chrome', headless: true });
|
||
let failed = false;
|
||
|
||
async function keys(page: Page, seq: string[]) {
|
||
await page.locator('[role="grid"]').first().focus();
|
||
for (const k of seq) await page.keyboard.press(k);
|
||
}
|
||
|
||
for (const id of games) {
|
||
const plan = PLANS[id];
|
||
if (!plan) {
|
||
console.log(`✗ ${id}: no plan`);
|
||
failed = true;
|
||
continue;
|
||
}
|
||
const errors: string[] = [];
|
||
const host = await (await browser.newContext({ viewport: { width: 1440, height: 900 }, locale: 'ko-KR' })).newPage();
|
||
const guests: Page[] = [];
|
||
for (let g = 1; g < (plan.players ?? 2); g++) {
|
||
guests.push(await (await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, locale: 'ko-KR' })).newPage());
|
||
}
|
||
const guest = guests[0]!;
|
||
for (const p of [host, ...guests]) p.on('pageerror', (e) => errors.push(`${id}: ${e.message}`));
|
||
// The first-game "30초 규칙 요약" cards are tested in e2e/tutorial.e2e.ts; mark them seen here.
|
||
for (const p of [host, ...guests]) await p.addInitScript((g) => localStorage.setItem(`bg:qs:${g}`, '1'), plan.game ?? id);
|
||
try {
|
||
await host.goto(`${ORIGIN}/g/${plan.game ?? id}`);
|
||
await host.getByRole('button', { name: /친구랑 하기/ }).click();
|
||
await host.getByLabel('내 이름(닉네임)').fill('방장');
|
||
await host.getByRole('button', { name: '이 이름으로 시작하기' }).click();
|
||
await host.waitForURL(/\/r\/\d{6}$/);
|
||
const code = host.url().slice(-6);
|
||
for (const [gi, g] of guests.entries()) {
|
||
const nick = gi === 0 ? '친구' : `친구${gi + 1}`;
|
||
await g.goto(`${ORIGIN}/r/${code}`);
|
||
await g.getByLabel('내 이름(닉네임)').fill(nick);
|
||
await g.getByRole('button', { name: '이 이름으로 입장하기' }).click();
|
||
await host.getByLabel('자리').getByText(nick, { exact: true }).waitFor();
|
||
}
|
||
if (plan.lobby) await plan.lobby(host);
|
||
await host.screenshot({ path: join(SHOTS, `${id}-0-lobby.png`) });
|
||
await host.getByRole('button', { name: '▶ 게임 시작' }).click();
|
||
await host.getByRole('button', { name: '시작하기' }).click();
|
||
if (plan.drive) {
|
||
await host.locator('.turn-status').waitFor();
|
||
await plan.drive([host, ...guests]);
|
||
} else {
|
||
await host.locator('[role="grid"]').first().waitFor();
|
||
await guest.locator('[role="grid"]').first().waitFor();
|
||
}
|
||
if (plan.setup) await plan.setup(host, guest);
|
||
const status = async (p: Page) => (await p.locator('.turn-status').innerText()).trim();
|
||
// Sides may be random: whoever shows "내 차례예요" plays the next sequence.
|
||
const myTurn = (p: Page) => p.evaluate(() => !!document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'));
|
||
for (const seq of plan.moves ?? []) {
|
||
let mover: Page | null = null;
|
||
for (let t = 0; t < 100 && !mover; t++) {
|
||
if (await myTurn(host)) mover = host;
|
||
else if (await myTurn(guest)) mover = guest;
|
||
else await host.waitForTimeout(100);
|
||
}
|
||
if (!mover) throw new Error('nobody has the turn');
|
||
await keys(mover, seq);
|
||
await mover.waitForFunction(() => !document.querySelector('.turn-status')?.textContent?.includes('내 차례예요'), null, { timeout: 5000 });
|
||
}
|
||
await host.screenshot({ path: join(SHOTS, `${id}-1-game-pc.png`) });
|
||
await guest.screenshot({ path: join(SHOTS, `${id}-2-game-phone.png`) });
|
||
if (errors.length) throw new Error(errors.join(' | '));
|
||
console.log(`✓ ${id} (host: ${await status(host)})`);
|
||
} catch (e) {
|
||
failed = true;
|
||
console.log(`✗ ${id}: ${(e as Error).message.split('\n')[0]}`);
|
||
await host.screenshot({ path: join(SHOTS, `${id}-fail-host.png`) }).catch(() => {});
|
||
await guest.screenshot({ path: join(SHOTS, `${id}-fail-guest.png`) }).catch(() => {});
|
||
}
|
||
}
|
||
await browser.close();
|
||
await app.stop();
|
||
console.log(failed ? 'E2E FAILED' : 'E2E PASSED');
|
||
process.exit(failed ? 1 : 0);
|