/** Card definitions shared by card games (docs/09 §5). */ // ---------------------------------------------------------------- standard 52 (+ jokers) export const SUITS = ['S', 'H', 'D', 'C'] as const; // ♠ ♥ ◆ ♣ export const RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'] as const; export type Suit = (typeof SUITS)[number]; export type Rank = (typeof RANKS)[number]; /** e.g. "AS" (ace of spades), "TD" (ten of diamonds), "X1"/"X2" jokers. */ export type CardId = string; export const SUIT_SYMBOL: Record = { S: '♠', H: '♥', D: '◆', C: '♣' }; export const SUIT_KO: Record = { S: '스페이드', H: '하트', D: '다이아', C: '클로버' }; export const RANK_LABEL: Record = { '2': '2', '3': '3', '4': '4', '5': '5', '6': '6', '7': '7', '8': '8', '9': '9', T: '10', J: 'J', Q: 'Q', K: 'K', A: 'A' }; export function standardDeck(jokers = 0): CardId[] { const deck: CardId[] = []; for (const s of SUITS) for (const r of RANKS) deck.push(`${r}${s}`); for (let j = 1; j <= jokers; j++) deck.push(`X${j}`); return deck; } export const isJoker = (c: CardId): boolean => c.startsWith('X'); export const rankOf = (c: CardId): Rank => c[0] as Rank; export const suitOf = (c: CardId): Suit => c[1] as Suit; /** 2..14 (ace high). */ export const rankValue = (c: CardId): number => RANKS.indexOf(rankOf(c)) + 2; export const cardLabel = (c: CardId): string => (isJoker(c) ? '조커' : `${SUIT_SYMBOL[suitOf(c)]}${RANK_LABEL[rankOf(c)]}`); // ---------------------------------------------------------------- hwatu 48 (+ bonus) export type HwatuKind = 'gwang' | 'yeol' | 'tti' | 'pi' | 'ssangpi' | 'bonus'; export type TtiKind = 'hong' | 'cheong' | 'cho' | 'plain'; export interface HwatuCard { id: number; /** 1..12, 0 for bonus cards. */ month: number; kind: HwatuKind; tti?: TtiKind; /** Special flags used by scoring: godori birds, 비광, 국진(9월 열끗) etc. */ tags: string[]; /** Korean display name, e.g. "1월 광(송학)". */ name: string; /** Junk value (피 1, 쌍피 2, bonus 2/3). */ piValue: number; } const MONTH_NAME = ['', '송학', '매조', '벚꽃', '흑싸리', '난초', '모란', '홍싸리', '공산', '국화', '단풍', '오동', '비']; /** id = (month-1)*4 + slot, matching docs/games/gostop.md §3.1. */ const TABLE: [HwatuKind, TtiKind | null, string[]][][] = [ /* 1 */ [['gwang', null, ['crane']], ['tti', 'hong', []], ['pi', null, []], ['pi', null, []]], /* 2 */ [['yeol', null, ['godori']], ['tti', 'hong', []], ['pi', null, []], ['pi', null, []]], /* 3 */ [['gwang', null, ['cherry']], ['tti', 'hong', []], ['pi', null, []], ['pi', null, []]], /* 4 */ [['yeol', null, ['godori']], ['tti', 'cho', []], ['pi', null, []], ['pi', null, []]], /* 5 */ [['yeol', null, []], ['tti', 'cho', []], ['pi', null, []], ['pi', null, []]], /* 6 */ [['yeol', null, []], ['tti', 'cheong', []], ['pi', null, []], ['pi', null, []]], /* 7 */ [['yeol', null, []], ['tti', 'cho', []], ['pi', null, []], ['pi', null, []]], /* 8 */ [['gwang', null, ['moon']], ['yeol', null, ['godori']], ['pi', null, []], ['pi', null, []]], /* 9 */ [['yeol', null, ['gukjin']], ['tti', 'cheong', []], ['pi', null, []], ['pi', null, []]], /* 10 */ [['yeol', null, []], ['tti', 'cheong', []], ['pi', null, []], ['pi', null, []]], /* 11 */ [['gwang', null, ['phoenix']], ['ssangpi', null, []], ['pi', null, []], ['pi', null, []]], /* 12 */ [['gwang', null, ['rain']], ['yeol', null, ['swallow']], ['tti', 'plain', []], ['ssangpi', null, []]], ]; const KIND_KO: Record = { gwang: '광', yeol: '열끗', tti: '띠', pi: '피', ssangpi: '쌍피', bonus: '보너스' }; const TTI_KO: Record = { hong: '홍단', cheong: '청단', cho: '초단', plain: '띠' }; export const HWATU: HwatuCard[] = TABLE.flatMap((cards, m) => cards.map(([kind, tti, tags], slot) => { const month = m + 1; const id = m * 4 + slot; const label = kind === 'tti' ? TTI_KO[tti!] : month === 12 && kind === 'gwang' ? '비광' : KIND_KO[kind]; return { id, month, kind, ...(tti ? { tti } : {}), tags, name: `${month}월 ${label}(${MONTH_NAME[month]})`, piValue: kind === 'pi' ? 1 : kind === 'ssangpi' ? 2 : 0, }; }), ); /** Bonus cards: ids 48.. (2피 cards, then a 3피 card last). */ export function hwatuBonus(count: number): HwatuCard[] { return Array.from({ length: count }, (_, i) => { const three = i === count - 1 && count >= 3; return { id: 48 + i, month: 0, kind: 'bonus' as const, tags: [], name: three ? '보너스 3피' : '보너스 2피', piValue: three ? 3 : 2 }; }); } export const hwatu = (id: number): HwatuCard => { const c = HWATU[id]; if (c) return c; if (id >= 48) return hwatuBonus(id - 47).at(-1)!; throw new Error(`unknown hwatu id ${id}`); }; /** 섯다 20장: each month 1–10, its special card (slot 0) and the next card (slot 1) — docs/games/seotda.md §3. */ export const SEOTDA_DECK: number[] = Array.from({ length: 10 }, (_, m) => [m * 4, m * 4 + 1]).flat();