컴퓨터 난이도 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

@@ -0,0 +1,61 @@
/**
* "업데이트 내용이 있습니다" (docs/07 §11.1). The page knows its own build (`<meta name="bg-build">`, written by
* vite.config.ts); the server tells its build in `welcome` and at `/api/version`. When they differ the page offers a
* refresh at the top; ✕ hides it until the next update. Dev builds have no meta and never ask.
*/
import { useSyncExternalStore } from 'react';
const POLL_MS = 5 * 60_000;
const mine = typeof document === 'undefined' ? null : (document.querySelector<HTMLMetaElement>('meta[name="bg-build"]')?.content ?? null);
/** Build the server has that this page doesn't ('protocol' = the server speaks a newer protocol). */
let latest: string | null = null;
let dismissed: string | null = null;
const listeners = new Set<() => void>();
const emit = () => listeners.forEach((l) => l());
/** The server's build (welcome message, `/api/version`). */
export function noteServerBuild(build: string | null | undefined): void {
if (!mine || !build || build === mine || build === latest) return;
latest = build;
emit();
}
/** The server speaks a different protocol: this page must be refreshed whatever its build. */
export function markOutdated(): void {
if (latest) return;
latest = 'protocol';
emit();
}
export function dismissUpdate(): void {
dismissed = latest;
emit();
}
async function check(): Promise<void> {
try {
const res = await fetch('/api/version', { cache: 'no-store' });
if (res.ok) noteServerBuild(((await res.json()) as { build?: string | null }).build);
} catch {
// Offline or restarting: the next check (or the socket's welcome) will tell.
}
}
/** Call once at startup: checks now and then, and whenever the tab comes back into view. */
export function initUpdateCheck(): void {
if (!mine) return;
setInterval(() => void check(), POLL_MS);
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') void check();
});
}
const subscribe = (l: () => void) => {
listeners.add(l);
return () => void listeners.delete(l);
};
export function useUpdateAvailable(): boolean {
return useSyncExternalStore(subscribe, () => latest !== null && latest !== dismissed, () => false);
}