원카드: 카드 내기와 원카드 외치기 분리(내면서 외치기 없앰), 잡기 전 보호 시간(1~3초, 기본 2초), 컴퓨터도 사람처럼 늦게 외치고 잡기, 한 턴 시간 무제한, 원카드 보너스 옵션

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:15:18 +09:00
parent f12cf12b84
commit 28590df429
9 changed files with 378 additions and 57 deletions

View File

@@ -5,7 +5,7 @@
*/
import { secureRandom, type AnyGameDefinition, type PlayerId } from '@bg/engine';
import type { BotLevel } from './persona';
import type { BotStrategy, LiveBotStrategy } from './types';
import type { BotReaction, BotStrategy, LiveBotStrategy } from './types';
import { pick, playable, randomPolicy } from './policy';
import { omokBot } from '../omok/bot';
import { othelloBot } from '../othello/bot';
@@ -16,7 +16,7 @@ import { seotdaBot } from '../seotda/bot';
import { pokerBot } from '../poker/bot';
import { yachtBot } from '../yacht/bot';
import { yutBot } from '../yut/bot';
import { oneCardBot } from '../one-card/bot';
import { oneCardBot, oneCardReaction } from '../one-card/bot';
import { rummikubBot } from '../rummikub/bot';
import { gostopBot } from '../gostop/bot';
import { bangBot } from '../bang/bot';
@@ -38,7 +38,7 @@ import { unoBot } from '../uno/bot';
import { liarBot } from '../liar/bot';
import { magicalAthleteBot } from '../magical-athlete/bot';
export type { BotInput, BotStrategy, LiveBotDecision, LiveBotInput, LiveBotStrategy } from './types';
export type { BotInput, BotReaction, BotStrategy, LiveBotDecision, LiveBotInput, LiveBotStrategy } from './types';
export { botDraw, botPace, botPersona, hash01, idLevel, type BotLevel, type BotPersona } from './persona';
export { botPlay } from './policy';
@@ -73,6 +73,22 @@ export const BOT_STRATEGIES: Record<string, BotStrategy> = {
'magical-athlete': magicalAthleteBot,
};
/** Games whose computers also react out of turn on their own clock (원카드 외치기·잡기). */
export const BOT_REACTIONS: Record<string, BotReaction> = {
'one-card': oneCardReaction,
};
/** When `me` reacts out of turn (server time), 'ignore', or null (nothing to react to / the game has no reactions). */
export function botReactionAt(def: AnyGameDefinition, state: unknown, me: PlayerId, level?: BotLevel): number | 'ignore' | null {
const react = BOT_REACTIONS[def.id];
if (!react) return null;
try {
return react({ me, view: def.view(state, me), level });
} catch {
return null;
}
}
/** The bot's legal actions as the game lists them (validated lazily: only the chosen one, see below). */
export function botCandidates(def: AnyGameDefinition, state: unknown, me: PlayerId): unknown[] {
return def.legalActions ? def.legalActions(state, me) : [];

View File

@@ -56,3 +56,10 @@ export interface LiveBotDecision<A = any> {
}
export type LiveBotStrategy<V = any, A = any> = (input: LiveBotInput<V>) => LiveBotDecision<A>;
/**
* Out-of-turn reactions (원카드 외치기·잡기): when (server time, ms) this computer reacts to what is on its screen now,
* 'ignore' when it doesn't notice (left alone unless the game waits on it), or null when there is nothing to react to
* (normal thinking time). Must give the same answer every time it is asked about the same moment.
*/
export type BotReaction<V = any> = (input: { me: PlayerId; view: V; level?: import('./persona').BotLevel }) => number | 'ignore' | null;