컴퓨터 난이도 1~60단계·방장 선택·판마다 변화·운, 공정성 확인에 표기, 업데이트 알림 팝업

- 난이도 1~60(쉬움 1~20·보통 21~40·어려움 41~60): 넣을 때 랜덤, 방장이 대기실에서 [랜덤][쉬움][보통][어려움] 선택(botLevel) → 범위 안 무작위
- 다음 판마다 -2~+2, 처음 단계 ±5·같은 범위 안(drift); 말투는 처음 단계(>30 존댓말)
- humanBest 확률을 단계별로 보간(BOT_PLAY_ANCHORS: 1·10·30·50·60)
- 운(-1~+1): 카드·주사위 게임에서 시작 전에 시드 후보 1~5개를 작업 스레드에서 끝까지 둬 보고 운에 맞는 것을 고름(luck.ts, luck-worker.ts). 해시 공개는 그대로
- 결과 화면 공정성 확인에 컴퓨터별 단계·운, 섞어 본 후보 수
- 업데이트 알림: 빌드 ID meta + /api/version + welcome.build → 상단 팝업 [지금 새로고침하기] [✕]
- 문서 03·04 §5.1·06 §12·07 §11.1·09 §9.1, 테스트(bot-level.room, luck, version, e2e bots·pwa)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-11 17:46:13 +09:00
parent 3cbc3698d3
commit 84d64b27f2
40 changed files with 1349 additions and 133 deletions

View File

@@ -18,18 +18,18 @@ export function botPace(bot: string): number {
return 0.7 + ((h >>> 0) / 2 ** 32) * 0.8;
}
/** How well a computer plays (docs/09-game-engine.md §9.1). */
export type BotLevel = 'easy' | 'normal' | 'hard';
/** Share of computers at each level: 쉬움 35%, 보통 40%, 어려움 25%. */
export const BOT_LEVEL_ODDS: Readonly<Record<BotLevel, number>> = { easy: 0.35, normal: 0.4, hard: 0.25 };
/**
* How well a computer plays: level 1 (weakest) … 60 (strongest), docs/09-game-engine.md §9.1. 1~20 쉬움, 21~40 보통,
* 41~60 어려움. The room keeps each computer's level (it drifts a little between games); see `botPlay`.
*/
export type BotLevel = number;
const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
/**
* The computer's own die roll in [0, 1), read straight from the random part of its id: the server makes bot ids as
* `bot:<n>:<ULID>` with OS secure randomness (`secureRandom`), so the first 6 random characters are 30 uniform bits.
* Other ids (tests, hand-made) fall back to a hash. Fixed for the id, so the computer keeps its level after a restart.
* A fixed roll in [0, 1) for a bot id: the server makes bot ids as `bot:<n>:<ULID>` with OS secure randomness
* (`secureRandom`), so the first 6 random characters are 30 uniform bits. Other ids (tests, hand-made) fall back to a
* hash. Only used for computers saved before rooms kept a level per computer (and in tests).
*/
export function botDraw(bot: string): number {
const u = bot.split(':')[2] ?? '';
@@ -39,17 +39,13 @@ export function botDraw(bot: string): number {
return v / 32 ** 6;
}
export function levelOf(draw: number): BotLevel {
if (draw < BOT_LEVEL_ODDS.easy) return 'easy';
return draw < BOT_LEVEL_ODDS.easy + BOT_LEVEL_ODDS.normal ? 'normal' : 'hard';
}
/** Level 1~60 from the id alone, for computers without a saved level. */
export const idLevel = (bot: string): BotLevel => 1 + Math.floor(botDraw(bot) * 60);
export interface BotPersona {
/** 쉬움 / 보통 / 어려움: how often it slips in board games (`humanBest`). */
level: BotLevel;
/**
* 똑똑한 편(근거를 보고 추리, 존댓말) / 허술한 편(느낌과 분위기를 따름, 반말): half of the computers each, by the
* same roll as the level — every 쉬움 is 허술, every 어려움 똑똑, 보통 split in two.
* 똑똑한 편(근거를 보고 추리, 존댓말) / 허술한 편(느낌과 분위기를 따름, 반말): the computer's starting level is
* above 30 (the upper half of 보통 and every 어려움) or not, so a random computer is either with even odds.
*/
smart: boolean;
/** Reaction speed multiplier (`botPace`): 0.7 quick … 1.5 slow. */
@@ -58,7 +54,7 @@ export interface BotPersona {
chatty: number;
}
export function botPersona(bot: string): BotPersona {
const draw = botDraw(bot);
return { level: levelOf(draw), smart: draw >= 0.5, pace: botPace(bot), chatty: 0.5 + hash01(bot, 'chatty') * 0.5 };
/** `base` = the level the computer started with (the room's), or one from the id. */
export function botPersona(bot: string, base: BotLevel = idLevel(bot)): BotPersona {
return { smart: base > 30, pace: botPace(bot), chatty: 0.5 + hash01(bot, 'chatty') * 0.5 };
}