그림 맞히기·클루: 그리기·차례 시간 무제한(출제자 정답 공개로 넘기기), 소리·움직임, 할리갈리·사과 게임 문서에 무제한

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:01:42 +09:00
parent bafbf95d98
commit b8966db2a6
15 changed files with 413 additions and 84 deletions

View File

@@ -202,7 +202,7 @@ describe('점수(§6)', () => {
test('multi: 아무도 못 맞히면 출제자 0점, 시간 만료로 공개', () => {
let s = drawWith(make(3), '기린');
const d = s.turn.drawer;
s = act(s, d, { type: 'tick' }, s.turn.endsAt);
s = act(s, d, { type: 'tick' }, s.turn.endsAt!);
expect(s.turn.phase).toBe('reveal');
expect(s.turn.endReason).toBe('time');
expect(s.scores[d]).toBe(0);
@@ -224,11 +224,42 @@ describe('점수(§6)', () => {
test('speedBonus: 남은 시간 비율 × 5점 추가', () => {
let s = drawWith(make(3, { speedBonus: true }), '기린', T0);
const g = guessers(s)[0]!;
const dur = s.turn.endsAt - s.turn.startedAt;
const dur = s.turn.endsAt! - s.turn.startedAt;
s = act(s, g, guess('기린'), T0 + dur / 2);
expect(s.scores[g]).toBe(10 + 3); // round(2.5)
});
test('그리기 무제한: 마감 없음(힌트는 80초 기준), 출제자 정답 공개로 넘기기, 시간 제한 방에서는 거절', () => {
let s = drawWith(make(3, { drawSeconds: null, speedBonus: true }), '아이스크림', T0);
const d = s.turn.drawer;
const [a, b] = guessers(s) as [string, string];
expect(s.turn.endsAt).toBeNull();
expect(view(s, a).phaseMs).toBeNull();
// Hints still come, at 40 s and 60 s (the 80 s reference); after them nothing is due.
expect(cm.deadline!(s)).toBe(T0 + 40_000);
s = act(s, d, { type: 'tick' }, T0 + 40_000);
expect(s.turn.hintStage).toBe(1);
s = act(s, d, { type: 'tick' }, T0 + 60_000);
expect(s.turn.hintStage).toBe(2);
expect(cm.deadline!(s)).toBeNull();
// A guess long after "80 s" is still taken (speed bonus 0 by then).
s = act(s, a, guess('아이스크림'), T0 + 600_000);
expect(s.scores[a]).toBe(10);
expect(reason(s, a, { type: 'giveUp' })).toBe('출제자만 정답을 공개할 수 있어요.');
s = act(s, d, { type: 'giveUp' }, T0 + 601_000);
expect(s.turn.phase).toBe('reveal');
expect(s.turn.endReason).toBe('giveUp');
expect(s.scores[d]).toBe(2); // one solver in multi mode
expect(view(s, b).word).toBe('아이스크림');
const timed = drawWith(make(3), '기린');
expect(reason(timed, timed.turn.drawer, { type: 'giveUp' })).toBe('제한 시간이 있는 방에서는 시간이 끝날 때까지 그려요.');
// An away drawer is still timed out by the room (nothing else due → drawerAway).
let w = drawWith(make(3, { drawSeconds: null, hints: 'basic' }), '기린', T0);
expect(cm.deadline!(w)).toBeNull();
w = act(w, w.turn.drawer, { type: 'tick' }, T0 + 30_000);
expect(w.turn.endReason).toBe('drawerAway');
});
test('신고 과반 → 즉시 종료, 출제자 0점(맞힌 사람 점수 유지)', () => {
let s = drawWith(make(5), '기린');
const d = s.turn.drawer;
@@ -367,16 +398,16 @@ describe('진행(§5.1, §5.2, §8.5)', () => {
expect(s.turn.phase).toBe('drawing');
expect(s.turn.word!.word).toBe(c0);
expect(s.away).toEqual([]);
s = act(s, first, { type: 'tick' }, s.turn.endsAt);
s = act(s, first, { type: 'tick' }, s.turn.endsAt!);
expect(s.turn.phase).toBe('reveal');
expect(cm.deadline!(s)).toBe(s.turn.startedAt + REVEAL_MS);
s = act(s, first, { type: 'tick' }, s.turn.endsAt);
s = act(s, first, { type: 'tick' }, s.turn.endsAt!);
expect(s.turn.drawer).not.toBe(first);
expect(s.turn.no).toBe(2);
const second = s.turn.drawer;
s = act(s, second, { type: 'chooseWord', index: 2 }, s.turn.startedAt + 1000);
s = act(s, second, { type: 'tick' }, s.turn.endsAt);
s = act(s, second, { type: 'tick' }, s.turn.endsAt);
s = act(s, second, { type: 'tick' }, s.turn.endsAt!);
s = act(s, second, { type: 'tick' }, s.turn.endsAt!);
expect(s.finished).toBe(true);
const r = cm.result(s)!;
expect(r.ranking.flat().sort()).toEqual(['p1', 'p2']);
@@ -410,15 +441,15 @@ describe('진행(§5.1, §5.2, §8.5)', () => {
// Skipped while away: the next drawers are the others.
const seen: string[] = [];
for (let i = 0; i < 2; i++) {
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt);
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt!);
seen.push(s.turn.drawer);
s = act(s, s.turn.drawer, { type: 'chooseWord', index: 0 }, s.turn.startedAt + 100);
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt);
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt!);
}
expect(seen).not.toContain(d);
// "돌아왔어요" clears the mark.
expect(reason(s, d, { type: 'back' })).toBeNull();
s = act(s, d, { type: 'back' }, s.turn.endsAt - 1);
s = act(s, d, { type: 'back' }, s.turn.endsAt! - 1);
expect(s.away).toEqual([]);
expect(reason(s, d, { type: 'back' })).not.toBeNull();
});
@@ -431,7 +462,7 @@ describe('진행(§5.1, §5.2, §8.5)', () => {
expect(s.turn.phase).toBe('reveal');
expect(s.turn.endReason).toBe('drawerLeft');
expect(cm.onLeave!(s, d)).toBeNull();
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt);
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt!);
expect(s.turn.drawer).not.toBe(d);
const other = s.order.find((p) => p !== d && p !== s.turn.drawer)!;
s = act(s, other, { type: 'leave' }, s.turn.startedAt + 100);
@@ -454,7 +485,7 @@ describe('진행(§5.1, §5.2, §8.5)', () => {
let s = drawWith(make(4, { guessMode: 'firstOnly', answererDraws: true }), '기린');
const g = guessers(s)[2]!;
s = act(s, g, guess('기린'), T0 + 2000);
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt);
s = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt!);
expect(s.turn.drawer).toBe(g);
});
@@ -466,7 +497,7 @@ describe('진행(§5.1, §5.2, §8.5)', () => {
s.turnsPlayed = s.totalTurns - 1;
s.round = s.options.rounds;
s.turn.drawer = s.order.at(-1)!;
const r = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt);
const r = act(s, s.turn.drawer, { type: 'tick' }, s.turn.endsAt!);
expect(r.finished).toBe(true);
expect(cm.result(r)!.ranking.map((g) => [...g].sort())).toEqual([['p2'], ['p1', 'p3'], ['p4']]);
expect(r.final!.ranking.map((x) => x.rank)).toEqual([1, 2, 2, 4]);
@@ -540,7 +571,8 @@ function fastPlayout(players: PlayerId[], options: CatchmindOptions, seed: RngSt
invariants(s, poolSize);
if (cm.result(s)) return { state: s, trace, steps: step };
// Timer: the drawer's tick when due (as the room would), otherwise a random actor.
const due = cm.deadline!(s)!;
// 무제한 drawing without hints has no deadline: only the random "away drawer" ticks below.
const due = cm.deadline!(s) ?? Infinity;
let p: PlayerId;
let a: CatchmindAction;
if (now >= due || pick.int(12) === 0) {
@@ -603,7 +635,7 @@ describe('무작위 대국(§10, docs/09 §7)', () => {
const options = opts({
guessMode: pk.int(3) === 0 ? 'firstOnly' : 'multi',
rounds: (1 + pk.int(3)) as 1 | 2 | 3,
drawSeconds: ([60, 80, 100, 120] as const)[pk.int(4)]!,
drawSeconds: ([60, 80, 100, 120, null] as const)[pk.int(5)]!,
wordChoice: pk.int(4) !== 0,
hints: (['none', 'basic', 'full'] as const)[pk.int(3)]!,
letterReport: pk.int(3) !== 0,

View File

@@ -118,11 +118,16 @@ export function reportsNeeded(s: S): number {
return Math.floor(voters / 2) + 1;
}
/** 무제한 drawings time their hints and the speed bonus as if they had the default 80 seconds. */
export const UNLIMITED_REF_MS = 80_000;
/** The drawing's length for hints / speed bonus (무제한: the 80 s reference). */
const drawLen = (t: Turn) => (t.endsAt === null ? UNLIMITED_REF_MS : t.endsAt - t.startedAt);
/** Next hint time while drawing (`hints: full` only): 50% → initials, 75% → one letter (skipped for ≤ 2 letters). */
export function nextHintAt(s: S): number | null {
const t = s.turn;
if (s.finished || t.phase !== 'drawing' || s.options.hints !== 'full' || !t.word) return null;
const dur = t.endsAt - t.startedAt;
const dur = drawLen(t);
if (t.hintStage === 0) return t.startedAt + Math.round(dur * 0.5);
if (t.hintStage === 1 && letters(t.word.word) > 2) return t.startedAt + Math.round(dur * 0.75);
return null;
@@ -178,7 +183,7 @@ function beginDrawing(s: S, index: number, ctx: Ctx): void {
t.choices = [];
t.phase = 'drawing';
t.startedAt = ctx.now;
t.endsAt = ctx.now + s.options.drawSeconds * 1000;
t.endsAt = s.options.drawSeconds === null ? null : ctx.now + s.options.drawSeconds * 1000;
t.hintStage = 0;
ctx.events.push({ type: 'drawing', no: t.no, drawer: t.drawer });
}
@@ -297,7 +302,7 @@ function guess(s: S, p: PlayerId, raw: string, ctx: Ctx): void {
if (j === 'correct') {
const k = t.solvers.length + 1;
let points = s.options.guessMode === 'multi' ? Math.max(10 - 2 * (k - 1), 4) : 10;
if (s.options.speedBonus) points += Math.round((5 * Math.max(0, t.endsAt - ctx.now)) / Math.max(1, t.endsAt - t.startedAt));
if (s.options.speedBonus) points += Math.round((5 * Math.max(0, t.startedAt + drawLen(t) - ctx.now)) / Math.max(1, drawLen(t)));
t.solvers.push({ id: p, at: ctx.now, points });
s.scores[p] = (s.scores[p] ?? 0) + points;
s.correctCounts[p] = (s.correctCounts[p] ?? 0) + 1;
@@ -318,7 +323,7 @@ function tick(s: S, ctx: Ctx): void {
const t = s.turn;
if (t.phase === 'choosing') {
// Only a disconnected drawer is timed out before the 10 s are up (room grace hook): skip them next time.
if (ctx.now < t.endsAt) markAway(s, t.drawer);
if (ctx.now < t.endsAt!) markAway(s, t.drawer);
beginDrawing(s, 0, ctx);
return;
}
@@ -328,7 +333,7 @@ function tick(s: S, ctx: Ctx): void {
advanceHint(s, ctx);
hinted = true;
}
if (ctx.now >= t.endsAt) return endDrawing(s, 'time', ctx);
if (t.endsAt !== null && ctx.now >= t.endsAt) return endDrawing(s, 'time', ctx);
if (hinted) return;
// Nothing was due: the drawer has been disconnected for DRAWER_AWAY_MS (§5.2) → 0 points, answer revealed.
markAway(s, t.drawer);
@@ -499,7 +504,7 @@ function buildView(s: S, viewer: PlayerId | null, withCanvas: boolean): Catchmin
drawer: t.drawer,
startedAt: t.startedAt,
endsAt: t.endsAt,
phaseMs: t.endsAt - t.startedAt,
phaseMs: t.endsAt === null ? null : t.endsAt - t.startedAt,
choices: isDrawer && t.phase === 'choosing' && !s.finished ? t.choices.map((w) => ({ word: w.word, category: w.category, difficulty: w.difficulty })) : null,
word: knows && t.word ? t.word.word : null,
category: knows && t.word ? t.word.category : null,
@@ -613,7 +618,7 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
const len = [...cleanText(a.text)].length;
if (len < 1) return fail('내용을 입력해 주세요.');
if (len > GUESS_MAX) return fail(`${GUESS_MAX}자까지 쓸 수 있어요.`);
if (now !== undefined && now >= t.endsAt) return fail('시간이 다 됐어요.');
if (now !== undefined && t.endsAt !== null && now >= t.endsAt) return fail('시간이 다 됐어요.');
if (!rateOk(s.msgTimes[actor], GUESS_MSGS_PER_SEC, now)) return fail('조금 천천히 보내 주세요.');
return ok;
}
@@ -632,6 +637,11 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
return ok;
case 'back':
return s.away.includes(actor) ? ok : fail('이미 게임에 참여하고 있어요.');
case 'giveUp':
if (actor !== t.drawer) return fail('출제자만 정답을 공개할 수 있어요.');
if (t.phase !== 'drawing') return fail('그리는 동안에만 정답을 공개할 수 있어요.');
if (s.options.drawSeconds !== null) return fail('제한 시간이 있는 방에서는 시간이 끝날 때까지 그려요.');
return ok;
case 'report':
if (!s.options.letterReport) return fail('이 방은 신고를 쓰지 않아요.');
if (t.phase !== 'drawing') return fail('그리는 동안에만 신고할 수 있어요.');
@@ -670,6 +680,9 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
case 'back':
ctx.events.push({ type: 'back', player: actor });
break;
case 'giveUp':
endDrawing(s, 'giveUp', ctx);
break;
case 'report':
s.turn.reports.push(actor);
ctx.events.push({ type: 'report', count: s.turn.reports.length, need: reportsNeeded(s) });
@@ -702,7 +715,9 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
deadline(s) {
if (s.finished) return null;
const h = nextHintAt(s);
return h === null ? s.turn.endsAt : Math.min(h, s.turn.endsAt);
const e = s.turn.endsAt;
if (h === null) return e;
return e === null ? h : Math.min(h, e);
},
/** The drawer's clock drives every server tick (choosing, hints, time up, reveal). */
@@ -768,7 +783,7 @@ export const catchmind: GameDefinition<S, A, CatchmindView, CatchmindOptions> =
out.push({ type: 'draw', op: { k: 'e', s: t.lastStroke } });
}
if (t.live > 0) out.push({ type: 'draw', op: { k: 'u' } }, { type: 'draw', op: { k: 'x' } });
out.push({ type: 'reaction', code: 'almost' });
out.push({ type: 'reaction', code: 'almost' }, { type: 'giveUp' });
} else {
out.push({ type: 'guess', text: t.word!.word }, { type: 'guess', text: '모르겠어요' }, { type: 'guess', text: `${t.word!.word} 맞나` }, { type: 'report' });
}

View File

@@ -53,9 +53,10 @@ export const catchmindOptionsSchema = z.object({
rounds: lit<1 | 2 | 3>(1, 2, 3)
.default(2)
.meta({ title: '라운드 수(모두 한 번씩 그리면 1라운드)', labels: { 1: '1라운드', 2: '2라운드', 3: '3라운드' } }),
drawSeconds: lit<60 | 80 | 100 | 120>(60, 80, 100, 120)
/** null = 무제한: the drawing goes on until it is solved (or the drawer opens the answer with `giveUp`). */
drawSeconds: lit<60 | 80 | 100 | 120 | null>(60, 80, 100, 120, null)
.default(80)
.meta({ title: '그리기 제한 시간', labels: { 60: '60초', 80: '80초', 100: '100초', 120: '120초' } }),
.meta({ title: '그리기 제한 시간', labels: { 60: '60초', 80: '80초', 100: '100초', 120: '120초', null: '무제한(맞히거나 출제자가 넘길 때까지)' } }),
wordChoice: z.boolean().default(true).meta({ title: '출제자가 단어 3개 중 고르기(끄면 무작위 1개)' }),
categories: z
.object(Object.fromEntries(CATEGORIES.map((c) => [c, z.boolean().default(true).meta({ title: CATEGORY_KO[c] })])) as Record<Category, z.ZodDefault<z.ZodBoolean>>)
@@ -104,6 +105,8 @@ export const catchmindActionSchema = z.discriminatedUnion('type', [
z.object({ type: z.literal('report') }),
/** "돌아왔어요": clears the away mark (players marked away are skipped as drawer). */
z.object({ type: z.literal('back') }),
/** 무제한 only: the drawer opens the answer and ends the drawing (drawer points as usual for those who got it). */
z.object({ type: z.literal('giveUp') }),
]);
/** Client actions plus system-only ones (server timer, leaving) that are not in the schema. */
export type CatchmindAction = z.infer<typeof catchmindActionSchema> | { type: 'tick' } | { type: 'leave' };
@@ -130,7 +133,7 @@ export interface Solver {
points: number;
}
export type TurnEndReason = 'time' | 'allSolved' | 'first' | 'report' | 'drawerAway' | 'drawerLeft';
export type TurnEndReason = 'time' | 'allSolved' | 'first' | 'report' | 'drawerAway' | 'drawerLeft' | 'giveUp';
export interface Turn {
/** 1-based turn counter (also the canvas key). */
@@ -140,7 +143,8 @@ export interface Turn {
choices: WordEntry[];
word: WordEntry | null;
startedAt: number;
endsAt: number;
/** null only while drawing with no time limit (무제한). */
endsAt: number | null;
/** 0 letter count, 1 initial consonants, 2 one letter (§5.4). */
hintStage: 0 | 1 | 2;
revealIndex: number | null;
@@ -243,9 +247,9 @@ export interface CatchmindView {
phase: Turn['phase'] | 'ended';
drawer: PlayerId;
startedAt: number;
endsAt: number;
/** Length of the current phase (ms), for timer rings. */
phaseMs: number;
endsAt: number | null;
/** Length of the current phase (ms), for timer rings; null = 무제한. */
phaseMs: number | null;
/** Drawer only, while choosing. */
choices: ChoiceView[] | null;
/** Drawer, solvers and (after the turn) everyone. */

View File

@@ -314,6 +314,29 @@ describe('timer and leaving', () => {
expect(u.deadlineAt).toBe(clock + 10_000);
});
test('turnSeconds 무제한: no clock on turns or refuting; an away player (room grace) is still moved on and then gets the short clock', () => {
let s = rigged(hands, undefined, { turnSeconds: null });
// setup's own deadline was computed before rigging; a fresh turn shows the unlimited clock.
s = go(s, 'A', { type: 'timeout' });
expect(s.current).toBe('B');
expect(s.deadlineAt).toBeNull();
expect(clue.deadline!(s)).toBeNull();
let r = inRoom(rigged(hands, undefined, { turnSeconds: null }), 'A', 'library');
r = go(r, 'A', { type: 'suggest', suspect: 'mustard', weapon: 'rope' });
expect(r.phase.kind).toBe('refute');
expect(r.deadlineAt).toBeNull();
let u = rigged(hands, undefined, { turnSeconds: null });
u.out.C = true;
for (let i = 0; i < 3; i++) {
u = go(u, 'A', { type: 'timeout' });
u = go(u, 'B', { type: 'roll' });
u = go(u, 'B', clue.legalActions!(u, 'B').find((a) => a.type === 'walk' || a.type === 'go')!);
if (u.phase.kind === 'suggest') u = go(u, 'B', { type: 'end' });
}
expect(u.current).toBe('A');
expect(u.deadlineAt).toBe(clock + 10_000);
});
test('leaving: cards go face up, the answer chain and turns go on, the last one in the room wins', () => {
let s = inRoom(rigged(hands), 'A', 'library');
s = go(s, 'A', { type: 'suggest', suspect: 'green', weapon: 'rope' });
@@ -407,7 +430,12 @@ describe('random games', () => {
test('engine random playouts (secretsOf leak check, JSON round trip)', () => {
for (let i = 0; i < playoutSeeds(60); i++) {
const n = 3 + (i % 4);
const r = randomPlayout(clue, { players: ['A', 'B', 'C', 'D', 'E', 'F'].slice(0, n), seed: seedN(i + 1), maxApplyMs: 50 });
const r = randomPlayout(clue, {
players: ['A', 'B', 'C', 'D', 'E', 'F'].slice(0, n),
seed: seedN(i + 1),
maxApplyMs: 50,
...(i % 4 === 3 ? { options: clue.optionsSchema.parse({ turnSeconds: null }) } : {}),
});
expect(r.finished).toBe(true);
}
});

View File

@@ -66,11 +66,14 @@ function refreshDeadline(s: ClueState, now: number): void {
s.deadlineAt = null;
return;
}
const unlimited = s.options.turnSeconds === null;
if (s.phase.kind === 'refute') {
s.deadlineAt = now + REFUTE_MS;
s.deadlineAt = unlimited ? null : now + REFUTE_MS;
return;
}
s.deadlineAt = now + ((s.idle[s.current] ?? 0) >= IDLE_TURNS ? IDLE_MS : s.options.turnSeconds * 1000);
// Someone who let the clock run out three turns in a row gets a short clock (무제한 too: only away players time out there).
if ((s.idle[s.current] ?? 0) >= IDLE_TURNS) s.deadlineAt = now + IDLE_MS;
else s.deadlineAt = unlimited ? null : now + s.options.turnSeconds! * 1000;
}
function finish(s: ClueState, winner: PlayerId | null, reason: ClueFinal['reason'], events: GameEvent[]): void {

View File

@@ -7,7 +7,7 @@ export * from './board';
// ---------------------------------------------------------------- options
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 clueOptionsSchema = z.object({
@@ -15,9 +15,10 @@ export const clueOptionsSchema = z.object({
.enum(['dice', 'free'])
.default('dice')
.meta({ title: '이동 방식', labels: { dice: '주사위 2개로 복도 이동(원작처럼)', free: '빠르게(아무 방이나 바로 이동)' } }),
turnSeconds: lit(30, 45, 60, 90)
/** null = 무제한: no clock on turns or on showing a card (only players away past the room's grace period are moved on). */
turnSeconds: lit<30 | 45 | 60 | 90 | null>(30, 45, 60, 90, null)
.default(60)
.meta({ title: '차례 제한 시간', labels: { 30: '30초', 45: '45초', 60: '60초', 90: '90초' } }),
.meta({ title: '차례 제한 시간', labels: { 30: '30초', 45: '45초', 60: '60초', 90: '90초', null: '무제한' } }),
});
export type ClueOptions = z.infer<typeof clueOptionsSchema>;