새 게임 티츄: 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

@@ -9,7 +9,7 @@ import { assertCleanText, eachView, seatIds, usersOf } from './help-kit.test-uti
const IDS = Object.keys(GAME_UI);
test('모든 게임에 도움말이 있어요', () => {
expect(IDS).toHaveLength(34);
expect(IDS).toHaveLength(35);
for (const id of IDS) {
const src = readFileSync(join(import.meta.dir, id, 'index.tsx'), 'utf8');
expect(src, id).toMatch(/\bquickStart,/);

View File

@@ -36,6 +36,7 @@ export const GAME_UI: Record<string, () => Promise<{ default: GameUI }>> = {
liar: () => import('./liar'),
'magical-athlete': () => import('./magical-athlete'),
blackjack: () => import('./blackjack'),
tichu: () => import('./tichu'),
};
const cache = new Map<string, GameUI>();

View File

@@ -0,0 +1,132 @@
/**
* 티츄 card art (docs/games/tichu.md §3, §12): the 52 number cards reuse the shared PlayingCard (4-colour suits:
* 옥 green ♣ · 칼 black ♠ · 탑 blue ◆ · 별 red ♥ — the names are the original's, the shapes are the site's), the four
* special cards are our own simple SVG drawings. Size comes from the parent (`--cw` CSS variable, see `.tc-c`).
*/
import type { CSSProperties } from 'react';
import { PlayingCard } from '../../components/cards/PlayingCard';
import { cardName } from '@bg/games/tichu/combo';
const SUIT_MAP: Record<string, string> = { j: 'C', s: 'S', b: 'D', t: 'H' };
const RANK_MAP: Record<number, string> = { 10: 'T', 11: 'J', 12: 'Q', 13: 'K', 14: 'A' };
/** PlayingCard id ("TD", "AS") of a number card. */
export const stdId = (id: string): string => {
const r = Number(id.slice(1));
return `${RANK_MAP[r] ?? String(r)}${SUIT_MAP[id[0]!] ?? 'S'}`;
};
const SPECIAL: Record<string, { name: string; corner: string; bg: string; ink: string }> = {
MJ: { name: '참새', corner: '1', bg: '#fef9c3', ink: '#a16207' },
DOG: { name: '개', corner: '개', bg: '#f5f5f4', ink: '#57534e' },
PH: { name: '봉황', corner: '봉', bg: '#ffedd5', ink: '#c2410c' },
DR: { name: '용', corner: '용', bg: '#dcfce7', ink: '#15803d' },
};
function SpecialPicture({ id, ink }: { id: string; ink: string }) {
switch (id) {
case 'MJ':
// A small round sparrow.
return (
<g>
<ellipse cx="54" cy="82" rx="24" ry="19" fill={ink} opacity="0.85" />
<circle cx="72" cy="64" r="12" fill={ink} />
<path d="M83 63 L95 66 L83 69 Z" fill="#f59e0b" />
<circle cx="75" cy="61" r="2.5" fill="#fff" />
<path d="M34 78 L18 70 L30 88 Z" fill={ink} opacity="0.7" />
<path d="M50 100 L46 112 M60 100 L62 112" stroke={ink} strokeWidth="3" strokeLinecap="round" />
</g>
);
case 'DOG':
// A friendly dog face.
return (
<g>
<ellipse cx="50" cy="80" rx="24" ry="22" fill="#a8a29e" />
<ellipse cx="30" cy="66" rx="9" ry="17" fill={ink} transform="rotate(20 30 66)" />
<ellipse cx="70" cy="66" rx="9" ry="17" fill={ink} transform="rotate(-20 70 66)" />
<circle cx="42" cy="76" r="3.5" fill="#1c1917" />
<circle cx="58" cy="76" r="3.5" fill="#1c1917" />
<ellipse cx="50" cy="88" rx="6" ry="4.5" fill="#1c1917" />
<path d="M44 95 Q50 100 56 95" stroke="#1c1917" strokeWidth="2.5" fill="none" strokeLinecap="round" />
</g>
);
case 'PH':
// A bird of flame: three feathers and a crest.
return (
<g>
<path d="M50 112 C30 100 24 78 34 60 C38 74 44 80 50 82 C56 80 62 74 66 60 C76 78 70 100 50 112 Z" fill="#f97316" />
<path d="M50 104 C40 96 38 84 42 74 C46 82 50 86 50 86 C50 86 54 82 58 74 C62 84 60 96 50 104 Z" fill="#fde047" />
<circle cx="50" cy="56" r="9" fill={ink} />
<path d="M50 47 C46 38 52 32 56 30 C54 36 58 40 54 47 Z" fill="#ef4444" />
<path d="M58 56 L66 58 L58 60 Z" fill="#fbbf24" />
</g>
);
default:
// A winding dragon with a pearl.
return (
<g>
<path d="M22 108 C22 86 46 92 46 74 C46 58 24 62 28 46 C32 36 46 36 54 42" stroke={ink} strokeWidth="11" fill="none" strokeLinecap="round" />
<path d="M22 108 C22 86 46 92 46 74 C46 58 24 62 28 46 C32 36 46 36 54 42" stroke="#fbbf24" strokeWidth="3" strokeDasharray="4 6" fill="none" />
<circle cx="60" cy="44" r="10" fill={ink} />
<circle cx="63" cy="41" r="2.5" fill="#fff" />
<path d="M66 36 L76 28 M60 34 L64 24" stroke={ink} strokeWidth="3" strokeLinecap="round" />
<circle cx="76" cy="84" r="9" fill="#fbbf24" stroke="#d97706" strokeWidth="2" />
</g>
);
}
}
export function SpecialCard({ id }: { id: string }) {
const s = SPECIAL[id]!;
return (
<span className="tc-sp" aria-hidden style={{ display: 'inline-flex' }}>
<svg viewBox="0 0 100 140" width={64} height={90} aria-hidden>
<rect x="1" y="1" width="98" height="138" rx="9" fill={s.bg} stroke={s.ink} strokeWidth="3" />
<SpecialPicture id={id} ink={s.ink} />
<text x="9" y="31" fontSize={s.corner.length > 1 ? 22 : 30} fontWeight="800" fill={s.ink} fontFamily="Pretendard Variable, sans-serif">
{s.corner}
</text>
<text x="50" y="132" fontSize="17" fontWeight="800" fill={s.ink} textAnchor="middle" fontFamily="Pretendard Variable, sans-serif">
{s.name}
</text>
</svg>
</span>
);
}
/** One card face (or back with `id` null). Sized by the surrounding `.tc-c` box. */
export function CardFace({ id }: { id: string | null }) {
if (id && SPECIAL[id]) return <SpecialCard id={id} />;
return <PlayingCard card={id ? stdId(id) : null} size="md" fourColor />;
}
export interface TCardProps {
id: string;
selected?: boolean;
dimmed?: boolean;
highlight?: boolean;
badge?: string;
onClick?: () => void;
label?: string;
style?: CSSProperties;
}
/** A tappable (or still) card of the 티츄 deck. */
export function TCard({ id, selected, dimmed, highlight, badge, onClick, label, style }: TCardProps) {
const cls = `tc-c${selected ? ' sel' : ''}${dimmed ? ' dim' : ''}${highlight ? ' hi' : ''}`;
const aria = label ?? cardName(id);
if (onClick) {
return (
<button type="button" className={cls} onClick={onClick} aria-pressed={!!selected} aria-label={aria} data-card={id} style={style}>
<CardFace id={id} />
{badge && <span className="tc-badge-on">{badge}</span>}
</button>
);
}
return (
<span className={cls} role="img" aria-label={aria} data-card={id} style={style}>
<CardFace id={id} />
{badge && <span className="tc-badge-on">{badge}</span>}
</span>
);
}

View File

@@ -0,0 +1,21 @@
import { expect, test } from 'bun:test';
import { GAMES } from '@bg/games';
import { applyAction, setupGame, usersOf } from '../help-kit.test-util';
import { helpNow } from './help';
const ids = ['A', 'B', 'C', 'D'];
const users = usersOf(ids);
const view = (s: unknown, who: string | null) => GAMES.tichu!.view(s, who) as any;
test('티츄: 그랜드 → 교환 → 첫 트릭', () => {
let { state: s } = setupGame('tichu', 4);
expect(helpNow(view(s, 'A'), 'A', users)).toContain('그랜드 티츄');
expect(helpNow(view(s, null), null, users)).toContain('준비 중');
for (const p of ids) s = applyAction('tichu', s, p, { type: 'grand', call: false });
expect(helpNow(view(s, 'A'), 'A', users)).toContain('[보내기]');
for (const p of ids) s = applyAction('tichu', s, p, { type: 'exchange', give: view(s, p).my.exchangeSuggest });
const lead = s.seats[s.current].owner as string;
expect(helpNow(view(s, lead), lead, users)).toContain('새 트릭을 시작해요');
const other = ids.find((p) => p !== lead)!;
expect(helpNow(view(s, other), other, users)).toContain('기다려 주세요');
});

View File

@@ -0,0 +1,81 @@
/** 티츄 [?] "지금 할 수 있는 것" (docs/07 §5). Pure: only reads the client view. */
import type { TichuView } from '@bg/games/tichu';
import type { PublicUser } from '@bg/shared/lite';
const RANK: Record<number, string> = { 11: 'J', 12: 'Q', 13: 'K', 14: 'A' };
const rk = (r: number) => RANK[r] ?? String(r);
const subj = (n: string) => (n === '나' ? '내가' : `${n}이`);
export function helpNow(v: TichuView, me: string | null, players: Record<string, PublicUser>): string {
const name = (seat: number) => {
const s = v.seats[seat];
if (!s) return '다른 사람';
const n = players[s.owner]?.nickname ?? '다른 사람';
return s.dummy ? `더미(${n}님)` : s.owner === me ? '나' : `${n}님`;
};
const goal = '마주 앉은 짝꿍과 한 팀이에요. 앞 조합보다 센 같은 모양·같은 장수를 내며 손패를 먼저 털고, 점수 카드(5·10·K·용)를 모아요.';
const my = v.my;
if (v.phase === 'finished') return `게임이 끝났어요. ${v.result?.summary ?? ''}`.trim() + '\n결과 창에서 [한 판 더]를 누르면 다시 할 수 있어요.';
if (v.phase === 'grand') {
if (!my) return `${v.round}라운드 준비 중이에요. 모두 첫 카드를 보고 그랜드 티츄를 할지 고르고 있어요.\n${goal}`;
if (my.grandPending) {
const lines = ['첫 카드만 보고 그랜드 티츄를 할지 골라요. 이번 라운드에 내가 1등으로 나가면 +200, 못 하면 −200이에요.'];
lines.push(my.canGrand ? '자신 없으면 [안 함]을 눌러요. 그다음 나머지 카드를 받아요.' : '딜러는 그랜드 티츄를 할 수 없어요. [안 함]을 눌러요.');
return lines.join('\n');
}
return '골랐어요. 다른 사람이 고르기를 기다리는 중이에요. 모두 고르면 나머지 카드를 받아요.';
}
if (v.phase === 'exchange') {
if (!my) return '모두 카드를 한 장씩 건넬 사람을 고르고 있어요. 다 고르면 한꺼번에 옮겨져요.';
const lines: string[] = [];
if (my.exchangeSent === null || (v.dummy && v.dummy.exchangeSent === null)) {
const who = my.exchangeTargets.map((t) => t.label).join('·');
lines.push(`${who}에게 카드를 한 장씩 줘요. 카드를 누르고 칸을 누르거나 [추천대로 채우기]를 누른 뒤 [보내기]를 눌러요.`);
lines.push('짝꿍에게는 좋은 카드, 상대에게는 약한 카드를 주는 게 보통이에요.');
} else lines.push('보냈어요. 모두 보내기 전에는 [다시 고르기]로 바꿀 수 있어요.');
if (my.canTichu) lines.push('손패가 좋으면 [티츄!]로 1등에 걸 수 있어요(+100 / −100). 첫 카드를 내기 전까지 언제든 돼요.');
return lines.join('\n');
}
if (v.phase === 'roundEnd') {
const r = v.lastRound;
const head = r ? `${r.round}라운드가 끝났어요. 이번 라운드 A팀 ${r.total[0]}점, B팀 ${r.total[1]}점이에요.` : '라운드가 끝났어요.';
return `${head}\n${me && v.ready && !v.ready[me] ? '[다음 라운드]를 누르면 새 카드를 받아요.' : '다른 사람이 준비하기를 기다리는 중이에요.'}`;
}
if (v.phase === 'dragonGift') {
const mine = (my?.dragonTargets.length ?? 0) > 0 || (v.dummy?.dragonTargets.length ?? 0) > 0;
if (mine) return '용으로 트릭을 이겼어요! 용 트릭은 상대 팀 한 명에게 줘야 해요. 버튼 중 하나를 눌러요(보통 카드가 많은 상대에게 줘요).';
return `${subj(v.dragonBy !== null ? name(v.dragonBy) : '다른 사람')} 용으로 트릭을 이겨서, 그 트릭을 줄 상대를 고르고 있어요.`;
}
// playing
const top = v.trick?.plays[v.trick.plays.length - 1] ?? null;
const wish = v.wish !== null ? `\n참새 소원(${rk(v.wish)})이 걸려 있어요. 그 숫자를 가진 사람은 낼 수 있으면 꼭 넣어서 내야 해요.` : '';
if (v.trick?.closingAt) {
const can = my?.canNoBomb || v.dummy?.canNoBomb;
return `모두 패스해서 카드를 모으는 중이에요. 이때도 폭탄을 낼 수 있어요.${can ? '\n폭탄이 없으면 [폭탄 없음]을 눌러요. 누르지 않아도 곧 모아요.' : ''}`;
}
const ctl = [my, v.dummy].find((h) => h && h.canPlay) ?? null;
if (ctl) {
const lines: string[] = [];
if (ctl.leading) lines.push(`내 차례예요${ctl.dummy ? '(더미 손패)' : ''}. 새 트릭을 시작해요. 아무 조합이나 낼 수 있어요(패스는 안 돼요).`);
else lines.push(`내 차례예요${ctl.dummy ? '(더미 손패)' : ''}. 바닥 맨 위는 ${top!.label}. 같은 모양·같은 장수로 더 센 조합을 내거나 [패스]를 눌러요.`);
lines.push('카드를 눌러 고르면 위에 조합 이름과 낼 수 있는지가 나와요. [추천] 칩을 누르면 한 번에 골라져요.');
if (ctl.mustWish !== null) lines.push(`소원 카드(${rk(ctl.mustWish)})를 넣어서 낼 수 있으니 꼭 넣어야 해요.`);
if (ctl.canTichu) lines.push('아직 카드를 안 냈으니 [티츄!]로 1등에 걸 수 있어요.');
if (ctl.bombs.length) lines.push('[💣 폭탄]으로 무엇이든 이길 수 있어요.');
return lines.join('\n') + (ctl.mustWish === null ? wish : '');
}
const cur = v.current !== null ? name(v.current) : '다른 사람';
const table = top ? `바닥 맨 위: ${top.label}.` : `${subj(cur)} 새 트릭을 시작해요.`;
if (!my) return `${cur} 차례예요. ${table}\n${goal}${wish}`;
const seat = v.mySeat !== null ? v.seats[v.mySeat] : null;
if (seat?.place) return `${seat.place}등으로 손패를 다 털었어요! 짝꿍과 남은 사람을 지켜봐요.`;
const lines = [`${cur} 차례예요. 기다려 주세요. ${table}`];
if (my.canBombNow) lines.push('폭탄이 있어서 차례가 아니어도 [💣 폭탄]으로 끼어들 수 있어요.');
if (my.canTichu) lines.push('아직 카드를 안 냈으니 [티츄!]를 누를 수 있어요.');
return lines.join('\n') + wish;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
/** 티츄 30초 규칙 요약 (docs/07 §5). */
import type { QuickCard } from '../types';
function Card({ x, y, label, color = '#111827', bg = '#fffef9' }: { x: number; y: number; label: string; color?: string; bg?: string }) {
return (
<g transform={`translate(${x} ${y})`}>
<rect width={34} height={48} rx={5} fill={bg} stroke="#9ca3af" strokeWidth={1.5} />
<text x={17} y={31} textAnchor="middle" fontSize={label.length > 1 ? 13 : 18} fontWeight={900} fill={color}>
{label}
</text>
</g>
);
}
export const quickStart: QuickCard[] = [
{
pic: (
<svg viewBox="0 0 250 130" width={250} height={130} aria-hidden>
<circle cx={125} cy={65} r={34} fill="#15803d" />
<text x={125} y={18} textAnchor="middle" fontSize={14} fontWeight={800} fill="#2563eb">짝꿍</text>
<text x={125} y={124} textAnchor="middle" fontSize={14} fontWeight={800} fill="#2563eb">나</text>
<text x={40} y={70} textAnchor="middle" fontSize={14} fontWeight={800} fill="#dc2626">상대</text>
<text x={210} y={70} textAnchor="middle" fontSize={14} fontWeight={800} fill="#dc2626">상대</text>
<path d="M125 28 V102" stroke="#2563eb" strokeWidth={3} strokeDasharray="5 4" />
</svg>
),
alt: '네 사람이 둘러앉고 마주 앉은 나와 짝꿍이 한 팀',
title: '마주 앉은 짝꿍과 한 팀',
text: '4명이 2:2로 해요. 손패를 먼저 털고 트릭에서 5·10·K·용 점수 카드를 모아 목표 점수에 먼저 닿는 팀이 이겨요.',
},
{
pic: (
<svg viewBox="0 0 250 120" width={250} height={120} aria-hidden>
<Card x={10} y={20} label="8" />
<Card x={30} y={20} label="8" color="#dc2626" />
<text x={100} y={52} fontSize={26} fontWeight={900} fill="#374151">→</text>
<Card x={140} y={20} label="J" color="#2563eb" />
<Card x={160} y={20} label="J" color="#15803d" />
<text x={45} y={100} textAnchor="middle" fontSize={13} fontWeight={800} fill="#374151">8 페어</text>
<text x={175} y={100} textAnchor="middle" fontSize={13} fontWeight={800} fill="#15803d">더 센 페어</text>
</svg>
),
alt: '8 페어 위에 J 페어를 내는 모습',
title: '같은 모양으로 더 세게',
text: '싱글·페어·트리플·풀하우스·스트레이트·연속 페어 중 앞과 같은 모양·같은 장수로 더 센 것을 내거나 패스해요. 폭탄은 언제든 이겨요.',
},
{
pic: (
<svg viewBox="0 0 250 120" width={250} height={120} aria-hidden>
<Card x={12} y={14} label="참새" color="#a16207" bg="#fef9c3" />
<Card x={72} y={14} label="개" color="#57534e" bg="#f5f5f4" />
<Card x={132} y={14} label="봉황" color="#c2410c" bg="#ffedd5" />
<Card x={192} y={14} label="용" color="#15803d" bg="#dcfce7" />
<text x={125} y={92} textAnchor="middle" fontSize={15} fontWeight={900} fill="#dc2626">티츄! = 1등에 +100</text>
</svg>
),
alt: '특수 카드 참새, 개, 봉황, 용과 티츄 선언',
title: '특수 카드와 티츄!',
text: '참새는 소원을 부르고, 개는 선을 짝꿍에게, 봉황은 아무 숫자, 용은 가장 센 싱글이에요. 첫 카드 전 [티츄!]로 1등에 걸 수 있어요.',
},
];

View File

@@ -33,6 +33,7 @@ export const GAME_ICON: Record<string, string> = {
liar: '🤥',
'magical-athlete': '🏃',
blackjack: '🂡',
tichu: '🐉',
};
/** Shown on the home screen so users know what's coming (docs/12-roadmap.md). */
@@ -41,6 +42,6 @@ export const UPCOMING: string[] = [];
/** Tabs on the game picker (docs/07 §3.3). Games not listed here only show under 전체. */
export const GAME_GROUPS: { key: string; label: string; ids: string[] }[] = [
{ key: 'board', label: '판·주사위', ids: ['omok', 'connect-four', 'othello', 'chess', 'janggi', 'baduk', 'quoridor', 'yut', 'marble', 'yacht', 'las-vegas', 'magical-athlete', 'clue'] },
{ key: 'cards', label: '카드·패', ids: ['seotda', 'poker', 'blackjack', 'one-card', 'uno', 'gostop', 'dalmuti', 'splendor', 'cockroach-poker', 'ninety-nine', 'old-maid', 'mahjong', 'rummikub', 'davinci-code'] },
{ key: 'cards', label: '카드·패', ids: ['seotda', 'poker', 'blackjack', 'one-card', 'uno', 'gostop', 'dalmuti', 'splendor', 'cockroach-poker', 'ninety-nine', 'old-maid', 'mahjong', 'rummikub', 'davinci-code', 'tichu'] },
{ key: 'party', label: '여럿이 파티', ids: ['bang', 'halli-galli', 'dobble', 'catchmind', 'mafia', 'liar', 'apple'] },
];