Files
joke-app/packages/games/src/bang/cards.ts
EJClaw d6496dc1fa M6: 뱅 규칙·화면·테스트
- packages/games/src/bang: 뱅!(4~7명) 규칙 모듈. 카드 80장·캐릭터 16종 데이터, 거리/사거리,
  효과·반응 스택(뱅!/개틀링/인디언!/결투/잡화점/빈사/킷 칼슨/choose2), 다이너마이트·감옥 판정,
  처치 보상·보안관 벌칙·벌처 샘, 승리 판정, 역할·손패·덱 비공개 view, onTimeout/onLeave,
  legalActions·secretsOf. 하우스 룰 옵션 4종.
- 테스트 62개: 문서 §10 시나리오 전부, 시드 1,000개 4~7명 무작위 대국(카드 총수 보존, 생명 범위,
  정보 유출, onTimeout 합법, 결정성) + 엔진 randomPlayout 실행, 재생 결정성.
- apps/web/src/games/bang: 원형 테이블(생명 탄환·장착·거리·역할 배지), 꾹 눌러 보는 내 역할 카드,
  카드 선택 → 대상 강조 → 확인, 반응 시트와 타이머, 기록·카드 도감, PC/휴대폰, 라이트/다크.
- 등록: GAMES, 카탈로그(available), 웹 레지스트리, 아이콘(UPCOMING에서 '뱅' 제거).
- e2e: bang 플랜(PC 방장 + 휴대폰 3명, 반응 25초, 실제 턴 10번: 뱅!·기타 카드·반응·버리기).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:38:00 +09:00

168 lines
4.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 뱅! 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<Card, 'id'>;
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<CharacterId, number> = {
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<Record<CardKind, number>> = { 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<number, [number, number, number]> = { 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<Role>(dep).fill('deputy'), ...Array<Role>(out).fill('outlaw'), ...Array<Role>(ren).fill('renegade')];
}