원카드: 카드 내기와 원카드 외치기 분리(내면서 외치기 없앰), 잡기 전 보호 시간(1~3초, 기본 2초), 컴퓨터도 사람처럼 늦게 외치고 잡기, 한 턴 시간 무제한, 원카드 보너스 옵션
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
import { secureRandom, type AnyGameDefinition } from '@bg/engine';
|
||||
import { isBotId } from '@bg/shared';
|
||||
import { LIVE_BOT_STRATEGIES, botCandidates, botPace, botPersona, decideBotAction, idLevel, type LiveBotStrategy } from '@bg/games/bots';
|
||||
import { LIVE_BOT_STRATEGIES, botCandidates, botPace, botPersona, botReactionAt, decideBotAction, idLevel, type LiveBotStrategy } from '@bg/games/bots';
|
||||
|
||||
import type { BotBrain } from '../ai/brain';
|
||||
|
||||
@@ -39,6 +39,8 @@ export interface BotDelayInput {
|
||||
bot: string;
|
||||
/** The same bot just acted and is still on (e.g. yacht keep → roll): it already knows what it wants. */
|
||||
followUp: boolean;
|
||||
/** An out-of-turn reaction the game timed itself (원카드 외치기·잡기, `botReactionAt`): wait exactly this long. */
|
||||
reactMs?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +51,7 @@ export interface BotDelayInput {
|
||||
*/
|
||||
export function defaultBotDelay(input: BotDelayInput, random: () => number = secureRandom): 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);
|
||||
@@ -68,6 +71,8 @@ export class BotDriver {
|
||||
dueAt: number | null = null;
|
||||
/** Bot the planned action is for. */
|
||||
private planned: string | null = null;
|
||||
/** The planned action is that bot's out-of-turn reaction due at this time (not its normal move). */
|
||||
private plannedReact: number | null = null;
|
||||
/** Bot whose action is being played right now: if it is still on afterwards, its next move is a follow-up. */
|
||||
private acting: string | null = null;
|
||||
/** Live games (마피아): when each computer looks at the game again, and its notes for the current game. */
|
||||
@@ -87,26 +92,65 @@ export class BotDriver {
|
||||
/** Plans the next bot action if the game is waiting on a bot. Keeps an already planned one (the bot is "thinking"). */
|
||||
schedule(): void {
|
||||
if (this.liveStrategy()) return this.scheduleLive();
|
||||
if (this.dueAt !== null || this.busy) return;
|
||||
if (this.busy) return;
|
||||
if (this.dueAt !== null) {
|
||||
// A planned reaction the moment has passed for (someone called first): plan again; anything else stays planned.
|
||||
if (this.plannedReact === null || this.reactionDue()?.bot === this.planned) return;
|
||||
if (this.timer) clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
this.dueAt = null;
|
||||
this.planned = null;
|
||||
this.plannedReact = null;
|
||||
}
|
||||
const next = this.next();
|
||||
if (!next) return;
|
||||
// People can see it think: "생각 중…" until it moves.
|
||||
if (this.room.brain?.enabled()) this.room.brain.thinking(next.bot, true);
|
||||
const react = this.reactionDue();
|
||||
if (!next && !react) return;
|
||||
const now = this.room.now();
|
||||
let ms = this.delay({ choices: next.choices, withPeople: next.withPeople, bot: next.bot, followUp: next.bot === this.acting });
|
||||
const deadline = this.room.deadline?.() ?? null;
|
||||
if (deadline !== null) ms = Math.min(ms, Math.max(0, (deadline - now) * BOT_DEADLINE_SHARE));
|
||||
let ms = Infinity;
|
||||
if (next) {
|
||||
ms = this.delay({ choices: next.choices, withPeople: next.withPeople, bot: next.bot, followUp: next.bot === this.acting });
|
||||
const deadline = this.room.deadline?.() ?? null;
|
||||
if (deadline !== null) ms = Math.min(ms, Math.max(0, (deadline - now) * BOT_DEADLINE_SHARE));
|
||||
}
|
||||
// An out-of-turn reaction (원카드!) comes first when it is due earlier; it is not squeezed by the turn clock, so a
|
||||
// slow computer can really be late.
|
||||
if (react) {
|
||||
const rms = this.delay({ choices: 1, withPeople: true, bot: react.bot, followUp: false, reactMs: react.at - now });
|
||||
if (rms <= ms) {
|
||||
this.dueAt = now + rms;
|
||||
this.planned = react.bot;
|
||||
this.plannedReact = react.at;
|
||||
return this.arm();
|
||||
}
|
||||
}
|
||||
// People can see it think: "생각 중…" until it moves.
|
||||
if (this.room.brain?.enabled()) this.room.brain.thinking(next!.bot, true);
|
||||
this.dueAt = now + ms;
|
||||
this.planned = next.bot;
|
||||
this.planned = next!.bot;
|
||||
this.plannedReact = null;
|
||||
this.arm();
|
||||
}
|
||||
|
||||
/** The earliest out-of-turn reaction of a computer that may act now (games with `BOT_REACTIONS`). */
|
||||
private reactionDue(): { bot: string; at: number } | null {
|
||||
const g = this.room.game;
|
||||
if (!g || g.finished || this.room.status !== 'playing') return null;
|
||||
let best: { bot: string; at: number } | null = null;
|
||||
for (const p of g.players) {
|
||||
if (!isBotId(p)) continue;
|
||||
const at = botReactionAt(this.room.def, g.state, p, this.room.profile?.(p).level ?? idLevel(p));
|
||||
if (typeof at === 'number' && (!best || at < best.at)) best = { bot: p, at };
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
cancel(): void {
|
||||
if (this.timer) clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
if (this.planned) this.room.brain?.thinking(this.planned, false);
|
||||
this.dueAt = null;
|
||||
this.planned = null;
|
||||
this.plannedReact = null;
|
||||
this.liveDue.clear();
|
||||
}
|
||||
|
||||
@@ -219,8 +263,11 @@ export class BotDriver {
|
||||
const active = def.activePlayers(g.state);
|
||||
const waiting = new Set([...active, ...(def.timeoutPlayers?.(g.state) ?? [])]);
|
||||
const withPeople = active.some((p) => !isBotId(p));
|
||||
const timed = new Set(def.timeoutPlayers?.(g.state) ?? active);
|
||||
for (const p of g.players) {
|
||||
if (!isBotId(p) || !waiting.has(p)) continue;
|
||||
// Only there to react out of turn (원카드!): `reactionDue` times that, not the thinking time.
|
||||
if (!timed.has(p) && botReactionAt(def, g.state, p, this.room.profile?.(p).level ?? idLevel(p)) !== null) continue;
|
||||
const choices = botCandidates(def, g.state, p).length;
|
||||
if (choices > 0) return { bot: p, choices, withPeople };
|
||||
}
|
||||
@@ -239,13 +286,16 @@ export class BotDriver {
|
||||
return this.fireLive(live);
|
||||
}
|
||||
const planned = this.planned;
|
||||
const wasReact = this.plannedReact !== null;
|
||||
this.dueAt = null;
|
||||
this.planned = null;
|
||||
const next = this.next();
|
||||
this.plannedReact = null;
|
||||
const react = wasReact ? this.reactionDue() : null;
|
||||
const next = wasReact ? (react && react.bot === planned ? { bot: react.bot } : null) : this.next();
|
||||
const g = this.room.game;
|
||||
if (!next || !g) return;
|
||||
// Another bot's turn came up meanwhile: give it its own thinking time.
|
||||
if (next.bot !== planned) return this.schedule();
|
||||
if (!g) return;
|
||||
// Another bot's turn came up meanwhile (or the reaction is moot): give it its own thinking time.
|
||||
if (!next || next.bot !== planned) return this.schedule();
|
||||
const def = this.room.def;
|
||||
const t0 = performance.now();
|
||||
let action: unknown;
|
||||
@@ -258,7 +308,8 @@ 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) });
|
||||
const brain = this.room.brain;
|
||||
if (brain && action != null && brain.enabled()) {
|
||||
// A reaction (원카드!) is a reflex: no chat before it.
|
||||
if (brain && action != null && brain.enabled() && !wasReact) {
|
||||
// Like a person: maybe type something first (the model writes it; "입력 중…" while typing), then move.
|
||||
const bot = next.bot;
|
||||
this.busy = bot;
|
||||
|
||||
Reference in New Issue
Block a user