새 게임 티츄: 4인 2:2 팀전(원작, 1,000점) 기본 + 4인 개인전·3인(더미)·6인 3:3 변형, 그랜드/스몰 티츄, 끼어드는 폭탄, 참새 소원, 파티 모드

- 엔진 packages/games/src/tichu/: combo.ts(조합 판정·봉황 가장 센 해석·폭탄 비교·소원 의무·조합 찾기, 화면도 @bg/games/tichu/combo로 같이 씀), index.ts(그랜드 → 교환 → 플레이 → 용 주기 → 라운드 결과 상태 기계), bot.ts
- 옵션 전부: mode(team/individual/threechu/tientsin), targetScore, threechuHands, grandTichu, direction, bombTiming + bombWindowSeconds("카드 모으는 중" 폭탄 창, 폭탄 유무와 상관없이 같은 대기), wishRule(enforce/penalty), trickHistory(last/all), party(두 배·점수 뒤집기·손패 돌리기·평범, 연속 없음), turnSeconds, exchangeSeconds
- 비공개: 남의 손패·남은 6장·교환 전 더미. 카드 ID가 라운드마다 다시 쓰여 새 라운드에 지난 play 기록을 지움. 탑 무늬 ID는 b(p2 같은 플레이어 id와 겹침 방지)
- 컴퓨터: 손패 나누기 비용으로 가장 약한 조합부터, 짝꿍 트릭은 패스, 폭탄·용은 상대가 곧 나갈 때, 티츄/그랜드 판단, 교환(짝꿍 좋은 카드·상대 개와 약한 낱장), 패널티 모드에서도 소원 지킴, 레벨 1~60
- 화면 apps/web/src/games/tichu/: 52장은 PlayingCard(4색), 참새·개·봉황·용은 직접 그린 SVG. PC 십자 배치·휴대폰 칩 줄, 손패 7장×2줄(320px), 고른 카드 실시간 "풀하우스(9) · 낼 수 있어요", 추천 조합 칩, 소원 시트, 폭탄 목록, 교환 칸 3개(추천대로 채우기·다시 고르기), 용 주기, 라운드 결과 표, 점수판·라운드 기록·직전 트릭·나온 카드 표, 소리·흔들림·배너, 도움말·30초 요약
- 등록: GAMES·BOT_STRATEGIES·BOT_GAMES·CATALOG·GAME_UI·GAME_ICON·카드·패 탭, docs/games/README.md, result-score 테스트에 300점 옵션, e2e/games.e2e.ts(PC + 휴대폰 3대, 1라운드 끝 → 2라운드)
- 문서 docs/games/tichu.md에 구현 메모(정한 것) 추가
- 검증: tichu 64개, web games 224개, server 240개, bots·result-score 161개, 타입 검사·웹 빌드, E2E_PORT=4603 bun e2e/games.e2e.ts tichu 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-15 23:31:37 +09:00
parent 8620c82ca8
commit 4f69f19bf9
23 changed files with 5156 additions and 6 deletions

View File

@@ -1191,6 +1191,73 @@ async function magicalStep(p: Page, phone: boolean, st: { picks: number; selects
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> = {
blackjack: {
// PC host + phone guest. Each hand: bet the minimum, stand (decline insurance), then press 다음 판, until the
@@ -3190,6 +3257,64 @@ const PLANS: Record<string, Plan> = {
console.log(` magical-athlete: ${st.picks} picks, ${st.selects} race picks, ${st.acts} turn choices (${st.second} second options), powers + wild track seen`);
},
},
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);