From 122cf5ed1f015ecbd9f1f85e882d0b532b2189d8 Mon Sep 17 00:00:00 2001 From: EJClaw Date: Thu, 12 Nov 2026 12:53:45 +0900 Subject: [PATCH] =?UTF-8?q?=ED=83=80=EC=9E=90=20=EB=8C=80=EA=B2=B0:=20?= =?UTF-8?q?=EC=84=9C=EB=B0=94=EC=9D=B4=EB=B2=8C=EC=9D=B4=20=EB=B0=98?= =?UTF-8?q?=EB=93=9C=EC=8B=9C=20=EB=81=9D=EB=82=98=EA=B2=8C(=EB=AA=A8?= =?UTF-8?q?=EB=91=90=20=EB=8F=99=EC=8B=9C=20=ED=83=88=EB=9D=BD=C2=B7?= =?UTF-8?q?=EB=8F=99=EC=A0=90=203=EB=B2=88=20=EC=97=B0=EC=86=8D=EC=9D=B4?= =?UTF-8?q?=EB=A9=B4=20=EB=82=A8=EC=9D=80=20=EC=82=AC=EB=9E=8C=20=EA=B3=B5?= =?UTF-8?q?=EB=8F=99=201=EC=A0=90,=20=EB=AC=B8=EC=A0=9C=2060=EA=B0=9C=20?= =?UTF-8?q?=EC=83=81=ED=95=9C),=20=EB=9D=BC=EC=9A=B4=EB=93=9C=20=EB=81=9D?= =?UTF-8?q?=EB=82=9C=20=EB=92=A4=20=ED=8F=89=EA=B7=A0=20=ED=83=80=EC=88=98?= =?UTF-8?q?=C2=B7=EC=A0=95=ED=99=95=EB=8F=84=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=ED=95=A9=EC=82=B0=20=EA=B3=A0=EC=B9=A8,=20=EC=A0=95=ED=99=95?= =?UTF-8?q?=EB=8F=84=200%=EB=A5=BC=20100%=EB=A1=9C=20=EB=B3=B4=EC=9D=B4?= =?UTF-8?q?=EB=8D=98=20=EA=B2=83=20=EA=B3=A0=EC=B9=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 남은 사람이 모두 한꺼번에 탈락하게 되어 아무도 안 빠지는 문제(시간별은 모두 동점인 간격)가 SURVIVAL_STALL_LIMIT(3)번 이어지면 라운드를 끝내고 남은 사람이 함께 1점. 누가 치거나 탈락하면 횟수는 0으로. 함께 치기는 SURVIVAL_MAX_ITEMS(60)번째 문제에서도 끝. 라운드 요약 "더 탈락하는 사람이 없어서 남은 사람이 함께 1점을 얻어요". - seatView: 진행 중인 라운드만 누적에 더하고, roundEnd·ended에서는 endRound가 이미 더한 누적만 보여 줌. - SeatView.roundTried·tried(무언가 제출했는지)로 "아직 없음"(-)과 실제 0%를 구분(화면·도움말). - 테스트: 네 탈락 조건 모두 아무도 안 칠 때 200번 안에 끝남, 모두 늘 시간 안에 칠 때 60문제에서 끝, 진짜 탈락이 횟수를 초기화, 라운드 뒤 자리 표시 = 최종 결과, 전부 틀린 답의 정확도 0. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/games/typing/help.ts | 2 +- apps/web/src/games/typing/index.tsx | 4 +- packages/games/src/typing/index.ts | 32 ++++++++-- packages/games/src/typing/types.ts | 9 +++ packages/games/src/typing/typing.test.ts | 81 ++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 9 deletions(-) diff --git a/apps/web/src/games/typing/help.ts b/apps/web/src/games/typing/help.ts index 0be9b10..ddb7461 100644 --- a/apps/web/src/games/typing/help.ts +++ b/apps/web/src/games/typing/help.ts @@ -39,7 +39,7 @@ export function helpNow(v: TypingView, me: string | null, players: Record) {
지금 {curKpm}타 이번 라운드 {mine.roundKpm}타 - 정확도 {mine.roundAcc || 100}% + 정확도 {mine.roundTried ? `${mine.roundAcc}%` : '-'} {mine.wrong > 0 && 틀림 {mine.wrong}번} {item && {keyCount(item.text)}타짜리}
@@ -578,7 +578,7 @@ function TypingSide({ view: v, players }: BoardProps) { {s.left ? ' · 나감' : ''} - {s.kpm}타 · {s.acc ? `${s.acc}%` : '-'} + {s.kpm}타 · {s.tried ? `${s.acc}%` : '-'} {s.points} diff --git a/packages/games/src/typing/index.ts b/packages/games/src/typing/index.ts index b58a601..52ae0c8 100644 --- a/packages/games/src/typing/index.ts +++ b/packages/games/src/typing/index.ts @@ -74,6 +74,9 @@ export const autoRoundMs = (items: readonly string[]) => 10_000 + Math.round((it export const SURVIVAL_SHRINK = 0.9; /** … but never below the time a very fast typist (this many 타 a minute) needs, plus a second to read. */ export const SURVIVAL_FLOOR_KPM = 900; +/** 서바이벌 always ends: after this many items (or cuts) in a row where nobody could be knocked out, or this many items, the survivors share the round. */ +export const SURVIVAL_STALL_LIMIT = 3; +export const SURVIVAL_MAX_ITEMS = 60; /** * The clock of shared item `i`. 서바이벌 always has one (무제한 plays as 자동) and it gets shorter item by item, so a round @@ -183,6 +186,8 @@ function startRound(s: S, round: number, ctx: Ctx): void { s.roundEndsAt = null; s.nextCutAt = null; s.outOrder = []; + s.stalls = 0; + s.stalled = false; s.last = null; s.cur = 0; s.curOpen = false; @@ -225,10 +230,17 @@ function openItem(s: S, i: number, at: number): void { /** Does the shared round end after item `i` (the last item, or survival is decided)? */ function sharedOver(s: S, nextIdx: number): boolean { - if (isSurvival(s)) return alive(s).length <= 1; + if (isSurvival(s)) return alive(s).length <= 1 || survivalStalled(s, nextIdx); return !s.cycle && nextIdx >= s.items.length; } +/** 서바이벌 undecided: nobody could be knocked out several times in a row, or the item cap is reached. */ +function survivalStalled(s: S, nextIdx: number): boolean { + if ((s.stalls ?? 0) < SURVIVAL_STALL_LIMIT && nextIdx < SURVIVAL_MAX_ITEMS) return false; + s.stalled = true; + return true; +} + /** The current shared item is decided: remember it, then the next opens after the gap (or the round ends). */ function closeItem(s: S, winner: PlayerId | null, out: PlayerId[], ctx: Ctx): void { const text = itemText(s, s.cur); @@ -243,6 +255,8 @@ function closeItem(s: S, winner: PlayerId | null, out: PlayerId[], ctx: Ctx): vo const ms = w && w.solvedAt !== null ? w.solvedAt - s.curAt : 0; s.last = { text, winner, kpm: w ? kpm(keyCount(text), ms) : 0, out } satisfies LastItem; ctx.events.push({ type: 'itemEnd', item: s.cur, winner, out }); + // Somebody typed it or went out: the survivors are not stuck (only all-at-once misses in a row count as a stall). + if (out.length || s.order.some((p) => s.rs[p]!.alive && s.rs[p]!.solvedAt !== null && s.rs[p]!.prog >= keyCount(text))) s.stalls = 0; const next = s.cur + 1; if (sharedOver(s, next)) return endRound(s, ctx); openItem(s, next, ctx.now + GAP_MS); @@ -254,11 +268,13 @@ function knockOut(s: S, ps: PlayerId[], why: OutReason, ctx: Ctx, force = false) const hit = ps.filter((p) => s.rs[p]!.alive); if (!hit.length) return []; if (!force && hit.length >= live.length) { - // Everyone left would go: they all stay (a 목숨 rule keeps one life). + // Everyone left would go: they all stay (a 목숨 rule keeps one life) — but not for ever (`SURVIVAL_STALL_LIMIT`). for (const p of hit) if (s.rs[p]!.lives <= 0) s.rs[p]!.lives = 1; + s.stalls = (s.stalls ?? 0) + 1; ctx.events.push({ type: 'spared', players: hit }); return []; } + s.stalls = 0; const place = live.length - hit.length + 1; for (const p of hit) { const r = s.rs[p]!; @@ -310,7 +326,7 @@ function intervalCut(s: S, ctx: Ctx): void { 'least', ctx, ); - if (alive(s).length <= 1) endRound(s, ctx); + if (alive(s).length <= 1 || survivalStalled(s, 0)) endRound(s, ctx); else s.nextCutAt = (s.nextCutAt ?? ctx.now) + s.options.intervalSec * 1000; } @@ -432,7 +448,7 @@ function roundSummary(s: S, winners: PlayerId[]): string { case 'first': return solo ? '라운드 끝!' : `가장 많이 먼저 친 사람이 이 라운드 1등이에요${many}`; case 'survival': - return `끝까지 살아남은 사람이 1점을 얻어요${many}`; + return s.stalled ? `더 탈락하는 사람이 없어서 남은 사람이 함께 1점을 얻어요${many}` : `끝까지 살아남은 사람이 1점을 얻어요${many}`; case 'speed': return solo ? '라운드 끝! 타수를 확인해요' : `타수가 가장 높은 사람이 1점을 얻어요${many}`; case 'accuracy': @@ -678,13 +694,17 @@ function seatView(s: S, p: PlayerId): SeatView { const r = s.rs[p]!; const t = s.totals[p]!; const shared = flowOf(s.options) === 'shared'; + const live = s.phase === 'playing'; const target = s.phase === 'playing' && s.items.length ? targetOf(s, p) : ''; const of = target ? keyCount(target) : 0; return { id: p, points: t.points, - kpm: avgKpm({ keys: t.keys + r.keys, ms: t.ms + r.ms }), - acc: avgAcc({ accSum: t.accSum + r.accSum, accLen: t.accLen + r.accLen }), + // While a round is played its numbers are not in the totals yet; once it ends (`endRound`) they are. + kpm: avgKpm(live ? { keys: t.keys + r.keys, ms: t.ms + r.ms } : t), + acc: avgAcc(live ? { accSum: t.accSum + r.accSum, accLen: t.accLen + r.accLen } : t), + tried: t.accLen + (live ? r.accLen : 0) > 0, + roundTried: r.accLen > 0, left: t.left, idx: shared ? s.cur : r.idx, done: r.done, diff --git a/packages/games/src/typing/types.ts b/packages/games/src/typing/types.ts index 673e06c..4df3e3c 100644 --- a/packages/games/src/typing/types.ts +++ b/packages/games/src/typing/types.ts @@ -154,6 +154,12 @@ export interface TypingState { last: LastItem | null; /** 서바이벌 시간별: the next cut. */ nextCutAt: number | null; + /** + * 서바이벌: items / cuts in a row where everyone left would have gone out at once (so nobody did), and whether the + * round ended undecided (that went on too long, or the item cap) — the survivors then share the point. + */ + stalls?: number; + stalled?: boolean; /** Survivors knocked out so far this round, in order (for places). */ outOrder: PlayerId[]; rs: Record; @@ -184,6 +190,9 @@ export interface SeatView { prog: number; roundKpm: number; roundAcc: number; + /** Something was submitted this round / this game (so an accuracy of 0 is a real 0, not "nothing yet"). */ + roundTried: boolean; + tried: boolean; wrong: number; finished: boolean; lives: number; diff --git a/packages/games/src/typing/typing.test.ts b/packages/games/src/typing/typing.test.ts index ce95106..0286a36 100644 --- a/packages/games/src/typing/typing.test.ts +++ b/packages/games/src/typing/typing.test.ts @@ -4,12 +4,15 @@ import { COUNTDOWN_MS, GAP_MS, ROUND_END_MS, + SURVIVAL_MAX_ITEMS, + SURVIVAL_STALL_LIMIT, autoItemMs, itemLimit, ROUND_ITEMS, flowOf, itemText, keyCount, + minTypingMs, topicIdsFor, typing, type TypingAction, @@ -38,6 +41,8 @@ const reason = (s: TypingState, p: string, a: TypingAction, now: number) => { const later = (at: number) => at + 4000; /** Shared: the current item, typed right by `p` well after it opened. */ const solve = (s: TypingState, p: string, at = later(s.curAt)) => act(s, p, { type: 'submit', item: s.cur, text: itemText(s, s.cur) }, at); +/** 서바이벌 문장별, three players, playing. */ +const surv3 = () => tick(make({ mode: 'survival', elimination: 'sentence', rounds: 1 }, ['A', 'B', 'C']), START); /** Opens the next shared item (after the gap). */ const open = (s: TypingState) => tick(s, s.curAt); @@ -311,6 +316,82 @@ describe('타수 비교 · 정확도 대결 · 타임어택', () => { }); }); +describe('서바이벌은 반드시 끝나요', () => { + /** Fires the server clock until the game ends (nobody types). */ + const runClock = (s: TypingState, max = 500) => { + let n = 0; + while (s.phase !== 'ended' && n < max) { + s = tick(s, typing.deadline!(s)!); + n++; + } + return { s, n }; + }; + test.each(['wrong', 'sentence', 'interval', 'deadline'] as const)('%s: everybody away (all miss / all tie) → the survivors share the round after a few tries', (elimination) => { + const { s, n } = runClock(make({ mode: 'survival', elimination, rounds: 2, lives: 3 }, ['A', 'B', 'C'])); + expect(s.phase).toBe('ended'); + expect(n).toBeLessThan(200); + for (const r of s.rounds) { + expect(r.winners.sort()).toEqual(['A', 'B', 'C']); + expect(r.summary).toContain('더 탈락하는 사람이 없어서'); + } + expect(typing.result(s)!.ranking).toEqual([['A', 'B', 'C']]); + }); + + test(`a round where everybody always types in time stops after ${SURVIVAL_MAX_ITEMS} items`, () => { + let s = tick(make({ mode: 'survival', elimination: 'deadline', rounds: 1 }, ['A', 'B']), START); + let items = 0; + while (s.phase === 'playing') { + const fast = s.curAt + minTypingMs(keyCount(itemText(s, s.cur))) + 10; + s = solve(s, 'A', fast); + s = solve(s, 'B', fast + 10); + items++; + if (s.phase === 'playing') s = open(s); + } + expect(items).toBe(SURVIVAL_MAX_ITEMS); + expect(s.rounds[0]!.winners.sort()).toEqual(['A', 'B']); + }); + + test('one real knock-out resets the count of all-at-once misses', () => { + let s = surv3(); + for (let i = 0; i < SURVIVAL_STALL_LIMIT - 1; i++) s = open(tick(s, s.curEndsAt!)); + expect(s.stalls).toBe(SURVIVAL_STALL_LIMIT - 1); + s = solve(s, 'A'); + s = solve(s, 'B'); + expect(s.rs.C!.alive).toBe(false); + expect(s.stalls).toBe(0); + }); +}); + +describe('기록 표시', () => { + test('after a round, a seat shows the same 타수 and accuracy as the result (nothing counted twice)', () => { + let s = tick(make({ mode: 'speed', rounds: 2, category: 'word' }, ['A']), START); + for (let r = 0; r < 2; r++) { + const t0 = s.roundStartedAt; + for (let i = 0; i < s.items.length; i++) s = act(s, 'A', { type: 'submit', item: i, text: i % 2 ? s.items[i]! : `${s.items[i]}x` }, t0 + (i + 1) * 3000); + if (s.phase === 'roundEnd') { + const seat = typing.view(s, 'A').seats[0]!; + expect(seat.kpm).toBe(Math.round((s.totals.A!.keys * 60_000) / s.totals.A!.ms)); + s = tick(s, s.phaseEndsAt!); + s = tick(s, s.phaseEndsAt!); + } + } + expect(s.phase).toBe('ended'); + const seat = typing.view(s, 'A').seats[0]!; + const fin = s.final!.ranking[0]!; + expect(seat.kpm).toBe(fin.kpm); + expect(seat.acc).toBe(fin.acc); + }); + + test('all wrong answers: accuracy 0 is a real 0 (tried), not "nothing yet"', () => { + let s = tick(make({ mode: 'speed', rounds: 1 }), START); + let seat = typing.view(s, 'A').seats[0]!; + expect(seat).toMatchObject({ roundTried: false, tried: false }); + s = act(s, 'A', { type: 'submit', item: 0, text: 'ㅋㅋㅋ' }, START + 5000); + seat = typing.view(s, 'A').seats[0]!; + expect(seat).toMatchObject({ roundTried: true, tried: true, roundAcc: 0, acc: 0 }); + }); +}); + describe('leaving and clocks', () => { test('when everyone else leaves, the one who stayed wins', () => { let s = tick(make({}, ['A', 'B', 'C']), START);