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

@@ -1,7 +1,7 @@
/** 방: 대기실 ↔ 게임 ↔ 결과를 한 주소에서 전환 (docs/06 §5–§9). */
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react';
import { Link, useNavigate, useParams } from 'react-router';
import { botsAllowed, formatRoomCode, isBotId, type PublicUser, type RoomView } from '@bg/shared/lite';
import { BOT_BANDS, BOT_PICKS, BOT_PICK_LABEL, bandOf, botsAllowed, formatRoomCode, isBotId, luckLabel, type PublicUser, type RoomView } from '@bg/shared/lite';
import { Avatar, CodeLabel, ConfirmSheet, CopyButton, ShareButton, Sheet, TopBar } from '../components/ui';
import { GuestWarning, NicknameForm } from '../components/NicknameForm';
import { GameNotice, gameName } from '../components/GameNotice';
@@ -88,7 +88,7 @@ function RoomGone({ message }: { message: string }) {
function Room({ code, me }: { code: string; me: PublicUser }) {
const nav = useNavigate();
const { room, game, result, status, joinError, pending, slow, needsRefresh } = useRoom();
const { room, game, result, status, joinError, pending, slow } = useRoom();
const [ui, setUi] = useState<GameUI | null>(null);
const [leaveAsk, setLeaveAsk] = useState(false);
const [chatOpen, setChatOpen] = useState(false);
@@ -224,14 +224,6 @@ function Room({ code, me }: { code: string; me: PublicUser }) {
</button>
</div>
</nav>
{needsRefresh && (
<div className="card row" style={{ margin: 12, justifyContent: 'space-between' }}>
<span>새 버전이 있어요.</span>
<button className="btn btn-primary btn-sm" onClick={() => location.reload()}>
새로고침
</button>
</div>
)}
{inGame && game ? (
<GameView room={room} ui={ui} me={me} players={players} pending={pending !== null} slow={slow} />
) : (
@@ -331,18 +323,38 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
<div style={{ display: 'grid', gridTemplateColumns: wide ? `repeat(${room.seats.length > 4 ? 3 : 2}, minmax(0, 1fr))` : '1fr', gap: 10 }}>
{room.seats.map((s, i) =>
s && isBotId(s.user.id) ? (
<div key={i} className="card row" style={{ gap: 12, flexWrap: 'nowrap' }}>
<Avatar user={s.user} size={44} />
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontWeight: 700 }}>{s.user.nickname}</div>
<div className="row small" style={{ gap: 6 }}>
<span className="badge">🤖 컴퓨터</span>
<div key={i} className="card stack" style={{ gap: 10 }}>
<div className="row" style={{ gap: 12, flexWrap: 'nowrap' }}>
<Avatar user={s.user} size={44} />
<div style={{ flex: 1, minWidth: 0 }}>
<div style={{ fontWeight: 700 }}>{s.user.nickname}</div>
<div className="row small" style={{ gap: 6 }}>
<span className="badge">🤖 컴퓨터</span>
{!isHost && <span className="badge">난이도 {BOT_PICK_LABEL[room.botPicks?.[s.user.id] ?? 'random']}</span>}
</div>
</div>
{isHost && (
<button className="btn btn-ghost" onClick={() => socket.send({ t: 'removeBot', userId: s.user.id })} aria-label={`${s.user.nickname} 빼기`}>
✕
</button>
)}
</div>
{/* docs/06 §12: 랜덤 = any level 1~60; a band = a random level inside it. The level shows after the game. */}
{isHost && (
<button className="btn btn-ghost" onClick={() => socket.send({ t: 'removeBot', userId: s.user.id })} aria-label={`${s.user.nickname} 빼기`}>
✕
</button>
<div className="segmented bot-level" role="group" aria-label={`${s.user.nickname} 난이도`}>
{BOT_PICKS.map((p) => (
<button
key={p}
type="button"
aria-pressed={(room.botPicks?.[s.user.id] ?? 'random') === p}
disabled={room.starting}
title={p === 'random' ? '1~60단계 중 무작위' : `${BOT_BANDS[p][0]}~${BOT_BANDS[p][1]}단계 중 무작위`}
onClick={() => socket.send({ t: 'botLevel', userId: s.user.id, pick: p })}
>
{BOT_PICK_LABEL[p]}
</button>
))}
</div>
)}
</div>
) : s ? (
@@ -428,8 +440,8 @@ function Lobby({ room, ui, me }: { room: RoomView; ui: GameUI; me: PublicUser })
<div className="bottom-bar inline-wide">
<div className="bottom-bar-inner">
{isHost ? (
<button className="btn btn-primary" style={{ minHeight: 64, fontSize: '1.2rem' }} disabled={need > 0} onClick={() => (notReady > 0 ? setAskStart(true) : socket.send({ t: 'start' }))}>
{need > 0 ? `${need}명 더 필요해요` : '▶ 게임 시작'}
<button className="btn btn-primary" style={{ minHeight: 64, fontSize: '1.2rem' }} disabled={need > 0 || room.starting} onClick={() => (notReady > 0 ? setAskStart(true) : socket.send({ t: 'start' }))}>
{room.starting ? '🃏 섞는 중…' : need > 0 ? `${need}명 더 필요해요` : '▶ 게임 시작'}
</button>
) : mySeat >= 0 ? (
room.seats[mySeat]!.ready ? (
@@ -751,7 +763,7 @@ function ResultPanel({ room, me, players, onLeave, onAgain }: { room: RoomView;
방 나가기
</button>
{room.lastSeed && (
<FairnessCheck seedHash={room.seedHash} seed={room.lastSeed} />
<FairnessCheck seedHash={room.seedHash} seed={room.lastSeed} bots={room.lastBots} shuffles={room.lastShuffles} players={players} />
)}
</Sheet>
);
@@ -761,7 +773,19 @@ function ResultPanel({ room, me, players, onLeave, onAgain }: { room: RoomView;
* docs/04 §5: the seed's SHA-256 was published when the game started; the seed is revealed at the end.
* The browser recomputes the hash itself so players don't have to trust the server's word.
*/
function FairnessCheck({ seedHash, seed }: { seedHash: string | null; seed: string }) {
function FairnessCheck({
seedHash,
seed,
bots,
shuffles,
players,
}: {
seedHash: string | null;
seed: string;
bots?: RoomView['lastBots'];
shuffles?: number;
players: Record<string, PublicUser>;
}) {
const [verdict, setVerdict] = useState<null | boolean>(null);
const check = async () => {
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(seed));
@@ -771,6 +795,17 @@ function FairnessCheck({ seedHash, seed }: { seedHash: string | null; seed: stri
return (
<details className="small muted">
<summary>공정성 확인</summary>
{/* docs/09 §9.1: each computer's level (1~60) and luck in this game; docs/04 §5.1: shuffles tried for luck. */}
{bots && Object.keys(bots).length > 0 && (
<div className="stack" style={{ gap: 4, margin: '8px 0' }}>
{Object.entries(bots).map(([id, b]) => (
<p key={id} style={{ margin: 0 }}>
🤖 {players[id]?.nickname ?? '컴퓨터'}: 난이도 <strong>{b.level}단계</strong> ({BOT_PICK_LABEL[bandOf(b.level)]}) · 운 {luckLabel(b.luck)}
</p>
))}
{(shuffles ?? 1) > 1 && <p style={{ margin: 0 }}>이번 판은 컴퓨터의 운에 맞춰, 미리 섞어 본 {shuffles}가지 중 하나로 시작했어요. 고른 결과는 시작할 때 아래 값으로 공개했어요.</p>}
</div>
)}
<p>시작할 때 공개한 값(SHA-256): {seedHash ?? '-'}</p>
<p>끝나고 공개한 난수 씨앗: {seed}</p>
<button type="button" className="btn btn-secondary btn-sm" onClick={check}>