Files
joke-app/apps/web/src/games/tichu/cards.tsx
EJClaw 4f69f19bf9 새 게임 티츄: 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>
2026-10-15 23:31:37 +09:00

133 lines
5.7 KiB
TypeScript

/**
* 티츄 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>
);
}