/** 뱅! cards, characters and roles (docs/games/bang.md §3, §4). */ export type Suit = 'S' | 'H' | 'D' | 'C'; export type Rank = 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 'J' | 'Q' | 'K' | 'A'; export type CardKind = | 'bang' | 'missed' | 'beer' | 'saloon' | 'stagecoach' | 'wellsFargo' | 'generalStore' | 'panic' | 'catBalou' | 'duel' | 'indians' | 'gatling' | 'barrel' | 'mustang' | 'scope' | 'jail' | 'dynamite' | 'volcanic' | 'schofield' | 'remington' | 'carabine' | 'winchester'; /** Card ids are strings "c0".."c79" (fixed per card) so hidden-info checks can look for them in views. */ export interface Card { id: string; kind: CardKind; suit: Suit; rank: Rank; } /** A card without its id (logs, draw! results, stolen-card notes). */ export type CardFace = Omit; export type Role = 'sheriff' | 'deputy' | 'outlaw' | 'renegade'; export type CharacterId = | 'bart' | 'blackJack' | 'calamity' | 'elGringo' | 'jesse' | 'jourdonnais' | 'kit' | 'lucky' | 'paul' | 'pedro' | 'rose' | 'sid' | 'slab' | 'suzy' | 'vulture' | 'willy'; export const CHARACTER_IDS: CharacterId[] = [ 'bart', 'blackJack', 'calamity', 'elGringo', 'jesse', 'jourdonnais', 'kit', 'lucky', 'paul', 'pedro', 'rose', 'sid', 'slab', 'suzy', 'vulture', 'willy', ]; export const CHARACTER_LIFE: Record = { bart: 4, blackJack: 4, calamity: 4, elGringo: 3, jesse: 4, jourdonnais: 4, kit: 4, lucky: 4, paul: 3, pedro: 4, rose: 4, sid: 4, slab: 4, suzy: 4, vulture: 4, willy: 4, }; /** §3.3 table: rank+suit per copy. */ const DECK_SPEC: [CardKind, string][] = [ ['bang', 'AS 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD AD 2C 3C 4C 5C 6C 7C 8C 9C QH KH AH'], ['missed', '10C JC QC KC AC 2S 3S 4S 5S 6S 7S 8S'], ['beer', '6H 7H 8H 9H 10H JH'], ['panic', 'JH QH AH 8D'], ['catBalou', 'KH 9D 10D JD'], ['duel', 'QD JS 8C'], ['generalStore', '9C QS'], ['indians', 'KD AD'], ['stagecoach', '9S 9S'], ['gatling', '10H'], ['saloon', '5H'], ['wellsFargo', '3H'], ['barrel', 'QS KS'], ['mustang', '8H 9H'], ['scope', 'AS'], ['jail', 'JS 10S 4H'], ['dynamite', '2H'], ['volcanic', '10S 10C'], ['schofield', 'JC QC KS'], ['remington', 'KC'], ['carabine', 'AC'], ['winchester', '8S'], ]; function parseRank(r: string): Rank { if (r === 'J' || r === 'Q' || r === 'K' || r === 'A') return r; return Number(r) as Rank; } /** The 80 cards in a fixed order; `CARDS[n].id === "c" + n`. */ export const CARDS: Card[] = (() => { const out: Card[] = []; for (const [kind, list] of DECK_SPEC) { for (const code of list.split(' ')) { out.push({ id: `c${out.length}`, kind, suit: code.slice(-1) as Suit, rank: parseRank(code.slice(0, -1)) }); } } return out; })(); const BY_ID = new Map(CARDS.map((c) => [c.id, c])); export function cardById(id: string): Card { const c = BY_ID.get(id); if (!c) throw new Error(`bang: unknown card ${id}`); return c; } export const isCardId = (id: string): boolean => BY_ID.has(id); export const kindOf = (id: string): CardKind => cardById(id).kind; export function faceOf(id: string): CardFace { const { id: _id, ...face } = cardById(id); return face; } export const BLUE_KINDS: CardKind[] = ['barrel', 'mustang', 'scope', 'jail', 'dynamite', 'volcanic', 'schofield', 'remington', 'carabine', 'winchester']; export const WEAPON_RANGE: Partial> = { volcanic: 1, schofield: 2, remington: 3, carabine: 4, winchester: 5 }; export const isBlue = (k: CardKind): boolean => BLUE_KINDS.includes(k); export const isWeapon = (k: CardKind): boolean => WEAPON_RANGE[k] !== undefined; /** Dynamite explodes on ♠2–♠9. */ export const explodes = (f: CardFace): boolean => f.suit === 'S' && typeof f.rank === 'number' && f.rank >= 2 && f.rank <= 9; export const isHeart = (f: CardFace): boolean => f.suit === 'H'; /** §4 role table. */ export function rolesFor(n: number, deputyCount7 = false): Role[] { const table: Record = { 4: [0, 2, 1], 5: [1, 2, 1], 6: [1, 3, 1], 7: deputyCount7 ? [1, 4, 1] : [2, 3, 1] }; const row = table[n]; if (!row) throw new Error(`bang: ${n} players not supported`); const [dep, out, ren] = row; return ['sheriff', ...Array(dep).fill('deputy'), ...Array(out).fill('outlaw'), ...Array(ren).fill('renegade')]; }