카드 게임 시간 무제한(우노·뱅!·달무티·고스톱·도둑잡기·포커·바퀴벌레 포커·99), 공통 카드 움직임(card-fx), 우노·달무티·도둑잡기·포커 소리·애니메이션
- 무제한(null): 차례 시계·타임아웃 없음, 자리 비움만 짧은 시계, 연결 끊김은 방 유예 뒤 자동 행동 그대로 - 포커는 리바이 고르는 시간도 무제한 가능, 고스톱은 고·스톱 선택 시간도 무제한 가능, 뱅!은 반응 시간·캐릭터 고르기도 - card-fx: 날아가는 카드·칩(ghost), 제자리 날아오기, 배너, view 변화 감지 훅(처음 렌더·다시 보기는 건너뜀) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1053,7 +1053,7 @@ describe('시간 초과·자리 비움·나가기 (§8.5)', () => {
|
||||
const c = pool();
|
||||
const g = c('gatling');
|
||||
let s = rig({ players: basic({ A: { hand: [g] }, B: { life: 1, hand: [c('beer')] } }) });
|
||||
const before = s.turn.deadline;
|
||||
const before = s.turn.deadline!;
|
||||
s = play(s, 'A', g);
|
||||
const paused = clock;
|
||||
s = act(s, 'B', { type: 'takeHit' });
|
||||
@@ -1083,7 +1083,7 @@ describe('시간 초과·자리 비움·나가기 (§8.5)', () => {
|
||||
// Next time it is A's turn the limit is 5 s.
|
||||
for (const p of ['B', 'C', 'D']) x = act(x, p, { type: 'timeout' });
|
||||
expect(x.turn.player).toBe('A');
|
||||
expect(x.turn.deadline - clock).toBe(5000);
|
||||
expect(x.turn.deadline! - clock).toBe(5000);
|
||||
x = act(x, 'A', { type: 'endPlay' });
|
||||
expect(pl(x, 'A').away).toBe(false);
|
||||
});
|
||||
@@ -1111,6 +1111,73 @@ describe('시간 초과·자리 비움·나가기 (§8.5)', () => {
|
||||
expect(s.reactions.map((r) => (r.kind === 'indians' ? r.target : ''))).toEqual(['B', 'D']);
|
||||
});
|
||||
|
||||
test('무제한 (turnSeconds·reactionSeconds null): 시계 없음, 연결이 끊긴 사람은 여전히 자동 처리, 자리 비움은 5초', () => {
|
||||
const shape = (bang.optionsSchema as unknown as { shape: Record<string, { meta(): { labels?: Record<string, string> } | undefined }> }).shape;
|
||||
expect(shape.turnSeconds!.meta()?.labels?.null).toBe('무제한');
|
||||
expect(shape.reactionSeconds!.meta()?.labels?.null).toBe('무제한');
|
||||
expect(bang.optionsSchema.safeParse({ turnSeconds: null, reactionSeconds: null }).success).toBe(true);
|
||||
expect(bang.defaultOptions).toMatchObject({ turnSeconds: 60, reactionSeconds: 15 });
|
||||
const options = { turnSeconds: null, reactionSeconds: null };
|
||||
const c = pool();
|
||||
const ind = c('indians');
|
||||
const bg = c('bang');
|
||||
let s = rig({ players: basic({ A: { hand: [ind, bg, c('mustang'), c('scope'), c('barrel'), c('jail'), c('volcanic'), c('beer'), c('beer')] }, C: { hand: [c('bang')] } }), options });
|
||||
s.turn.deadline = null;
|
||||
expect(bang.deadline!(s)).toBeNull();
|
||||
expect(bang.timeoutPlayers!(s)).toEqual(['A']);
|
||||
expect(bang.view(s, 'A')).toMatchObject({ turnDeadline: null, deadlineTotalMs: 5000, reactionTotalMs: 5000 });
|
||||
// 인디언: every reaction is unclocked, so every responder is listed (the room's disconnect grace times each one out).
|
||||
s = play(s, 'A', ind);
|
||||
expect(s.reactions.map((r) => r.deadline)).toEqual([null, null, null]);
|
||||
expect(bang.deadline!(s)).toBeNull();
|
||||
expect(bang.timeoutPlayers!(s).sort()).toEqual(['B', 'C', 'D']);
|
||||
expect(bang.view(s, 'B').reactions.every((r) => r.deadline === null)).toBe(true);
|
||||
expect(JSON.parse(JSON.stringify(s))).toEqual(s);
|
||||
s = act(s, 'C', { type: 'timeout' });
|
||||
expect(s.log.some((e) => e.t === 'respond' && e.p === 'C' && e.why === 'indians')).toBe(true);
|
||||
s = act(s, 'B', { type: 'timeout' });
|
||||
expect(pl(s, 'B').life).toBe(pl(s, 'B').maxLife - 1);
|
||||
s = act(s, 'D', { type: 'takeHit' });
|
||||
// The turn clock stays off after the reactions (pause arithmetic skips null).
|
||||
expect(s.reactions).toEqual([]);
|
||||
expect(s.turn).toMatchObject({ deadline: null, pausedAt: null });
|
||||
// 뱅! at an away player: only that reaction has a clock (5 s), so only they are timed.
|
||||
pl(s, 'B').away = true;
|
||||
s = play(s, 'A', bg, { target: 'B' });
|
||||
expect(s.reactions[0]!.deadline).toBe(clock + 5000);
|
||||
expect(bang.deadline!(s)).toBe(clock + 5000);
|
||||
expect(bang.timeoutPlayers!(s)).toEqual(['B']);
|
||||
s = act(s, 'B', { type: 'timeout' });
|
||||
// Hand over the limit → discard phase, still unclocked; a timeout discards at random.
|
||||
s = act(s, 'A', { type: 'endPlay' });
|
||||
expect(s.turn).toMatchObject({ phase: 'discard', deadline: null });
|
||||
s = act(s, 'A', { type: 'timeout' });
|
||||
expect(s.turn.player).toBe('B');
|
||||
// B is away → the short clock on its own turn; C (not away) gets no clock.
|
||||
expect(s.turn.deadline! - clock).toBe(5000);
|
||||
expect(bang.deadline!(s)).toBe(s.turn.deadline);
|
||||
s = act(s, 'B', { type: 'timeout' });
|
||||
expect(s.turn.player).toBe('C');
|
||||
expect(s.turn.deadline).toBeNull();
|
||||
});
|
||||
|
||||
test('무제한: choose2 캐릭터 고르기도 시계 없음, 시간 초과(연결 끊김) 시 첫 번째 카드', () => {
|
||||
const players = ['A', 'B', 'C', 'D'];
|
||||
let s = bang.setup({ players, options: bang.optionsSchema.parse({ characterDraft: 'choose2', turnSeconds: null }), rng: SeededRng.fromSeed(seedN(5)), now: 0 });
|
||||
expect(s.reactions.every((r) => r.kind === 'choose2' && r.deadline === null)).toBe(true);
|
||||
expect(bang.deadline!(s)).toBeNull();
|
||||
expect(bang.timeoutPlayers!(s).sort()).toEqual(players);
|
||||
const offer = pl(s, 'B').characterOffer!;
|
||||
s = act(s, 'B', { type: 'timeout' });
|
||||
expect(pl(s, 'B').character).toBe(offer[0]!);
|
||||
for (const p of ['A', 'C', 'D']) s = act(s, p, { type: 'timeout' });
|
||||
expect(s.turn.phase).not.toBe('draft');
|
||||
expect(s.turn.deadline).toBeNull();
|
||||
// Timed draft keeps its 30 s clock.
|
||||
const t = bang.setup({ players, options: bang.optionsSchema.parse({ characterDraft: 'choose2' }), rng: SeededRng.fromSeed(seedN(5)), now: 0 });
|
||||
expect(bang.deadline!(t)).toBe(30_000);
|
||||
});
|
||||
|
||||
test('onTimeout은 모든 상태에서 합법 행동', () => {
|
||||
for (let seed = 1; seed <= 40; seed++) {
|
||||
const players = ['A', 'B', 'C', 'D', 'E'];
|
||||
@@ -1261,6 +1328,7 @@ const PRESETS: Partial<BangOptions>[] = [
|
||||
{ autoDefend: false, drawBeforeDeath: true },
|
||||
{ beerAtFullHealth: true, selfTargetCatBalou: true, deputyCount7: true },
|
||||
{ characterDraft: 'choose2', autoBarrel: false, autoDefend: false, reactionSeconds: 8 },
|
||||
{ characterDraft: 'choose2', turnSeconds: null, reactionSeconds: null },
|
||||
];
|
||||
|
||||
const SEEDS = playoutSeeds(1000);
|
||||
@@ -1297,6 +1365,7 @@ describe(`무작위 대국 (시드 ${SEEDS}개, 4~7명)`, () => {
|
||||
[5, { characterDraft: 'choose2' }],
|
||||
[6, { autoBarrel: false }],
|
||||
[7, { drawBeforeDeath: true }],
|
||||
[5, { turnSeconds: null, reactionSeconds: null, characterDraft: 'choose2' }],
|
||||
] as const)('randomPlayout with the engine per-step leak / round-trip checks: %i players', (n, opts) => {
|
||||
const players = Array.from({ length: n }, (_, k) => `P${k}`);
|
||||
const options = bang.optionsSchema.parse(opts);
|
||||
|
||||
@@ -71,12 +71,15 @@ export function clockwiseFrom(s: BangState, from: PlayerId): PlayerId[] {
|
||||
return out;
|
||||
}
|
||||
|
||||
export function reactionMs(s: BangState, p: PlayerState): number {
|
||||
return p.away ? AWAY_MS : s.options.reactionSeconds * 1000;
|
||||
/** Clock lengths in ms; null = 무제한 (an away player still gets the short clock). */
|
||||
export function reactionMs(s: BangState, p: PlayerState): number | null {
|
||||
return p.away ? AWAY_MS : s.options.reactionSeconds === null ? null : s.options.reactionSeconds * 1000;
|
||||
}
|
||||
export function turnMs(s: BangState, p: PlayerState): number {
|
||||
return p.away ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
export function turnMs(s: BangState, p: PlayerState): number | null {
|
||||
return p.away ? AWAY_MS : s.options.turnSeconds === null ? null : s.options.turnSeconds * 1000;
|
||||
}
|
||||
/** Absolute deadline `ms` from now; null stays null (never Infinity — state is JSON). */
|
||||
export const after = (ctx: Ctx, ms: number | null): number | null => (ms === null ? null : ctx.now + ms);
|
||||
|
||||
/** Cards kept inside reactions (general store, Kit Carlson) — counted for conservation. */
|
||||
export function limboCards(s: BangState): string[] {
|
||||
@@ -211,7 +214,7 @@ export function maxRecovery(s: BangState, p: PlayerState): number {
|
||||
|
||||
function openDying(s: BangState, ctx: Ctx, t: PlayerState, killer: PlayerId | null, lost: number): void {
|
||||
if (maxRecovery(s, t) >= 1 - t.life) {
|
||||
s.reactions.push({ kind: 'dying', player: t.id, killer, lost, source: killer, deadline: ctx.now + reactionMs(s, t) });
|
||||
s.reactions.push({ kind: 'dying', player: t.id, killer, lost, source: killer, deadline: after(ctx, reactionMs(s, t)) });
|
||||
} else {
|
||||
eliminate(s, ctx, t.id, killer);
|
||||
}
|
||||
@@ -351,7 +354,7 @@ function finish(s: BangState, ctx: Ctx, team: Team): void {
|
||||
export function startTurn(s: BangState, ctx: Ctx, id: PlayerId): void {
|
||||
const p = P(s, id);
|
||||
if (p.role === 'sheriff') s.round += 1;
|
||||
s.turn = { player: id, phase: 'start', bangsPlayed: 0, deadline: ctx.now + turnMs(s, p), pausedAt: null, dynamiteChecked: false, jailChecked: false };
|
||||
s.turn = { player: id, phase: 'start', bangsPlayed: 0, deadline: after(ctx, turnMs(s, p)), pausedAt: null, dynamiteChecked: false, jailChecked: false };
|
||||
log(s, ctx, { t: 'turn', p: id, round: s.round });
|
||||
}
|
||||
|
||||
@@ -428,7 +431,7 @@ export function doDraw(s: BangState, ctx: Ctx, a: { jesseFrom?: PlayerId; pedroD
|
||||
p.hand.push(...options);
|
||||
if (options.length) log(s, ctx, { t: 'draw', p: p.id, n: options.length, why: 'kit' });
|
||||
} else {
|
||||
s.reactions.push({ kind: 'kitKeep', player: p.id, options, deadline: ctx.now + reactionMs(s, p) });
|
||||
s.reactions.push({ kind: 'kitKeep', player: p.id, options, deadline: after(ctx, reactionMs(s, p)) });
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -471,7 +474,7 @@ export function settle(s: BangState, ctx: Ctx): void {
|
||||
return;
|
||||
}
|
||||
if (s.turn.pausedAt !== null) {
|
||||
s.turn.deadline += ctx.now - s.turn.pausedAt;
|
||||
if (s.turn.deadline !== null) s.turn.deadline += ctx.now - s.turn.pausedAt;
|
||||
s.turn.pausedAt = null;
|
||||
}
|
||||
const p = P(s, s.turn.player);
|
||||
@@ -514,7 +517,7 @@ function openBang(s: BangState, ctx: Ctx, source: PlayerId, target: PlayerId, vi
|
||||
needed: via === 'bang' && is(P(s, source), 'slab') ? 2 : 1,
|
||||
barrelTried: false,
|
||||
jourTried: false,
|
||||
deadline: ctx.now + reactionMs(s, t),
|
||||
deadline: after(ctx, reactionMs(s, t)),
|
||||
};
|
||||
if (s.options.autoBarrel) {
|
||||
while (r.needed > 0 && tryBarrel(s, ctx, r));
|
||||
@@ -582,7 +585,7 @@ export function storeAdvance(s: BangState, ctx: Ctx, r: Extract<Reaction, { kind
|
||||
continue;
|
||||
}
|
||||
r.picker = next;
|
||||
r.deadline = ctx.now + reactionMs(s, p);
|
||||
r.deadline = after(ctx, reactionMs(s, p));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -661,13 +664,13 @@ export function playCard(s: BangState, ctx: Ctx, actor: PlayerId, a: PlayAction)
|
||||
}
|
||||
case 'duel': {
|
||||
const t = P(s, a.target!);
|
||||
s.reactions.push({ kind: 'duel', actor: t.id, other: actor, source: actor, deadline: ctx.now + reactionMs(s, t) });
|
||||
s.reactions.push({ kind: 'duel', actor: t.id, other: actor, source: actor, deadline: after(ctx, reactionMs(s, t)) });
|
||||
break;
|
||||
}
|
||||
case 'indians':
|
||||
for (const id of clockwiseFrom(s, actor)) {
|
||||
if (id === actor) continue;
|
||||
s.reactions.push({ kind: 'indians', target: id, source: actor, deadline: ctx.now + reactionMs(s, P(s, id)) });
|
||||
s.reactions.push({ kind: 'indians', target: id, source: actor, deadline: after(ctx, reactionMs(s, P(s, id))) });
|
||||
}
|
||||
break;
|
||||
case 'gatling':
|
||||
@@ -700,7 +703,7 @@ export function respond(s: BangState, ctx: Ctx, actor: PlayerId, cardIds: string
|
||||
const next = r.other;
|
||||
r.other = r.actor;
|
||||
r.actor = next;
|
||||
r.deadline = ctx.now + reactionMs(s, P(s, next));
|
||||
r.deadline = after(ctx, reactionMs(s, P(s, next)));
|
||||
break;
|
||||
}
|
||||
case 'dying':
|
||||
@@ -793,7 +796,7 @@ export function endPlay(s: BangState, ctx: Ctx, actor: PlayerId): void {
|
||||
const p = P(s, actor);
|
||||
if (p.hand.length > p.life) {
|
||||
s.turn.phase = 'discard';
|
||||
s.turn.deadline = Math.max(s.turn.deadline, ctx.now + DISCARD_MIN_MS);
|
||||
if (s.turn.deadline !== null) s.turn.deadline = Math.max(s.turn.deadline, ctx.now + DISCARD_MIN_MS);
|
||||
} else s.turn.phase = 'ended';
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { CARDS, CHARACTER_IDS, CHARACTER_LIFE, cardById, kindOf, rolesFor } from
|
||||
import { distance, rangeOf } from './distance';
|
||||
import {
|
||||
AWAY_AFTER,
|
||||
AWAY_MS,
|
||||
P,
|
||||
autoSave,
|
||||
discardDown,
|
||||
@@ -71,17 +72,24 @@ export function allCards(s: BangState): string[] {
|
||||
return [...s.deck, ...s.discard, ...s.players.flatMap((p) => [...p.hand, ...p.inPlay]), ...limboCards(s)];
|
||||
}
|
||||
|
||||
/** Earliest clock; reactions with no clock (무제한) are skipped, null when nothing is timed. */
|
||||
function deadlineOf(s: BangState): number | null {
|
||||
if (s.winner) return null;
|
||||
if (s.reactions.length) return Math.min(...s.reactions.map((r) => r.deadline));
|
||||
if (s.reactions.length) {
|
||||
const ds = s.reactions.flatMap((r) => (r.deadline === null ? [] : [r.deadline]));
|
||||
return ds.length ? Math.min(...ds) : null;
|
||||
}
|
||||
return s.turn.deadline;
|
||||
}
|
||||
|
||||
/** Responders whose own deadline is the earliest (a later reaction must not be cut short). */
|
||||
/**
|
||||
* Responders whose own deadline is the earliest (a later reaction must not be cut short).
|
||||
* When no reaction has a clock (무제한), every responder is listed so the room's disconnect grace can still time each one out.
|
||||
*/
|
||||
function timed(s: BangState): PlayerId[] {
|
||||
if (s.winner) return [];
|
||||
if (!s.reactions.length) return [s.turn.player];
|
||||
const d = deadlineOf(s)!;
|
||||
const d = deadlineOf(s);
|
||||
return [...new Set(s.reactions.filter((r) => r.deadline === d).map(responder))];
|
||||
}
|
||||
|
||||
@@ -178,7 +186,8 @@ export const bang: Def = {
|
||||
deck: rng.shuffle(CARDS.map((c) => c.id)),
|
||||
discard: [],
|
||||
turn: { player: ps.find((p) => p.role === 'sheriff')!.id, phase: 'draft', bangsPlayed: 0, deadline: now, pausedAt: null, dynamiteChecked: false, jailChecked: false },
|
||||
reactions: draft ? ps.map((p) => ({ kind: 'choose2' as const, player: p.id, deadline: now + 30_000 })) : [],
|
||||
// The draft pick has its own 30 s clock, none when the turn clock is 무제한.
|
||||
reactions: draft ? ps.map((p) => ({ kind: 'choose2' as const, player: p.id, deadline: options.turnSeconds === null ? null : now + 30_000 })) : [],
|
||||
lastCheck: null,
|
||||
winner: null,
|
||||
deathOrder: [],
|
||||
@@ -318,8 +327,9 @@ export const bang: Def = {
|
||||
}
|
||||
: null,
|
||||
turnDeadline: s.turn.deadline,
|
||||
deadlineTotalMs: s.options.turnSeconds * 1000,
|
||||
reactionTotalMs: s.options.reactionSeconds * 1000,
|
||||
// 무제한: only an away player's short clock can run, so the ring is sized for it.
|
||||
deadlineTotalMs: s.options.turnSeconds === null ? AWAY_MS : s.options.turnSeconds * 1000,
|
||||
reactionTotalMs: s.options.reactionSeconds === null ? AWAY_MS : s.options.reactionSeconds * 1000,
|
||||
log: s.log.slice(-LOG_VIEW).map((e) => stripPrivate(e, me, over)),
|
||||
winner: s.winner,
|
||||
result: s.final,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
||||
import type { PlayerId } from '@bg/engine';
|
||||
import { CHARACTER_IDS, type Card, type CardFace, type CardKind, type CharacterId, type Role } from './cards';
|
||||
|
||||
const lit = <T extends number>(...vals: T[]) =>
|
||||
const lit = <T extends number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
export const bangOptionsSchema = z.object({
|
||||
@@ -11,12 +11,14 @@ export const bangOptionsSchema = z.object({
|
||||
.enum(['random', 'choose2'])
|
||||
.default('random')
|
||||
.meta({ title: '캐릭터 정하기', labels: { random: '무작위 1장', choose2: '2장 중 1장 고르기' } }),
|
||||
turnSeconds: lit(30, 60, 90, 120)
|
||||
/** null = 무제한 (also for the choose2 draft pick). A dropped connection still gets auto moves after the room's grace time. */
|
||||
turnSeconds: lit(30, 60, 90, 120, null)
|
||||
.default(60)
|
||||
.meta({ title: '내 턴 제한 시간', labels: { 30: '30초', 60: '60초', 90: '90초', 120: '120초' } }),
|
||||
reactionSeconds: lit(8, 15, 25)
|
||||
.meta({ title: '내 턴 제한 시간', labels: { 30: '30초', 60: '60초', 90: '90초', 120: '120초', null: '무제한' } }),
|
||||
/** null = 무제한 (away players still get the short clock). */
|
||||
reactionSeconds: lit(8, 15, 25, null)
|
||||
.default(15)
|
||||
.meta({ title: '반응 제한 시간(빗나감!·맥주·결투·잡화점)', labels: { 8: '8초', 15: '15초', 25: '25초' } }),
|
||||
.meta({ title: '반응 제한 시간(빗나감!·맥주·결투·잡화점)', labels: { 8: '8초', 15: '15초', 25: '25초', null: '무제한' } }),
|
||||
autoDefend: z.boolean().default(true).meta({ title: '반응 시간이 지나면 막을 카드를 자동으로 내기' }),
|
||||
autoBarrel: z.boolean().default(true).meta({ title: '술통·주르도네 판정을 묻지 않고 자동으로 하기' }),
|
||||
showDistanceHelper: z.boolean().default(true).meta({ title: '다른 사람까지 거리와 사거리 표시' }),
|
||||
@@ -70,15 +72,16 @@ export interface PlayerState {
|
||||
away: boolean;
|
||||
}
|
||||
|
||||
/** `deadline: null` = 무제한 (no clock; only the room's disconnect grace applies). Never Infinity (state is JSON). */
|
||||
export type Reaction =
|
||||
| { kind: 'bang'; target: PlayerId; source: PlayerId; via: 'bang' | 'gatling'; needed: number; barrelTried: boolean; jourTried: boolean; deadline: number }
|
||||
| { kind: 'indians'; target: PlayerId; source: PlayerId; deadline: number }
|
||||
| { kind: 'duel'; actor: PlayerId; other: PlayerId; source: PlayerId; deadline: number }
|
||||
| { kind: 'store'; picker: PlayerId; order: PlayerId[]; revealed: string[]; source: PlayerId; deadline: number }
|
||||
| { kind: 'bang'; target: PlayerId; source: PlayerId; via: 'bang' | 'gatling'; needed: number; barrelTried: boolean; jourTried: boolean; deadline: number | null }
|
||||
| { kind: 'indians'; target: PlayerId; source: PlayerId; deadline: number | null }
|
||||
| { kind: 'duel'; actor: PlayerId; other: PlayerId; source: PlayerId; deadline: number | null }
|
||||
| { kind: 'store'; picker: PlayerId; order: PlayerId[]; revealed: string[]; source: PlayerId; deadline: number | null }
|
||||
/** `lost` / `source`: the life loss that caused it (Bart / El Gringo trigger after surviving, §5.5). */
|
||||
| { kind: 'dying'; player: PlayerId; killer: PlayerId | null; lost: number; source: PlayerId | null; deadline: number }
|
||||
| { kind: 'kitKeep'; player: PlayerId; options: string[]; deadline: number }
|
||||
| { kind: 'choose2'; player: PlayerId; deadline: number };
|
||||
| { kind: 'dying'; player: PlayerId; killer: PlayerId | null; lost: number; source: PlayerId | null; deadline: number | null }
|
||||
| { kind: 'kitKeep'; player: PlayerId; options: string[]; deadline: number | null }
|
||||
| { kind: 'choose2'; player: PlayerId; deadline: number | null };
|
||||
export type ReactionKind = Reaction['kind'];
|
||||
|
||||
export type TurnPhase = 'draft' | 'start' | 'draw' | 'play' | 'discard' | 'ended';
|
||||
@@ -87,7 +90,8 @@ export interface TurnState {
|
||||
player: PlayerId;
|
||||
phase: TurnPhase;
|
||||
bangsPlayed: number;
|
||||
deadline: number;
|
||||
/** null = 무제한. */
|
||||
deadline: number | null;
|
||||
/** Turn timer is paused while reactions run during the play phase. */
|
||||
pausedAt: number | null;
|
||||
dynamiteChecked: boolean;
|
||||
@@ -217,7 +221,7 @@ export interface ReactionView {
|
||||
via?: 'bang' | 'gatling';
|
||||
needed?: number;
|
||||
revealed?: Card[];
|
||||
deadline: number;
|
||||
deadline: number | null;
|
||||
}
|
||||
|
||||
export interface BangView {
|
||||
@@ -246,7 +250,9 @@ export interface BangView {
|
||||
canSidHeal: boolean;
|
||||
prompt: Prompt | null;
|
||||
} | null;
|
||||
turnDeadline: number;
|
||||
/** null = 무제한 (no clock shown). */
|
||||
turnDeadline: number | null;
|
||||
/** Full clock lengths for the timer ring (the short away clock when the option is 무제한). */
|
||||
deadlineTotalMs: number;
|
||||
reactionTotalMs: number;
|
||||
log: LogEntry[];
|
||||
|
||||
@@ -389,6 +389,23 @@ describe('시간 초과 (§8.5)', () => {
|
||||
expect(game.deadline!(back)! - back.turnStartedAt).toBe(30_000);
|
||||
});
|
||||
|
||||
test('무제한 (turnSeconds null): 마감 없음, 그래도 시간 초과(연결 끊김)는 대신 두고 자리 비움이면 5초', () => {
|
||||
expect(game.optionsSchema.safeParse({ turnSeconds: null }).success).toBe(true);
|
||||
const t0 = rigged({ A: ['rat', 'fly'], B: ['bat'], C: ['toad'] }, { turnSeconds: null });
|
||||
expect(game.deadline!(t0)).toBeNull();
|
||||
expect(game.view(t0, 'A').turnMs).toBe(0);
|
||||
const third = actE({ ...t0, timeoutsInRow: { A: 2, B: 0, C: 0 } }, 'A', { type: 'timeout' });
|
||||
expect(third.events.map((e) => e.type)).toEqual(['timeout', 'away', 'offer']);
|
||||
// B (not away) now holds the card: still no clock.
|
||||
expect(game.deadline!(third.state)).toBeNull();
|
||||
const w = { ...t0, away: { A: true, B: false, C: false } };
|
||||
expect(game.deadline!(w)! - w.turnStartedAt).toBe(5000);
|
||||
expect(game.view(w, 'A').turnMs).toBe(5000);
|
||||
const back = act(w, 'A', { type: 'offer', cardId: 'rat-0', to: 'B', claim: 'rat' });
|
||||
expect(back.away.A).toBe(false);
|
||||
expect(game.deadline!(back)).toBeNull();
|
||||
});
|
||||
|
||||
test('모두 무응답이어도 게임이 끝남; 매 상태에서 onTimeout이 합법', () => {
|
||||
for (let seed = 1; seed <= 40; seed++) {
|
||||
const n = 2 + (seed % 5);
|
||||
@@ -538,7 +555,7 @@ function cfg(i: number): { players: string[]; options: CockroachOptions } {
|
||||
claimHistory: i % 3 !== 0,
|
||||
eightKindsRule: i % 7 === 0,
|
||||
twoPlayerPass: i % 2 === 0,
|
||||
turnSeconds: ([15, 30, 60] as const)[i % 3],
|
||||
turnSeconds: ([15, 30, 60, null] as const)[i % 4],
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,10 +45,11 @@ export const cockroachOptionsSchema = z.object({
|
||||
.union([z.literal('auto'), z.literal(3), z.literal(4), z.literal(5)])
|
||||
.default('auto')
|
||||
.meta({ title: '같은 벌레가 몇 장 모이면 패배', labels: { auto: '자동(2명 5장, 3~6명 4장)', 3: '3장(짧은 게임)', 4: '4장', 5: '5장' } }),
|
||||
/** null = 무제한 (no clock; a dropped connection still gets an auto move after the room's grace time). */
|
||||
turnSeconds: z
|
||||
.union([z.literal(15), z.literal(30), z.literal(60)])
|
||||
.union([z.literal(15), z.literal(30), z.literal(60), z.literal(null)])
|
||||
.default(30)
|
||||
.meta({ title: '건네기·판정 제한 시간', labels: { 15: '15초', 30: '30초', 60: '60초' } }),
|
||||
.meta({ title: '건네기·판정 제한 시간', labels: { 15: '15초', 30: '30초', 60: '60초', null: '무제한' } }),
|
||||
claimHistory: z.boolean().default(true).meta({ title: '이번 라운드 주장 기록 보이기' }),
|
||||
quickChat: z.boolean().default(true).meta({ title: '빠른 말 버튼("정말이야!", "의심스러운데?")' }),
|
||||
eightKindsRule: z.boolean().default(false).meta({ title: '앞마당에 8종을 모두 모아도 패배(하우스 룰)' }),
|
||||
@@ -200,6 +201,7 @@ export interface CockroachView {
|
||||
said: Said[];
|
||||
removedCount: number;
|
||||
turnStartedAt: number;
|
||||
/** Clock length in ms; 0 = 무제한 (no clock). */
|
||||
turnMs: number;
|
||||
seq: number;
|
||||
final: CockroachFinal | null;
|
||||
@@ -266,9 +268,11 @@ function peekBlock(s: CockroachState): string | null {
|
||||
return passTargets(s, r.holder!).length === 0 ? '모두 이 카드를 이미 봐서 넘길 사람이 없어요. 진짜인지 거짓인지 골라 주세요.' : null;
|
||||
}
|
||||
|
||||
function turnMs(s: CockroachState): number {
|
||||
/** Clock for the waiting player in ms; null = 무제한 (an away player still gets the short clock). */
|
||||
function turnMs(s: CockroachState): number | null {
|
||||
const p = waiting(s)[0];
|
||||
return p && s.away[p] ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
if (p && s.away[p]) return AWAY_MS;
|
||||
return s.options.turnSeconds === null ? null : s.options.turnSeconds * 1000;
|
||||
}
|
||||
|
||||
function newRound(s: CockroachState, starter: PlayerId): void {
|
||||
@@ -576,7 +580,7 @@ export const cockroachPoker: GameDefinition<CockroachState, CockroachAction, Coc
|
||||
said: s.said,
|
||||
removedCount: s.removed.length,
|
||||
turnStartedAt: s.turnStartedAt,
|
||||
turnMs: turnMs(s),
|
||||
turnMs: turnMs(s) ?? 0,
|
||||
seq: s.seq,
|
||||
final: s.final,
|
||||
revealed: over ? { hands: s.hands, removed: s.removed } : null,
|
||||
@@ -586,7 +590,8 @@ export const cockroachPoker: GameDefinition<CockroachState, CockroachAction, Coc
|
||||
activePlayers: waiting,
|
||||
|
||||
deadline(s) {
|
||||
return finished(s) ? null : s.turnStartedAt + turnMs(s);
|
||||
const ms = turnMs(s);
|
||||
return finished(s) || ms === null ? null : s.turnStartedAt + ms;
|
||||
},
|
||||
|
||||
timeoutPlayers: waiting,
|
||||
|
||||
@@ -475,6 +475,30 @@ describe('시간 초과와 나가기 (§8.5)', () => {
|
||||
expect(s.away.B).toBe(false);
|
||||
});
|
||||
|
||||
test('무제한 (turnSeconds null): no clock for turns, hand check or tax return; timeouts still work and away keeps the 5 s clock', () => {
|
||||
expect(dalmuti.optionsSchema.safeParse({ turnSeconds: null }).success).toBe(true);
|
||||
// Hand check and tax return have no clock either.
|
||||
let c = make({ turnSeconds: null });
|
||||
expect(c.phase.kind).toBe('revolutionCheck');
|
||||
expect(dalmuti.deadline!(c)).toBeNull();
|
||||
expect(dalmuti.view(c, 'A').deadlineTotalMs).toBe(0);
|
||||
for (const p of c.players) c = act(c, p, { type: 'timeout' });
|
||||
expect(c.phase.kind).toBe('taxReturn');
|
||||
expect(dalmuti.deadline!(c)).toBeNull();
|
||||
// Playing: no turn clock; a dropped connection's timeouts still play and lead to away.
|
||||
let s = rig(make({ turnSeconds: null }), { order: P5, hands: { A: [C(1, 1), C(9, 1), C(9, 2), C(9, 3)], B: [C(12, 1), C(12, 2)], C: [C(12, 3)], D: [C(12, 4)], E: [C(12, 5)] } });
|
||||
s.timeoutsInRow.B = 2;
|
||||
s = play(s, 'A', [C(9, 1)]);
|
||||
expect(dalmuti.deadline!(s)).toBeNull();
|
||||
s = act(s, 'B', { type: 'timeout' });
|
||||
expect(s.away.B).toBe(true);
|
||||
for (const p of ['C', 'D', 'E']) s = pass(s, p);
|
||||
s = play(s, 'A', [C(9, 2)]);
|
||||
expect(s.current).toBe('B');
|
||||
expect(dalmuti.deadline!(s)).toBe(s.turnStartedAt + 5000);
|
||||
expect(dalmuti.view(s, 'A').deadlineTotalMs).toBe(5000);
|
||||
});
|
||||
|
||||
test('leaving does not eliminate: the seat stays, marked away, and keeps being auto-played', () => {
|
||||
let s = rig(make(), { order: P5, hands: { A: [C(9, 1)], B: [C(12, 1), C(5, 1)], C: [C(12, 3)], D: [C(12, 4)], E: [C(12, 5)] } });
|
||||
expect(dalmuti.onLeave!(s, 'B')).toEqual({ type: 'leave' });
|
||||
|
||||
@@ -437,18 +437,20 @@ function waiting(s: DalmutiState): PlayerId[] {
|
||||
}
|
||||
}
|
||||
|
||||
/** Clock in ms; null = 무제한 (`turnSeconds` null: no clock for any decision, but away players keep the short one). */
|
||||
function deadlineMs(s: DalmutiState): number | null {
|
||||
const w = waiting(s);
|
||||
const allAway = w.length > 0 && w.every((p) => s.away[p]);
|
||||
if (s.phase.kind === 'finished') return null;
|
||||
if (allAway) return AWAY_MS;
|
||||
if (s.options.turnSeconds === null) return null;
|
||||
switch (s.phase.kind) {
|
||||
case 'revolutionCheck':
|
||||
return allAway ? AWAY_MS : REVOLUTION_MS;
|
||||
return REVOLUTION_MS;
|
||||
case 'taxReturn':
|
||||
return allAway ? AWAY_MS : TAX_MS;
|
||||
return TAX_MS;
|
||||
case 'playing':
|
||||
return allAway ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
case 'finished':
|
||||
return null;
|
||||
return s.options.turnSeconds * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ export function deckFor(removeHighCards: boolean): DCard[] {
|
||||
|
||||
// ---------------------------------------------------------------- options / actions
|
||||
|
||||
const lit = <T extends string | number>(...vals: T[]) =>
|
||||
const lit = <T extends string | number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
export const dalmutiOptionsSchema = z.object({
|
||||
@@ -66,9 +66,13 @@ export const dalmutiOptionsSchema = z.object({
|
||||
jesterTaxable: z.boolean().default(false).meta({ title: '세금 낼 때 광대도 좋은 카드로 내기' }),
|
||||
passLocksOut: z.boolean().default(false).meta({ title: '한 번 패스하면 그 트릭에서 다시 못 내기' }),
|
||||
removeHighCards: z.boolean().default(false).meta({ title: '9~12 카드를 빼고 하기(38장)' }),
|
||||
turnSeconds: lit<15 | 20 | 30 | 45>(15, 20, 30, 45)
|
||||
/**
|
||||
* null = 무제한: no clock for turns, the hand check and the tax return either (a dropped connection still gets
|
||||
* automatic moves after the room's grace time, and away players keep the short clock).
|
||||
*/
|
||||
turnSeconds: lit<15 | 20 | 30 | 45 | null>(15, 20, 30, 45, null)
|
||||
.default(20)
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 15: '15초', 20: '20초', 30: '30초', 45: '45초' } }),
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 15: '15초', 20: '20초', 30: '30초', 45: '45초', null: '무제한' } }),
|
||||
});
|
||||
export type DalmutiOptions = z.infer<typeof dalmutiOptionsSchema>;
|
||||
|
||||
|
||||
@@ -776,6 +776,29 @@ describe('시간 초과·연결 끊김 (§8.5)', () => {
|
||||
s = act(s, 'A', play(gostop.view(s, 'A').myHand![0]!.card.id), 14_000);
|
||||
expect(s.autoPilot[0]).toBe(false);
|
||||
});
|
||||
test('무제한 (turnSeconds·decisionSeconds null): 마감 없음, 그래도 시간 초과(연결 끊김)는 처리되고 2회면 autoPilot 2초', () => {
|
||||
expect(gostop.optionsSchema.safeParse({ turnSeconds: null, decisionSeconds: null }).success).toBe(true);
|
||||
expect(gostop.optionsSchema.safeParse({ turnSeconds: 7 }).success).toBe(false);
|
||||
let s = rigged(2, { hands: [[2, 6, 10], [11, 15, 19]], floor: [20], deck: [24, 36, 37, 38, 39, 42, 43] }, { turnSeconds: null, decisionSeconds: null });
|
||||
expect(gostop.deadline!(s)).toBeNull();
|
||||
expect(gostop.view(s, 'A').deadline).toBeNull();
|
||||
s = act(s, 'A', { type: 'timeout' }, 10_000);
|
||||
expect(s.autoPilot[0]).toBe(false);
|
||||
expect(s.deadline).toBeNull();
|
||||
s = act(s, 'B', play(11), 11_000);
|
||||
s = act(s, 'A', { type: 'timeout' }, 12_000);
|
||||
expect(s.autoPilot[0]).toBe(true);
|
||||
s = act(s, 'B', play(15), 13_000);
|
||||
expect(s.deadline).toBe(13_000 + 2_000);
|
||||
s = act(s, 'A', play(gostop.view(s, 'A').myHand![0]!.card.id), 14_000);
|
||||
expect(s.autoPilot[0]).toBe(false);
|
||||
// 고·스톱 같은 선택 단계도 마감이 없어요.
|
||||
const g = rigged(2, { hands: [[25, 2], [11, 15]], floor: [24], deck: [36, 37, 38], captured: [[0, 8, 28, 1, 5, 9, 13, 33], [44]] }, { decisionSeconds: null });
|
||||
const after = act(g, 'A', play(25), 20_000);
|
||||
expect(after.round!.step).toBe('goStop');
|
||||
expect(after.deadline).toBeNull();
|
||||
expect(act(after, 'A', { type: 'timeout' }).round!.outcome?.type).toBe('stop');
|
||||
});
|
||||
test('나가기: autoPilot, 끊긴 사람 차례 마감 2초, 결과 화면 준비에서 빠짐', () => {
|
||||
let s = rigged(2, { hands: [[2, 6], [11, 15]], floor: [20], deck: [24, 36, 37, 38] });
|
||||
s = act(s, 'A', { type: 'leave' }, 5000);
|
||||
|
||||
@@ -89,7 +89,9 @@ function deadlineMs(s: GostopState): number | null {
|
||||
if (w.length === 0) return null;
|
||||
if (w.every((i) => s.autoPilot[i])) return AUTO_MS;
|
||||
const step = s.round!.step;
|
||||
return (step === 'play' ? s.rules.turnSeconds : s.rules.decisionSeconds) * 1000;
|
||||
const sec = step === 'play' ? s.rules.turnSeconds : s.rules.decisionSeconds;
|
||||
// 무제한: no clock (the room still times out a dropped connection after its grace time).
|
||||
return sec === null ? null : sec * 1000;
|
||||
}
|
||||
|
||||
function refreshDeadline(s: GostopState, now: number): void {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
||||
import type { PlayerId } from '@bg/engine';
|
||||
import type { BonusSetting, CardId, CardView } from './cards';
|
||||
|
||||
const lit = <T extends string | number>(...vals: T[]) =>
|
||||
const lit = <T extends string | number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
export const gostopOptionsSchema = z.object({
|
||||
@@ -58,12 +58,14 @@ export const gostopOptionsSchema = z.object({
|
||||
.enum(['gwang', 'gwangPlus'])
|
||||
.default('gwang')
|
||||
.meta({ title: '팔 수 있는 패', labels: { gwang: '광만', gwangPlus: '광 + 쌍피·국진·보너스' } }),
|
||||
turnSeconds: lit(5, 10, 15, 20, 30, 60)
|
||||
/** null = 무제한 (no clock; a dropped connection still gets auto moves after the room's grace time, autoPilot keeps 2초). */
|
||||
turnSeconds: lit(5, 10, 15, 20, 30, 60, null)
|
||||
.default(15)
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 5: '5초', 10: '10초', 15: '15초', 20: '20초', 30: '30초', 60: '60초' } }),
|
||||
decisionSeconds: lit(5, 10, 15, 20, 30)
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 5: '5초', 10: '10초', 15: '15초', 20: '20초', 30: '30초', 60: '60초', null: '무제한' } }),
|
||||
/** null = 무제한 (고·스톱, 뒤집은 패 고르기, 총통, 광팔기, 국진). */
|
||||
decisionSeconds: lit(5, 10, 15, 20, 30, null)
|
||||
.default(10)
|
||||
.meta({ title: '고·스톱·선택 제한 시간', labels: { 5: '5초', 10: '10초', 15: '15초', 20: '20초', 30: '30초' } }),
|
||||
.meta({ title: '고·스톱·선택 제한 시간', labels: { 5: '5초', 10: '10초', 15: '15초', 20: '20초', 30: '30초', null: '무제한' } }),
|
||||
hints: z.boolean().default(true).meta({ title: '먹을 수 있는 패·족보 힌트' }),
|
||||
});
|
||||
export type GostopOptions = z.infer<typeof gostopOptionsSchema>;
|
||||
|
||||
@@ -256,9 +256,11 @@ function validatePlay(s: NinetyNineState, actor: PlayerId, a: PlayAction): Valid
|
||||
return r.ok ? ok : fail(r.reason);
|
||||
}
|
||||
|
||||
/** Turn clock in ms; null = 무제한 (away players still get the short clock). */
|
||||
function deadlineMs(s: NinetyNineState): number | null {
|
||||
if (s.phase !== 'playing') return null;
|
||||
return s.away[s.current] ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
if (s.away[s.current]) return AWAY_MS;
|
||||
return s.options.turnSeconds === null ? null : s.options.turnSeconds * 1000;
|
||||
}
|
||||
|
||||
function handView(s: NinetyNineState, p: PlayerId, myTurn: boolean): HandCardView[] {
|
||||
|
||||
@@ -463,6 +463,20 @@ describe('시간 초과, 연결 끊김, 나가기 (§8.5)', () => {
|
||||
expect([t.away.A, t.timeoutsInRow.A]).toEqual([false, 0]);
|
||||
});
|
||||
|
||||
test('무제한 (turnSeconds null): no turn clock, but timeouts (dropped connection) still play and lead to away (3 s clock)', () => {
|
||||
expect(ninetyNine.optionsSchema.safeParse({ turnSeconds: null }).success).toBe(true);
|
||||
let s = rig(make({ turnSeconds: null }), { hands: { A: ['1', '2', '3', '4'], B: ['1', '2', '3', '4'], C: ['1', '2', '3', '4'] }, total: 10 });
|
||||
expect(ninetyNine.deadline!(s)).toBeNull();
|
||||
expect(ninetyNine.view(s, 'A').deadlineTotalMs).toBe(0);
|
||||
s.timeoutsInRow.A = 2;
|
||||
s = act(s, 'A', { type: 'timeout' });
|
||||
expect(s.away.A).toBe(true);
|
||||
expect(s.total).toBeGreaterThan(10);
|
||||
expect(ninetyNine.deadline!(s)).toBeNull();
|
||||
s.current = 'A';
|
||||
expect(ninetyNine.deadline!(s)).toBe(s.turnStartedAt + 3000);
|
||||
});
|
||||
|
||||
test('leaving: the current player leaving passes the turn with the same total; 2 players → the other wins', () => {
|
||||
let s = rig(make({ lives: 3 }), { hands: { A: ['1'], B: ['2'], C: ['3'] }, total: 40 });
|
||||
expect(ninetyNine.onLeave!(s, 'A')).toEqual({ type: 'leave' });
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { z } from 'zod';
|
||||
import type { PlayerId } from '@bg/engine';
|
||||
|
||||
const lit = <T extends string | number>(...vals: T[]) =>
|
||||
const lit = <T extends string | number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
export const ninetyNineOptionsSchema = z.object({
|
||||
@@ -47,9 +47,10 @@ export const ninetyNineOptionsSchema = z.object({
|
||||
deckCount: lit<'auto' | 1 | 2>('auto', 1, 2)
|
||||
.default('auto')
|
||||
.meta({ title: '(트럼프) 덱 수', labels: { auto: '자동(7명부터 2벌)', 1: '1벌', 2: '2벌' } }),
|
||||
turnSeconds: lit(10, 15, 20, 30)
|
||||
/** null = 무제한 (no turn clock; a dropped connection still gets auto moves after the room's grace time). */
|
||||
turnSeconds: lit(10, 15, 20, 30, null)
|
||||
.default(15)
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 10: '10초', 15: '15초', 20: '20초', 30: '30초' } }),
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 10: '10초', 15: '15초', 20: '20초', 30: '30초', null: '무제한' } }),
|
||||
});
|
||||
export type NNOptions = z.infer<typeof ninetyNineOptionsSchema>;
|
||||
export type NNMode = NNOptions['mode'];
|
||||
|
||||
@@ -54,8 +54,10 @@ function waiting(s: OldMaidState): PlayerId[] {
|
||||
return finished(s) || !s.turn ? [] : [s.turn];
|
||||
}
|
||||
|
||||
function turnMs(s: OldMaidState): number {
|
||||
return s.turn && s.away[s.turn] ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
/** Turn clock in ms; null = 무제한 (an away player still gets the short clock). */
|
||||
function turnMs(s: OldMaidState): number | null {
|
||||
if (s.turn && s.away[s.turn]) return AWAY_MS;
|
||||
return s.options.turnSeconds === null ? null : s.options.turnSeconds * 1000;
|
||||
}
|
||||
|
||||
function pushLog(s: OldMaidState, e: LogEntry): void {
|
||||
@@ -342,7 +344,7 @@ export const oldMaid: GameDefinition<OldMaidState, OldMaidAction, OldMaidView, O
|
||||
logCount: s.logCount,
|
||||
away: { ...s.away },
|
||||
turnStartedAt: s.turnStartedAt,
|
||||
turnMs: turnMs(s),
|
||||
turnMs: turnMs(s) ?? 0,
|
||||
seq: s.seq,
|
||||
final: s.final,
|
||||
revealed: over ? per((p) => [...s.hands[p]!]) : null,
|
||||
@@ -352,7 +354,8 @@ export const oldMaid: GameDefinition<OldMaidState, OldMaidAction, OldMaidView, O
|
||||
activePlayers: waiting,
|
||||
|
||||
deadline(s) {
|
||||
return finished(s) || !s.turn ? null : s.turnStartedAt + turnMs(s);
|
||||
const ms = turnMs(s);
|
||||
return finished(s) || !s.turn || ms === null ? null : s.turnStartedAt + ms;
|
||||
},
|
||||
|
||||
timeoutPlayers: waiting,
|
||||
|
||||
@@ -240,6 +240,28 @@ describe('시간 초과·나가기 (§8.5)', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('무제한 (turnSeconds null): 제한 시간 없음, 그래도 시간 초과(연결 끊김)는 뽑고 자리 비움이면 5초', () => {
|
||||
expect(game.optionsSchema.safeParse({ turnSeconds: null }).success).toBe(true);
|
||||
let s = rigged({ A: ['2H', '3H', '4H', '5H'], B: ['6H', '7H', '8H', '9H', X()], C: ['2S', '3S', '4S', '5S', '6S', '7S', '8S', '9S'] });
|
||||
s.options = game.optionsSchema.parse({ turnSeconds: null });
|
||||
expect(game.deadline!(s)).toBeNull();
|
||||
expect(game.view(s, 'A').turnMs).toBe(0);
|
||||
s = act(s, 'A', { type: 'timeout' });
|
||||
expect(s.lastDraw).toMatchObject({ drawer: 'A', from: 'B', auto: true });
|
||||
expect(game.deadline!(s)).toBeNull();
|
||||
// A is away after 3 timeouts in a row: the short clock comes back for A only.
|
||||
s.timeoutsInRow.A = 2;
|
||||
s.turn = 'A';
|
||||
s = act(s, 'A', { type: 'timeout' });
|
||||
expect(s.away.A).toBe(true);
|
||||
if (!s.final) {
|
||||
expect(game.deadline!(s)).toBeNull();
|
||||
s.turn = 'A';
|
||||
expect(game.deadline!(s)).toBe(s.turnStartedAt + 5000);
|
||||
expect(game.view(s, 'A').turnMs).toBe(5000);
|
||||
}
|
||||
});
|
||||
|
||||
test('모두 시간 초과만 해도 끝나고, 모든 상태에서 onTimeout이 합법', () => {
|
||||
for (const n of [2, 5, 8]) {
|
||||
let s = setup(Array.from({ length: n }, (_, i) => `P${i}`), n);
|
||||
|
||||
@@ -13,10 +13,11 @@ export const LOG_KEEP = 30;
|
||||
// ---------------------------------------------------------------- options
|
||||
|
||||
export const oldMaidOptionsSchema = z.object({
|
||||
/** null = 무제한 (no turn clock; a dropped connection still gets an auto draw after the room's grace time). */
|
||||
turnSeconds: z
|
||||
.union([z.literal(10), z.literal(20), z.literal(30), z.literal(60)])
|
||||
.union([z.literal(10), z.literal(20), z.literal(30), z.literal(60), z.literal(null)])
|
||||
.default(20)
|
||||
.meta({ title: '한 번 뽑는 제한 시간', labels: { 10: '10초', 20: '20초', 30: '30초', 60: '60초' } }),
|
||||
.meta({ title: '한 번 뽑는 제한 시간', labels: { 10: '10초', 20: '20초', 30: '30초', 60: '60초', null: '무제한' } }),
|
||||
});
|
||||
export type OldMaidOptions = z.infer<typeof oldMaidOptionsSchema>;
|
||||
|
||||
@@ -120,6 +121,7 @@ export interface OldMaidView {
|
||||
logCount: number;
|
||||
away: Record<PlayerId, boolean>;
|
||||
turnStartedAt: number;
|
||||
/** Turn clock length in ms; 0 = 무제한 (no clock). */
|
||||
turnMs: number;
|
||||
seq: number;
|
||||
final: OldMaidFinal | null;
|
||||
|
||||
@@ -739,22 +739,29 @@ export function deadlineSig(s: PokerState): string {
|
||||
return `${h.phase}:${h.no}:${h.step}`;
|
||||
}
|
||||
|
||||
/** Length of the current deadline window in ms (§8.5), or 0 for none. */
|
||||
/** Length of the current deadline window in ms (§8.5), or 0 for none.
|
||||
* 무제한 (turnSeconds/rebuySeconds null): no clock, except the short away clock when everyone we wait for is away
|
||||
* (a shared deadline would also time out the players who are not away). */
|
||||
export function deadlineWindow(s: PokerState): number {
|
||||
const o = s.options;
|
||||
if (s.phase === 'finished') return 0;
|
||||
if (s.phase === 'rebuy') return o.rebuySeconds * 1000;
|
||||
const isAway = (id: PlayerId) => (seatOf(s, id)?.timeoutsInRow ?? 0) >= 2;
|
||||
const unlimited = (): number => {
|
||||
const w = waitingFor(s);
|
||||
return w.length > 0 && w.every(isAway) ? o.awaySeconds * 1000 : 0;
|
||||
};
|
||||
if (s.phase === 'rebuy') return o.rebuySeconds === null ? unlimited() : o.rebuySeconds * 1000;
|
||||
const h = s.hand!;
|
||||
switch (h.phase) {
|
||||
case 'betting': {
|
||||
if (h.bet.turn === null) return 0;
|
||||
const seat = seatOf(s, h.order[h.bet.turn]!)!;
|
||||
return (seat.timeoutsInRow >= 2 ? o.awaySeconds : o.turnSeconds) * 1000;
|
||||
if (isAway(h.order[h.bet.turn]!)) return o.awaySeconds * 1000;
|
||||
return o.turnSeconds === null ? 0 : o.turnSeconds * 1000;
|
||||
}
|
||||
case 'choice':
|
||||
case 'draw':
|
||||
case 'declare':
|
||||
return (o.turnSeconds + 10) * 1000;
|
||||
return o.turnSeconds === null ? unlimited() : (o.turnSeconds + 10) * 1000;
|
||||
case 'handEnd':
|
||||
return o.handEndSeconds * 1000;
|
||||
default:
|
||||
|
||||
@@ -15,6 +15,9 @@ export const MODE_KO: Record<PokerMode, string> = {
|
||||
indian: '인디언 포커',
|
||||
};
|
||||
|
||||
const lit = <T extends number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
export const pokerOptionsSchema = z
|
||||
.object({
|
||||
mode: z.enum(MODES).default('sevenPoker').meta({ title: '게임 모드', labels: MODE_KO }),
|
||||
@@ -54,10 +57,10 @@ export const pokerOptionsSchema = z
|
||||
.union([z.literal(1), z.literal(2), z.literal(3)])
|
||||
.default(1)
|
||||
.meta({ title: '리바이 횟수(횟수 제한일 때)', labels: { 1: '1번', 2: '2번', 3: '3번' } }),
|
||||
turnSeconds: z
|
||||
.union([z.literal(15), z.literal(20), z.literal(30), z.literal(60)])
|
||||
/** null = 무제한 (no clock for betting or the simultaneous steps; a dropped connection still gets auto moves after the room's grace time). */
|
||||
turnSeconds: lit(15, 20, 30, 60, null)
|
||||
.default(20)
|
||||
.meta({ title: '행동 제한 시간', labels: { 15: '15초', 20: '20초', 30: '30초', 60: '60초' } }),
|
||||
.meta({ title: '행동 제한 시간', labels: { 15: '15초', 20: '20초', 30: '30초', 60: '60초', null: '무제한' } }),
|
||||
dealerRule: z
|
||||
.enum(['rotate', 'winner'])
|
||||
.default('rotate')
|
||||
@@ -100,10 +103,10 @@ export const pokerOptionsSchema = z
|
||||
.union([z.literal(3), z.literal(4), z.literal(6), z.literal(10)])
|
||||
.default(4)
|
||||
.meta({ title: '판 결과 보여 주는 시간', labels: { 3: '3초', 4: '4초', 6: '6초', 10: '10초' } }),
|
||||
rebuySeconds: z
|
||||
.union([z.literal(10), z.literal(15), z.literal(30)])
|
||||
/** null = 무제한 (same rule as turnSeconds). */
|
||||
rebuySeconds: lit(10, 15, 30, null)
|
||||
.default(15)
|
||||
.meta({ title: '리바이 고르는 시간', labels: { 10: '10초', 15: '15초', 30: '30초' } }),
|
||||
.meta({ title: '리바이 고르는 시간', labels: { 10: '10초', 15: '15초', 30: '30초', null: '무제한' } }),
|
||||
awaySeconds: z
|
||||
.union([z.literal(3), z.literal(5), z.literal(10)])
|
||||
.default(5)
|
||||
|
||||
@@ -180,6 +180,54 @@ describe('korean betting (§5.2)', () => {
|
||||
s = act(s, 'A', { type: 'k.check' });
|
||||
expect(view(s, null).seats[0]!.away).toBe(false);
|
||||
});
|
||||
|
||||
test('poker 무제한: no clock for turns, simultaneous steps and the rebuy choice; timeout still works, away keeps the short clock', () => {
|
||||
expect(poker.optionsSchema.parse({ turnSeconds: null, rebuySeconds: null })).toMatchObject({ turnSeconds: null, rebuySeconds: null });
|
||||
expect(poker.optionsSchema.parse({})).toMatchObject({ turnSeconds: 20, rebuySeconds: 15 });
|
||||
let s = mk({ mode: 'badugi', turnSeconds: null }, 3, { dealerSeat: 2 });
|
||||
expect(s.deadlineAt).toBeNull();
|
||||
expect(poker.deadline!(s)).toBeNull();
|
||||
expect(view(s, null).deadlineTotalMs).toBe(0);
|
||||
s = act(s, 'A', { type: 'timeout' }); // the room still times out a dropped player → auto check
|
||||
expect(s.hand!.players.A!.lastAction).toBe('체크');
|
||||
expect(s.deadlineAt).toBeNull();
|
||||
s = act(s, 'B', { type: 'k.check' });
|
||||
s = act(s, 'C', { type: 'k.check' });
|
||||
expect(s.hand!.phase).toBe('draw');
|
||||
expect(s.deadlineAt).toBeNull(); // simultaneous step: no clock either
|
||||
s = act(s, 'A', { type: 'timeout' });
|
||||
expect(view(s, null).seats[0]!.away).toBe(true);
|
||||
expect(s.deadlineAt).toBeNull(); // B and C are not away → still no shared clock
|
||||
s = act(s, 'B', { type: 'draw', cardIds: [] });
|
||||
s = act(s, 'C', { type: 'draw', cardIds: [] });
|
||||
expect(toAct(s)).toBe('A');
|
||||
expect(s.deadlineAt! - clock).toBe(5_000); // away player's betting turn: short clock
|
||||
s = act(s, 'A', { type: 'k.check' });
|
||||
expect(view(s, null).seats[0]!.away).toBe(false);
|
||||
expect(s.deadlineAt).toBeNull();
|
||||
|
||||
// simultaneous step where everyone we wait for is away → short clock
|
||||
let d = mk({ mode: 'badugi', turnSeconds: null }, 2, { dealerSeat: 1 });
|
||||
for (const id of ['A', 'B']) d.seats.find((x) => x.id === id)!.timeoutsInRow = 2;
|
||||
d = act(d, toAct(d)!, { type: 'timeout' });
|
||||
d = act(d, toAct(d)!, { type: 'timeout' });
|
||||
expect(d.hand!.phase).toBe('draw');
|
||||
expect(d.deadlineAt! - clock).toBe(5_000);
|
||||
|
||||
// rebuy choice: no clock; a timeout still declines
|
||||
let t = mk({ mode: 'indian', rebuySeconds: null }, 3, { dealerSeat: 2, deck: deckOf('2S TS 3S', deckD20()) });
|
||||
expect(t.deadlineAt! - clock).toBe(20_000);
|
||||
t = act(t, 'A', { type: 'nl.allIn' });
|
||||
t = act(t, 'B', { type: 'nl.fold' });
|
||||
t = act(t, 'C', { type: 'nl.call' });
|
||||
expect(t.deadlineAt! - clock).toBe(4_000); // result screen keeps its clock
|
||||
t = readyAll(t);
|
||||
expect(t.phase).toBe('rebuy');
|
||||
expect(t.deadlineAt).toBeNull();
|
||||
expect(poker.timeoutPlayers!(t)).toEqual(['A']);
|
||||
t = act(t, 'A', { type: 'timeout' });
|
||||
expect(t.seats[0]!.status).toBe('eliminated');
|
||||
});
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------ 7포커
|
||||
|
||||
@@ -571,14 +571,17 @@ function validatePlay(s: UnoState, actor: PlayerId, a: PlayAction): Validation {
|
||||
return ok;
|
||||
}
|
||||
|
||||
/** Turn clock in ms; null = 무제한 (away players still get the short clock). */
|
||||
const turnMs = (s: UnoState, p: PlayerId): number | null => (s.away[p] ? AWAY_MS : s.options.turnSeconds === null ? null : s.options.turnSeconds * 1000);
|
||||
|
||||
function deadlineMs(s: UnoState): number | null {
|
||||
switch (s.phase.kind) {
|
||||
case 'startColor':
|
||||
case 'turn':
|
||||
case 'afterDraw':
|
||||
return s.away[s.current] ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
return turnMs(s, s.current);
|
||||
case 'wild4':
|
||||
return s.away[s.phase.target] ? AWAY_MS : s.options.turnSeconds * 1000;
|
||||
return turnMs(s, s.phase.target);
|
||||
case 'roundEnd':
|
||||
return ROUND_END_MS;
|
||||
case 'finished':
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
||||
import type { PlayerId } from '@bg/engine';
|
||||
import type { Color, UnoCard } from '../one-card/cards';
|
||||
|
||||
const lit = <T extends string | number>(...vals: T[]) =>
|
||||
const lit = <T extends string | number | null>(...vals: T[]) =>
|
||||
z.union(vals.map((v) => z.literal(v)) as unknown as [z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]);
|
||||
|
||||
const colorSchema = z.enum(['R', 'Y', 'G', 'B']);
|
||||
@@ -22,9 +22,10 @@ export const unoOptionsSchema = z.object({
|
||||
}),
|
||||
stacking: z.boolean().default(false).meta({ title: '(하우스 룰) 드로우 카드 쌓기' }),
|
||||
drawUntilPlayable: z.boolean().default(false).meta({ title: '(하우스 룰) 낼 수 있을 때까지 뽑기' }),
|
||||
turnSeconds: lit(10, 15, 20, 30, 60)
|
||||
/** null = 무제한 (no turn clock; a dropped connection still gets auto moves after the room's grace time). */
|
||||
turnSeconds: lit(10, 15, 20, 30, 60, null)
|
||||
.default(20)
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 10: '10초', 15: '15초', 20: '20초', 30: '30초', 60: '60초' } }),
|
||||
.meta({ title: '한 턴 제한 시간', labels: { 10: '10초', 15: '15초', 20: '20초', 30: '30초', 60: '60초', null: '무제한' } }),
|
||||
});
|
||||
export type UnoOptions = z.infer<typeof unoOptionsSchema>;
|
||||
|
||||
|
||||
@@ -461,6 +461,22 @@ describe('시간 초과와 나가기 (§8.5)', () => {
|
||||
expect(s.away.A).toBe(false);
|
||||
});
|
||||
|
||||
test('무제한 (turnSeconds null): no turn clock, but timeouts (dropped connection) still play and lead to away', () => {
|
||||
expect(uno.optionsSchema.safeParse({ turnSeconds: null }).success).toBe(true);
|
||||
let s = rig(make({ turnSeconds: null }), { hands: { A: ['B9a', 'B8a', 'B7a', 'B6a'], B: ['G2a', 'G3a', 'G4a'], C: ['Y3a', 'Y4a', 'Y5a'] }, discard: ['R5a'] });
|
||||
expect(uno.deadline!(s)).toBeNull();
|
||||
expect(uno.view(s, 'A').deadlineTotalMs).toBe(0);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
s.current = 'A';
|
||||
s.phase = { kind: 'turn' };
|
||||
s = act(s, 'A', { type: 'timeout' });
|
||||
}
|
||||
expect(s.away.A).toBe(true);
|
||||
s.current = 'A';
|
||||
s.phase = { kind: 'turn' };
|
||||
expect(uno.deadline!(s)).toBe(s.turnStartedAt + 5000);
|
||||
});
|
||||
|
||||
test('leaving: the hand goes under the draw pile, the turn moves on; the last one left wins', () => {
|
||||
let s = rig(make(), { hands: { A: ['R1a', 'R2a'], B: ['G2a'], C: ['Y3a'] }, discard: ['R5a'] });
|
||||
expect(uno.onLeave!(s, 'A')).toEqual({ type: 'leave' });
|
||||
|
||||
Reference in New Issue
Block a user