Merge branch 'wip/game-tichu' into codex/owner/grp_discord_joke-app
# 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 # e2e/games.e2e.ts # packages/games/package.json # packages/games/src/bots/index.ts # packages/games/src/index.ts # packages/shared/src/bots.ts # packages/shared/src/catalog.ts
This commit is contained in:
121
e2e/games.e2e.ts
121
e2e/games.e2e.ts
@@ -1234,6 +1234,71 @@ async function sixStep(p: Page, phone: boolean, st: { selects: number; taps: num
|
||||
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> = {
|
||||
@@ -3561,6 +3626,62 @@ const PLANS: Record<string, Plan> = {
|
||||
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'))))}`);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user