게임 속도 배율: 1배도 애니메이션·연출·컴퓨터 생각 시간을 예전의 1.5배로 늦추고, 관리자 사이트 설정 "게임 속도 배율"(1/16~16배, 기본 1)로 나눠 조절. 저장하면 열린 방에도 바로 적용(RoomView.gameSpeed 재전송)
- 서버: SiteSettings.gameSpeed, /api/config에 노출, 컴퓨터 생각 시간(defaultBotDelay)과 마피아·라이어 컴퓨터가 살펴보는 간격에 BOT_SLOWDOWN(1.5)/배율. 게임이 정한 반응 시각(원카드 외치기)은 그대로 - 웹: lib/motion.ts — .game-layout 안 CSS 애니메이션·트랜지션은 useMotionScope가 playbackRate로, Web Animations는 fxAnim, 연출 타이머(배너 유지·다음 단계·복사본 정리·숫자 세기·다시 보기 한 칸)는 fxMs. 채팅·role="timer"·규칙 시간·꾹 눌러 보기는 제외 - 관리자 사이트 탭에 배율 버튼(1/16~16)과 직접 입력 - 테스트: 배율 검증(API 400/200, 열린 방 즉시 반영), 컴퓨터 생각 시간 배율, motion 단위 테스트, e2e/speed.e2e.ts(돌 애니메이션 재생 배율·컴퓨터 응답 시간), 관리자 e2e에 배율 저장 - 문서: 14-admin §5, 07-ui-ux, 06-lobby-rooms, 13-decisions, README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -196,6 +196,33 @@ describe('site settings, rooms, users', () => {
|
||||
expect((await chat).text).toBe('너 **야');
|
||||
});
|
||||
|
||||
test('game speed: 1/16~16 (default 1), shown in /api/config, out of range rejected', async () => {
|
||||
const s = start();
|
||||
const sup = await discordLogin(s, SUPER);
|
||||
const site = (await api(s.base, '/api/admin/site', { cookie: sup.cookie })).body.site;
|
||||
expect(site.gameSpeed).toBe(1);
|
||||
expect((await api(s.base, '/api/config')).body.gameSpeed).toBe(1);
|
||||
for (const bad of [0, 1 / 32, 17, -1]) {
|
||||
const r = await api(s.base, '/api/admin/site', { method: 'PUT', cookie: sup.cookie, body: JSON.stringify({ ...site, gameSpeed: bad }) });
|
||||
expect(r.res.status).toBe(400);
|
||||
}
|
||||
for (const ok of [1 / 16, 16, 0.75]) {
|
||||
const r = await api(s.base, '/api/admin/site', { method: 'PUT', cookie: sup.cookie, body: JSON.stringify({ ...site, gameSpeed: ok }) });
|
||||
expect(r.res.status).toBe(200);
|
||||
expect((await api(s.base, '/api/config')).body.gameSpeed).toBe(ok);
|
||||
}
|
||||
// An open room gets the new speed at once (its screen's animations follow it).
|
||||
const g = await guest(s.base, '방장님');
|
||||
const room = await api(s.base, '/api/rooms', { method: 'POST', cookie: g.cookie, body: JSON.stringify({ gameId: 'omok' }) });
|
||||
const c = await new Client(s.base, g.cookie, g.id).connect();
|
||||
clients.push(c);
|
||||
c.send({ t: 'join', code: room.body.code, as: 'player' });
|
||||
expect((await c.next('room')).room.gameSpeed).toBe(0.75);
|
||||
const next = c.next('room');
|
||||
await api(s.base, '/api/admin/site', { method: 'PUT', cookie: sup.cookie, body: JSON.stringify({ ...site, gameSpeed: 2 }) });
|
||||
expect((await next).room.gameSpeed).toBe(2);
|
||||
});
|
||||
|
||||
test('admin closes a room: everyone is told and disconnected from it', async () => {
|
||||
const s = start();
|
||||
const sup = await discordLogin(s, SUPER);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import type { Database } from 'bun:sqlite';
|
||||
import { z } from 'zod';
|
||||
import type { AnyGameDefinition } from '@bg/engine';
|
||||
import { CATALOG, type CatalogEntry } from '@bg/shared';
|
||||
import { CATALOG, GAME_SPEED_DEFAULT, GAME_SPEED_MAX, GAME_SPEED_MIN, type CatalogEntry } from '@bg/shared';
|
||||
|
||||
export const SiteSettingsSchema = z.object({
|
||||
siteName: z.string().trim().min(1).max(40).default('같이 놀자 보드게임'),
|
||||
@@ -17,6 +17,8 @@ export const SiteSettingsSchema = z.object({
|
||||
graceSec: z.number().int().min(10).max(600).default(60),
|
||||
chatEnabledDefault: z.boolean().default(true),
|
||||
chatFilterDefault: z.boolean().default(true),
|
||||
/** Animations and the computers' thinking time are divided by this (applies at once, also to running games). */
|
||||
gameSpeed: z.number().min(GAME_SPEED_MIN).max(GAME_SPEED_MAX).default(GAME_SPEED_DEFAULT),
|
||||
});
|
||||
export type SiteSettings = z.infer<typeof SiteSettingsSchema>;
|
||||
|
||||
|
||||
@@ -93,6 +93,8 @@ export function createAdminApp(d: AdminDeps) {
|
||||
const before = d.settings.getSite();
|
||||
d.settings.setSite(parsed.data, actor(c));
|
||||
d.audit.log(actor(c), 'site.update', null, before, parsed.data);
|
||||
// The game speed applies at once: open rooms get it with a fresh room view (their animations follow it).
|
||||
if (before.gameSpeed !== parsed.data.gameSpeed) for (const r of d.rooms.all()) r.broadcastRoom();
|
||||
return c.json({ site: parsed.data });
|
||||
});
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ export function createHttpApp(d: HttpDeps) {
|
||||
siteName: site.siteName,
|
||||
announcement: site.announcement,
|
||||
maintenance: site.maintenance,
|
||||
gameSpeed: site.gameSpeed,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { BOT_STRATEGIES, LIVE_BOT_STRATEGIES, botReactionAt } from '@bg/games/bo
|
||||
import { classicDeck, type OneCardState } from '@bg/games/one-card';
|
||||
import { BOT_GAMES, ClientMessage, botProfile, isBotId, type ServerMessage } from '@bg/shared';
|
||||
import { openDb } from '../db';
|
||||
import { SiteSettingsSchema, type SettingsStore } from '../admin/settings';
|
||||
import { botPace, defaultBotDelay, type BotDelayInput } from './bots';
|
||||
import { RoomManager } from './manager';
|
||||
import { Room, type Conn, type RoomSnapshot } from './room';
|
||||
@@ -89,6 +90,41 @@ describe('bot list', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('game speed scales the thinking time, but not a reaction the game timed itself', () => {
|
||||
const bot = 'bot:1:01J0000000000000000000000';
|
||||
const r = () => 0.5;
|
||||
const input = { choices: 4, withPeople: true, bot, followUp: false };
|
||||
expect(defaultBotDelay(input, r, 3)).toBe(Math.round((2600 * botPace(bot) + 1500) * 3));
|
||||
expect(defaultBotDelay(input, r, 0.25)).toBe(Math.round((2600 * botPace(bot) + 1500) * 0.25));
|
||||
expect(defaultBotDelay({ ...input, reactMs: 800 }, r, 3)).toBe(800);
|
||||
});
|
||||
|
||||
test('the admin game speed reaches the computers (×1.5 slower base) and the room view', () => {
|
||||
let speed = 1 / 16;
|
||||
const db = openDb(':memory:');
|
||||
let now = 1_000_000;
|
||||
const users = { publicUser: (id: string) => botProfile(id) ?? { id, nickname: id, avatar: null, kind: 'guest' as const } };
|
||||
const settings = { game: () => null, getSite: () => SiteSettingsSchema.parse({ gameSpeed: speed }) } as unknown as SettingsStore;
|
||||
const manager = new RoomManager({ store: new RoomStore(db), games: GAMES, users, now: () => now, settings });
|
||||
const play = () => {
|
||||
const room = manager.createPractice('A', 'omok') as Room;
|
||||
rooms.push(room);
|
||||
room.join({ userId: 'A', send: () => {}, close: () => {} }, 'player');
|
||||
room.configure('A', { options: { ...(room.config.options as object), colorAssignment: 'hostBlack' } });
|
||||
expect(room.start('A')).toBeNull();
|
||||
room.act('A', 1, { type: 'place', x: 7, y: 7 });
|
||||
expect(room.roomView().gameSpeed).toBe(speed);
|
||||
return room.bots.dueAt! - now;
|
||||
};
|
||||
// 1/16: at least the shortest thought (0.49 s) × 1.5 × 16, though never past half the 30 s turn timer.
|
||||
const slow = play();
|
||||
expect(slow).toBeGreaterThanOrEqual(11_000);
|
||||
expect(slow).toBeLessThanOrEqual(15_000);
|
||||
speed = 16;
|
||||
// ×16: at most the longest thought (10.4 s) × 1.5 / 16.
|
||||
expect(play()).toBeLessThanOrEqual(1000);
|
||||
});
|
||||
|
||||
test('thinking never takes more than half of the time left on the turn timer', () => {
|
||||
const h = harness(undefined, undefined, () => 60 * 60_000);
|
||||
const room = h.manager.createPractice('A', 'omok') as Room;
|
||||
|
||||
@@ -27,6 +27,8 @@ export interface BotRoom {
|
||||
profile?(bot: string): { level: number; base: number };
|
||||
/** The computers' talk and visible activity with the local model (docs/06 §12.1). */
|
||||
brain?: BotBrain;
|
||||
/** Multiplies the computers' thinking time and live games' look intervals (game speed, docs/14 §5); absent = 1. */
|
||||
timeScale?(): number;
|
||||
}
|
||||
|
||||
/** What a planned computer move looks like, for its thinking time. */
|
||||
@@ -47,18 +49,23 @@ export interface BotDelayInput {
|
||||
* Human-like thinking time (ms). A forced move still takes a moment to notice (0.7~1.3 s); a real choice takes longer
|
||||
* the more moves there are (1.6~3.9 s), and now and then the computer hesitates (+1~3 s). Each bot scales it by its
|
||||
* own pace, and a follow-up move of the same turn is quicker. When people may act in the same window the computer
|
||||
* waits 1.5 s more so it never beats a person to a reaction just by being fast.
|
||||
* waits 1.5 s more so it never beats a person to a reaction just by being fast. `scale` (game speed, `BOT_SLOWDOWN /
|
||||
* speed`) multiplies the whole thinking time; a reaction the game timed itself (`reactMs`) is never scaled, so who
|
||||
* calls first stays fair.
|
||||
*/
|
||||
export function defaultBotDelay(input: BotDelayInput, random: () => number = secureRandom): number {
|
||||
export function defaultBotDelay(input: BotDelayInput, random: () => number = secureRandom, scale = 1): number {
|
||||
const { choices, withPeople, bot, followUp } = input;
|
||||
if (input.reactMs !== undefined) return Math.max(0, Math.round(input.reactMs));
|
||||
let ms = choices <= 1 ? 700 + random() * 600 : 1300 + 300 * Math.min(Math.log2(choices), 4) + random() * 1400;
|
||||
if (choices > 1 && !followUp && random() < 0.12) ms += 1000 + random() * 2000;
|
||||
ms *= botPace(bot);
|
||||
if (followUp) ms *= 0.5;
|
||||
return Math.round(withPeople ? ms + 1500 : ms);
|
||||
return Math.round((withPeople ? ms + 1500 : ms) * scale);
|
||||
}
|
||||
|
||||
/** At game speed ×1 the computers take this much longer than `defaultBotDelay`'s base times (2026-10-14: a bit slower). */
|
||||
export const BOT_SLOWDOWN = 1.5;
|
||||
|
||||
/** Never use more than this share of the time left on the turn timer for thinking. */
|
||||
export const BOT_DEADLINE_SHARE = 0.5;
|
||||
|
||||
@@ -86,7 +93,7 @@ export class BotDriver {
|
||||
constructor(
|
||||
private room: BotRoom,
|
||||
private random: () => number = secureRandom,
|
||||
private delay: (input: BotDelayInput) => number = (input) => defaultBotDelay(input, random),
|
||||
private delay: (input: BotDelayInput) => number = (input) => defaultBotDelay(input, random, room.timeScale?.() ?? 1),
|
||||
) {}
|
||||
|
||||
/** Plans the next bot action if the game is waiting on a bot. Keeps an already planned one (the bot is "thinking"). */
|
||||
@@ -154,6 +161,10 @@ export class BotDriver {
|
||||
this.liveDue.clear();
|
||||
}
|
||||
|
||||
private timeScale(): number {
|
||||
return this.room.timeScale?.() ?? 1;
|
||||
}
|
||||
|
||||
private liveStrategy(): LiveBotStrategy | null {
|
||||
return LIVE_BOT_STRATEGIES[this.room.def.id] ?? null;
|
||||
}
|
||||
@@ -177,7 +188,7 @@ export class BotDriver {
|
||||
}
|
||||
const now = this.room.now();
|
||||
for (const p of g.players) {
|
||||
if (isBotId(p) && !this.liveDue.has(p)) this.liveDue.set(p, now + Math.round((300 + this.random() * 1200) * botPace(p)));
|
||||
if (isBotId(p) && !this.liveDue.has(p)) this.liveDue.set(p, now + Math.round((300 + this.random() * 1200) * botPace(p) * this.timeScale()));
|
||||
}
|
||||
const next = Math.min(...this.liveDue.values());
|
||||
this.dueAt = Number.isFinite(next) ? next : null;
|
||||
@@ -210,7 +221,7 @@ export class BotDriver {
|
||||
}
|
||||
const ms = performance.now() - t0;
|
||||
if (ms > BOT_SLOW_MS) this.room.log?.('warn', 'slow bot move', { game: def.id, ms: Math.round(ms) });
|
||||
this.liveDue.set(bot, now + Math.max(100, decision.next));
|
||||
this.liveDue.set(bot, now + Math.max(100, Math.round(decision.next * this.timeScale())));
|
||||
if (decision.action == null) continue;
|
||||
if (!def.validate(g.state, bot, decision.action, { now }).ok) continue; // the moment passed (phase changed); look again later
|
||||
const brain = this.room.brain;
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
*/
|
||||
import { ulid } from 'ulid';
|
||||
import { SeededRng, createSeed, secureRandom, seedToHex, type AnyGameDefinition, type ChaChaSeed, type GameResult, type RngState } from '@bg/engine';
|
||||
import { botChatRequired, botsAllowed, isBotId, makeBotId, botNumber, maskProfanity, type BotPick, type PublicUser, type RoomView, type ServerMessage, type SeatView } from '@bg/shared';
|
||||
import { botChatRequired, clampGameSpeed, botsAllowed, isBotId, makeBotId, botNumber, maskProfanity, type BotPick, type PublicUser, type RoomView, type ServerMessage, type SeatView } from '@bg/shared';
|
||||
import { botPersona } from '@bg/games/bots';
|
||||
import { luckApplies, shufflesFor, type LuckJob } from '@bg/games/bots/luck';
|
||||
import { sha256Hex } from '../auth/sessions';
|
||||
import { BotDriver, type BotDelayInput } from './bots';
|
||||
import { BOT_SLOWDOWN, BotDriver, type BotDelayInput } from './bots';
|
||||
import { drift, newBotProfile, profileFromId, repick, type BotProfile } from './bot-profile';
|
||||
import { BotBrain, type BotActivity } from '../ai/brain';
|
||||
import type { Llm } from '../ai/llm';
|
||||
@@ -224,6 +224,7 @@ export class Room {
|
||||
nameOf: (id) => this.deps.users.publicUser(id)?.nickname ?? '누군가',
|
||||
profile: (bot) => this.profile(bot),
|
||||
brain: this.brain,
|
||||
timeScale: () => BOT_SLOWDOWN / this.gameSpeed(),
|
||||
},
|
||||
secureRandom,
|
||||
deps.botDelay,
|
||||
@@ -440,6 +441,7 @@ export class Room {
|
||||
...(this.starting ? { starting: true } : {}),
|
||||
// Levels are revealed only once the game is over (fairness check).
|
||||
...(this.game?.finished && this.game.bots ? { lastBots: this.game.bots, lastShuffles: this.game.shuffles ?? 1 } : {}),
|
||||
gameSpeed: this.gameSpeed(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -623,6 +625,11 @@ export class Room {
|
||||
}
|
||||
|
||||
/** A computer's level and luck; computers saved without one get it from their id. */
|
||||
/** Admin game speed (docs/14 §5), read live so a change reaches running games too. */
|
||||
gameSpeed(): number {
|
||||
return clampGameSpeed(this.deps.settings?.getSite().gameSpeed);
|
||||
}
|
||||
|
||||
profile(bot: string): BotProfile {
|
||||
return (this.botProfiles[bot] ??= profileFromId(bot));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user