/** Computer players for solo practice (docs/06-lobby-rooms.md §12). Shared by server and web (no runtime deps). */ import type { PublicUser } from './types'; /** Bot user ids look like `bot::`; real user ids are plain ULIDs, so they can never collide. */ export const BOT_PREFIX = 'bot:'; export const isBotId = (id: string): boolean => id.startsWith(BOT_PREFIX); export const makeBotId = (n: number, unique: string): string => `${BOT_PREFIX}${n}:${unique}`; /** Number shown in the bot's name ("컴퓨터 2"). */ export function botNumber(id: string): number | null { if (!isBotId(id)) return null; const n = Number(id.slice(BOT_PREFIX.length).split(':')[0]); return Number.isInteger(n) && n > 0 ? n : null; } /** Public profile of a bot id, or null for anything else. */ export function botProfile(id: string): PublicUser | null { const n = botNumber(id); return n === null ? null : { id, nickname: `컴퓨터 ${n}`, avatar: null, kind: 'bot' }; } /** * Games that offer computer players. Real-time and drawing games (도블, 할리갈리, 그림 맞히기) don't: a bot there is * either unbeatable or meaningless. 마피아 has talking computers (2026-10-11). */ export const BOT_GAMES: readonly string[] = [ 'omok', 'othello', 'chess', 'janggi', 'baduk', 'seotda', 'poker', 'yacht', 'yut', 'one-card', 'rummikub', 'gostop', 'bang', 'davinci-code', 'mahjong', 'marble', 'dalmuti', 'splendor', 'quoridor', 'las-vegas', 'cockroach-poker', 'ninety-nine', 'mafia', ]; /** Players a practice room starts with when the minimum makes a thin game (마피아 4명 = 마피아 1, 경찰, 의사, 시민 1). */ export const PRACTICE_PLAYERS: Readonly> = { mafia: 6 }; export const botsAllowed = (gameId: string): boolean => BOT_GAMES.includes(gameId); /** * Computer levels 1~60 (docs/09-game-engine.md §9.1): 1~20 쉬움, 21~40 보통, 41~60 어려움. The host can pick a band * for each computer after adding it; the exact level inside the band is drawn at random and stays hidden until the * game is over (fairness check). */ export const BOT_LEVEL_MAX = 60; export type BotBand = 'easy' | 'normal' | 'hard'; export type BotPick = 'random' | BotBand; export const BOT_PICKS: readonly BotPick[] = ['random', 'easy', 'normal', 'hard']; export const BOT_BANDS: Readonly> = { easy: [1, 20], normal: [21, 40], hard: [41, 60] }; export const BOT_PICK_LABEL: Readonly> = { random: '랜덤', easy: '쉬움', normal: '보통', hard: '어려움' }; export function bandOf(level: number): BotBand { return level <= BOT_BANDS.easy[1] ? 'easy' : level <= BOT_BANDS.normal[1] ? 'normal' : 'hard'; } /** * Luck in [-1, 1] as people read it. A computer's luck decides how many shuffles the server tries before a game and * whether it keeps the best or the worst one for that computer (docs/04-stability-security.md §5.1). */ export function luckLabel(luck: number): string { if (luck <= -0.6) return '아주 나쁨'; if (luck <= -0.2) return '나쁨'; if (luck < 0.2) return '보통'; return luck < 0.6 ? '좋음' : '아주 좋음'; }