새 게임 타자 대결: 한국어·영어, 가장 먼저 입력·서바이벌·타수 비교·정확도 대결·타임어택, 단어·짧은글·긴글, 주제 여러 개, 1~10라운드

- 규칙 packages/games/src/typing: 함께 치기(같은 문제를 동시에, 정해지면 1.5초 쉬고 다음)와 각자 치기(한 줄씩 자기 속도로).
  가장 먼저 입력은 문제마다 먼저 정확하게 친 사람 1점, 나머지는 라운드 1등 1점, 최종은 점수 → 평균 타수 → 정확도.
  서바이벌 탈락 조건: 틀렸을 때(목숨 1~5, 기본 3)·문장별(가장 늦게 친 사람)·시간별(간격마다 가장 적게 친 사람)·시간 초과.
  서바이벌은 문제마다 시간이 0.9배씩 줄어(900타 + 1초 아래로는 안 줄어) 반드시 끝나고, 모두 한꺼번에 탈락하게 되면 아무도 탈락하지 않음.
  제한 시간 자동(글 길이)/10초~5분/무제한, 타임어택 30초~2분, 3초 카운트다운, 라운드 결과 6초.
- 타수: 두벌식 자판 수(겹모음·겹받침 2타), 조합 중 글자는 친 자판까지 맞은 것으로, 정확도 = 1 − 편집 거리/길이.
  붙여 넣기 막기: 화면에서 막고 서버는 2,400타/분 + 0.15초보다 빠른 정답을 거절, 진행 막대도 그 속도 이상 못 앞섬.
- 진행은 stream 액션(progress)이라 서버는 이벤트만 전달(보기 재계산·DB 쓰기 없이 묶어서 저장).
- 글 묶음 37개 주제: 한국어 단어 8(과일·동물·채소·나라·음식·직업·스포츠·사자성어), 짧은글 4(속담·명언·잰말놀이·일상 문장),
  긴글 11(애국가·별 헤는 밤·서시·진달래꽃·산유화·님의 침묵·훈민정음 서문·전래 동화 3), 영어 단어 7·짧은글 4·긴글 7.
  시는 위키문헌 원문과 대조해 현대 맞춤법으로. 일반 자판 글자만(테스트로 확인), 긴 줄은 띄어쓰기에서 나눔.
- 컴퓨터(live): 레벨에 따라 120~620타(영어 100~500), 읽는 시간, 오타 확률. 함께 치기는 틀리면 고쳐서 다시.
- 화면: 글자별 초록/빨강/조합 중 표시, 긴글은 단락 전체와 지금 줄(자동 스크롤), 다음 두 줄 미리 보기, 한글 조합 중 Enter 처리,
  한/영 경고, 지금 타수·정확도, 모두의 진행 막대(실시간)·목숨 하트, "먼저 쳤어요"/"탈락" 띠, 라운드 결과 표, 소리, 휴대폰.
- 등록: GAMES·LIVE_BOT_STRATEGIES·BOT_GAMES·CATALOG·GAME_UI·아이콘 ⌨️·파티 탭, README(43개), docs/games/typing.md.
- 테스트: 규칙 34·타수/글 묶음 9·컴퓨터 12·방 통합 4·웹 도움말 3, e2e games.e2e.ts typing·typingSpeed·typingSurvival.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-12 12:39:37 +09:00
parent f793391b79
commit fffb860282
25 changed files with 4130 additions and 7 deletions

View File

