Files
joke-app/packages/games/src/bang/distance.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

44 lines
1.6 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.
/** Distance and range (docs/games/bang.md §5.1). */
import type { PlayerId } from '@bg/engine';
import { WEAPON_RANGE, kindOf, type CardKind } from './cards';
import type { BangState, PlayerState } from './types';
export const hasEquip = (p: PlayerState, kind: CardKind): boolean => p.inPlay.some((id) => kindOf(id) === kind);
export function weaponOf(p: PlayerState): CardKind | null {
for (const id of p.inPlay) {
const k = kindOf(id);
if (WEAPON_RANGE[k] !== undefined) return k;
}
return null;
}
/** Weapon range, or 1 for the default Colt .45. */
export function rangeOf(p: PlayerState): number {
const w = weaponOf(p);
return w ? WEAPON_RANGE[w]! : 1;
}
/** Seats between two living players, the shorter way round, counting living players only. */
export function seatDistance(s: BangState, a: PlayerId, b: PlayerId): number {
const alive = s.players.filter((p) => p.alive);
const ia = alive.findIndex((p) => p.id === a);
const ib = alive.findIndex((p) => p.id === b);
if (ia < 0 || ib < 0) return Infinity;
const d = Math.abs(ia - ib);
return Math.min(d, alive.length - d);
}
/** distance(A→B) = max(1, seats + B's mustang/Paul Regret − A's scope/Rose Doolan). */
export function distance(s: BangState, a: PlayerId, b: PlayerId): number {
if (a === b) return 0;
const pa = s.players.find((p) => p.id === a)!;
const pb = s.players.find((p) => p.id === b)!;
let d = seatDistance(s, a, b);
if (hasEquip(pb, 'mustang')) d += 1;
if (pb.character === 'paul' && !pb.characterOffer) d += 1;
if (hasEquip(pa, 'scope')) d -= 1;
if (pa.character === 'rose' && !pa.characterOffer) d -= 1;
return Math.max(1, d);
}