@@ -0,0 +1,86 @@
/**
* 타자 대결 computer players (docs/games/typing.md §10). A live bot like 사과 게임's: it types on its own timer, sends
* its progress now and then (so its bar moves like a person's) and presses Enter when it has typed the whole item.
* It only reads its own screen (`view`).
*
* The level (1~60) sets how it types, like a person getting better:
* - speed: about 120타 a minute at level 1 … 620타 at level 60 (English: 100 … 500 letters a minute),
* - a moment to read before typing (0.9 s … 0.35 s),
* - typos: a weak computer often makes one in a sentence; a strong one rarely. In 가장 먼저 입력 and 서바이벌 a typo
* is noticed when Enter is refused, then fixed; in the other modes it stays in the line (lower accuracy).
* The computer's own pace (`persona.pace`) makes some a little quicker or slower than others of the same level.
*/
import type { LiveBotDecision, LiveBotInput } from '../bots/types';
import { keyCount } from './keys';
import type { TypingClientAction, TypingView } from './types';
type In = LiveBotInput<TypingView>;
const DEFAULT_LEVEL = 30;
export const skillOf = (level: number | undefined): number => Math.max(0, Math.min(1, ((level ?? DEFAULT_LEVEL) - 1) / 59));
/** Keystrokes a minute at this skill (before the computer's own pace). */
export const botKpm = (skill: number, lang: 'ko' | 'en') => (lang === 'ko' ? 120 + 500 * skill : 100 + 400 * skill);
/** One wrong letter somewhere in the middle of the text. */
export function withTypo(text: string, random: () => number): string {
const chars = [...text];
if (!chars.length) return 'ㅋ';
const i = Math.floor(random() * chars.length);
const ko = /[가-힣]/.test(text);
const pool = ko ? '가나다라마바사아자차카타파하' : 'abcdefghijklmnopqrstuvwxyz';
let c = pool[Math.floor(random() * pool.length)]!;
if (c === chars[i]) c = ko ? '흐' : 'q';
chars[i] = c;
return chars.join('');
}
interface Plan {
key: string;
/** When typing (after reading) began, when it will be done. */
from: number;
doneAt: number;
typo: boolean;
}
export function typingBot({ me, view: v, now, random, persona, level, memory }: In): LiveBotDecision<TypingClientAction> {
if (v.phase === 'ended') return { action: null, next: 10_000 };
if (v.phase !== 'playing') return { action: null, next: Math.max(100, (v.phaseEndsAt ?? now + 1000) - now + 60) };
const seat = v.seats.find((s) => s.id === me);
if (!seat || !seat.alive || seat.finished) return { action: null, next: 1500 };
const item = v.upcoming[0];
const shared = v.flow === 'shared';
if (!item) return { action: null, next: shared ? Math.max(100, v.curAt - now + 60) : 1000 };
if (shared && seat.solved) return { action: null, next: 700 };
const skill = skillOf(level);
const key = `${v.round}:${item.idx}`;
let plan = memory.plan as Plan | undefined;
if (!plan || plan.key !== key) {
const speed = botKpm(skill, v.options.lang) / (0.75 + 0.25 * persona.pace) * (0.85 + 0.3 * random());
const read = (900 - 550 * skill) * (0.7 + 0.6 * random());
const start = shared ? Math.max(now, v.curAt) : now;
const keys = keyCount(item.text);
const typoChance = Math.min(0.7, (0.35 - 0.31 * skill) * Math.max(0.3, keys / 40));
plan = { key, from: start + read, doneAt: start + read + (keys * 60_000) / speed, typo: random() < typoChance };
memory.plan = plan;
}
if (now < plan.doneAt) {
const frac = Math.max(0, Math.min(1, (now - plan.from) / Math.max(1, plan.doneAt - plan.from)));
const chars = [...item.text];
const typed = chars.slice(0, Math.floor(chars.length * frac)).join('');
const wait = Math.min(Math.round(350 + random() * 300), Math.max(60, Math.ceil(plan.doneAt - now)));
return typed ? { action: { type: 'progress', item: item.idx, text: typed }, next: wait } : { action: null, next: wait };
}
if (plan.typo) {
const text = withTypo(item.text, random);
if (shared) {
// Enter is refused: it looks for the mistake and fixes it.
plan.typo = false;
plan.from = now;
plan.doneAt = now + 500 + (1600 - 1000 * skill) * (0.6 + 0.8 * random());
return { action: { type: 'submit', item: item.idx, text }, next: Math.ceil(plan.doneAt - now) };
}
return { action: { type: 'submit', item: item.idx, text }, next: 120 };
}
return { action: { type: 'submit', item: item.idx, text: item.text }, next: shared ? 600 : 120 };
}