From 2ec622ebf641974f381a1eb616eb0a0fe9f3a558 Mon Sep 17 00:00:00 2001 From: EJClaw Date: Mon, 12 Oct 2026 21:59:30 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=A9=20=EC=84=A4=EC=A0=95=20"=EC=BB=B4?= =?UTF-8?q?=ED=93=A8=ED=84=B0=20=EC=B1=84=ED=8C=85":=20=EC=BB=B4=ED=93=A8?= =?UTF-8?q?=ED=84=B0=EA=B0=80=20=ED=98=BC=EC=9E=90=20=EB=A7=90=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B1=B4=20=EB=B0=A9=EC=9E=A5=EC=9D=B4=20=EC=BC=A4?= =?UTF-8?q?=20=EB=95=8C=EB=A7=8C(=EA=B8=B0=EB=B3=B8=20=EB=81=84=EA=B8=B0),?= =?UTF-8?q?=20=EB=A7=88=ED=94=BC=EC=95=84=EB=8A=94=20=ED=95=AD=EC=83=81=20?= =?UTF-8?q?=EC=BC=9C=EC=A7=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - RoomConfig/RoomView.botChat, config 메시지에 botChat. 새 방·옛 방 모두 끄기. - BotBrain: 꺼져 있으면 도발·반응·대답·시작 인사·끝 인사 안 함, 모델 미리 올리기도 안 함. 바퀴벌레 포커 진짜/블러핑 판단은 그대로, 한마디만 뺌. - BOT_CHAT_REQUIRED(마피아): 설정과 상관없이 항상 켜짐, 설정 칸에 "항상 켜짐" 표시. - 대기실 설정에 컴퓨터 채팅 켜기/끄기(컴퓨터 상대가 있는 게임만). Co-Authored-By: Claude Opus 5.5 --- apps/server/src/ai/ai.test.ts | 57 +++++++++++++++++++++++++++++++- apps/server/src/ai/brain.ts | 24 +++++++++----- apps/server/src/rooms/manager.ts | 1 + apps/server/src/rooms/room.ts | 13 ++++++-- apps/web/src/pages/RoomPage.tsx | 17 +++++++++- docs/06-lobby-rooms.md | 3 +- packages/shared/src/bots.ts | 8 +++++ packages/shared/src/protocol.ts | 1 + packages/shared/src/types.ts | 2 ++ 9 files changed, 113 insertions(+), 13 deletions(-) diff --git a/apps/server/src/ai/ai.test.ts b/apps/server/src/ai/ai.test.ts index 5d69833..f3f1044 100644 --- a/apps/server/src/ai/ai.test.ts +++ b/apps/server/src/ai/ai.test.ts @@ -115,7 +115,7 @@ describe('rooms with the model', () => { rooms.push(room); const a = h.conn('A'); room.join(a, 'player'); - room.configure('A', { options: { ...(room.config.options as object), colorAssignment: 'hostBlack' } }); + room.configure('A', { options: { ...(room.config.options as object), colorAssignment: 'hostBlack' }, botChat: true }); expect(room.start('A')).toBeNull(); await settle(); room.act('A', 1, { type: 'place', x: 7, y: 7 }); @@ -139,6 +139,7 @@ describe('rooms with the model', () => { rooms.push(room); const a = h.conn('A'); room.join(a, 'player'); + room.configure('A', { botChat: true }); expect(room.start('A')).toBeNull(); room.chat('A', '컴퓨터 1 오목 잘해?'); for (let i = 0; i < 20 && !a.msgs.some((m) => m.t === 'chat' && (m as { text: string }).text.startsWith('저요?')); i++) await settle(); @@ -172,6 +173,7 @@ describe('rooms with the model', () => { rooms.push(room); const a = h.conn(`A${attempt}`); room.join(a, 'player'); + room.configure(`A${attempt}`, { botChat: true }); expect(room.start(`A${attempt}`)).toBeNull(); const st = () => room.game!.state as { round: { claim: string | null; card: string | null; starter: string } }; if (!isBotId(st().round.starter)) continue; @@ -190,6 +192,59 @@ describe('rooms with the model', () => { expect(checked).toBe(true); }); + test('컴퓨터 채팅 off (the default): computers never talk on their own — no taunts, answers, greetings or end words', async () => { + const h = harness(() => '흐음, 여기 두면 아프겠는데?', () => 0); + const room = h.manager.createPractice('A', 'omok') as Room; + rooms.push(room); + const a = h.conn('A'); + room.join(a, 'player'); + expect(room.roomView().botChat).toBe(false); + room.configure('A', { options: { ...(room.config.options as object), colorAssignment: 'hostBlack' } }); + expect(room.start('A')).toBeNull(); + await settle(); + room.chat('A', '컴퓨터 1 오목 잘해?'); + for (let i = 0; i < 3; i++) { + room.act('A', i + 1, { type: 'place', x: [0, 14, 0][i]!, y: [0, 14, 14][i]! }); + room.bots.fire(); + for (let k = 0; k < 20 && (room.game!.state as { moves: unknown[] }).moves.length < 2 * (i + 1); k++) await settle(); + } + expect((room.game!.state as { moves: unknown[] }).moves.length).toBe(6); + expect(a.msgs.some((m) => m.t === 'chat' && (m as { from: { id: string } | null }).from && isBotId((m as { from: { id: string } }).from.id))).toBe(false); + // The model isn't even warmed up: nothing in this game uses it. + expect(h.prompts).toHaveLength(0); + }); + + test('컴퓨터 채팅 off: in 바퀴벌레 포커 the model still decides truth or bluff, the computer just says nothing', async () => { + let checked = false; + for (let attempt = 0; attempt < 12 && !checked; attempt++) { + const h = harness((_u, body) => (body.format ? JSON.stringify({ bluff: false, say: '이건 진짜야, 믿어봐~' }) : '흠')); + const room = h.manager.createPractice(`B${attempt}`, 'cockroach-poker') as Room; + rooms.push(room); + const a = h.conn(`B${attempt}`); + room.join(a, 'player'); + expect(room.start(`B${attempt}`)).toBeNull(); + const st = () => room.game!.state as { round: { claim: string | null; card: string | null; starter: string } }; + if (!isBotId(st().round.starter)) continue; + for (let i = 0; i < 30 && !st().round.claim; i++) { + room.bots.fire(); + await settle(); + } + expect(st().round.claim).toBe(st().round.card!.replace(/-\d+$/, '')); + expect(a.msgs.some((m) => m.t === 'chat')).toBe(false); + checked = true; + } + expect(checked).toBe(true); + }); + + test('마피아 needs its computers to talk: 컴퓨터 채팅 is always on there', () => { + const h = harness(() => '흠'); + const room = h.manager.createPractice('A', 'mafia') as Room; + rooms.push(room); + room.join(h.conn('A'), 'player'); + room.configure('A', { botChat: false }); + expect(room.roomView().botChat).toBe(true); + }); + test('마피아: a computer says its planned line in its own words; a line claiming a role is thrown away', async () => { let n = 0; const h = harness(() => (n++ % 2 === 0 ? '안녕하세요~ 오늘 마피아 꼭 잡아봐요!' : '저 경찰이에요 믿어주세요')); diff --git a/apps/server/src/ai/brain.ts b/apps/server/src/ai/brain.ts index f9b4168..60792ec 100644 --- a/apps/server/src/ai/brain.ts +++ b/apps/server/src/ai/brain.ts @@ -9,6 +9,7 @@ * something to sell it. In 마피아 it says each line of the computer's plan in its own words. * Moves themselves still come from each game's computer strategy (it sees only its own screen). Without a model * (not configured, busy, down) the computers simply play as before, silently, and 마피아 uses its built-in lines. + * Talking on their own is a room setting (`chatty`, off by default); 마피아 talks always because the game needs it. */ import { secureRandom } from '@bg/engine'; import { botPace, hash01 } from '@bg/games/bots'; @@ -31,6 +32,11 @@ export interface BrainRoom { recentChat(): { from: string; text: string }[]; /** 똑똑한 편 (존댓말) or 허술한 편 (반말), docs/09 §9.1. */ smart(bot: string): boolean; + /** + * The computers may chat on their own (room setting "컴퓨터 채팅"; always on in 마피아). Off: no small talk, + * reactions, answers, greetings or end-of-game words — they just play (still showing "생각 중…"). + */ + chatty(): boolean; now(): number; } @@ -128,7 +134,7 @@ export class BotBrain { if (!type || type === 'chat' || type === 'say' || type === 'reaction' || type === 'ping' || type === 'timeout') return; this.happened.push(`${this.room.nameOf(actor)} ${ACTION_KO[type] ?? '행동함'}`); if (this.happened.length > 12) this.happened.shift(); - if (!this.enabled() || this.room.bots().includes(actor) || this.room.gameId() === 'mafia') return; + if (!this.enabled() || !this.room.chatty() || this.room.bots().includes(actor) || this.room.gameId() === 'mafia') return; const bots = this.room.bots().filter((b) => this.canTalk(b, 10_000, 30_000)); if (!bots.length || this.random() > 0.12) return; const bot = bots[Math.floor(this.random() * bots.length)]!; @@ -152,9 +158,10 @@ export class BotBrain { const r = await this.cockroachBluff(bot, a, view); if (r) { act = r.action; - line = r.say; + // Chat off: the model still decides truth or bluff, the computer just hands the card over without a word. + line = this.room.chatty() ? r.say : null; } - } else if (this.canTalk(bot) && this.random() < temperOf(bot).talk) { + } else if (this.room.chatty() && this.canTalk(bot) && this.random() < temperOf(bot).talk) { const type = String(a.type ?? ''); line = await writeLine(this.llm, this.request(bot, this.situation(), `나는 지금 "${ACTION_KO[type] ?? '내 수'}"를 하려 한다. 이 수를 두며 상대에게 던지는 도발이나 심리전 한마디.`)); } @@ -195,7 +202,7 @@ export class BotBrain { /** People chatting: a named computer answers; otherwise sometimes one of them joins in. */ onHumanChat(from: string, text: string): void { - if (!this.enabled() || this.room.gameId() === 'mafia') return; + if (!this.enabled() || !this.room.chatty() || this.room.gameId() === 'mafia') return; const bots = this.room.bots(); const named = bots.find((b) => { const n = /^컴퓨터 (\d+)$/.exec(this.room.nameOf(b))?.[1]; @@ -212,9 +219,10 @@ export class BotBrain { onGameStart(): void { this.happened = []; - // A game with computers and people: make sure the model is loaded before anyone talks. - if (this.llm?.available() && this.room.humans().length && this.room.bots().length) void this.llm.warm(); - if (!this.enabled() || this.room.gameId() === 'mafia' || this.random() > 0.7) return; + // A game with computers and people where the model will be used: make sure it is loaded before anyone talks. + const usesModel = this.room.chatty() || this.room.gameId() === 'cockroach-poker'; + if (usesModel && this.llm?.available() && this.room.humans().length && this.room.bots().length) void this.llm.warm(); + if (!this.enabled() || !this.room.chatty() || this.room.gameId() === 'mafia' || this.random() > 0.7) return; const bots = this.room.bots(); const bot = bots[Math.floor(this.random() * bots.length)]; if (!bot) return; @@ -226,7 +234,7 @@ export class BotBrain { /** The game ended: a computer that won gloats a little, or one that lost takes it with a word. */ onGameEnd(ranking: string[][]): void { - if (!this.llm?.available() || !this.room.humans().length || this.room.gameId() === 'mafia' || this.random() > 0.85) return; + if (!this.llm?.available() || !this.room.chatty() || !this.room.humans().length || this.room.gameId() === 'mafia' || this.random() > 0.85) return; const bots = this.room.bots(); const winner = (ranking[0] ?? []).find((p) => bots.includes(p)); const bot = winner ?? bots[Math.floor(this.random() * bots.length)]; diff --git a/apps/server/src/rooms/manager.ts b/apps/server/src/rooms/manager.ts index 6feb385..510c1c4 100644 --- a/apps/server/src/rooms/manager.ts +++ b/apps/server/src/rooms/manager.ts @@ -115,6 +115,7 @@ export class RoomManager { allowSpectators: true, chatEnabled: site?.chatEnabledDefault ?? true, chatFilter: site?.chatFilterDefault ?? true, + botChat: false, graceSec: site?.graceSec ?? 60, }; const code = this.newCode(); diff --git a/apps/server/src/rooms/room.ts b/apps/server/src/rooms/room.ts index 1d63fbb..bc6686f 100644 --- a/apps/server/src/rooms/room.ts +++ b/apps/server/src/rooms/room.ts @@ -4,7 +4,7 @@ */ import { ulid } from 'ulid'; import { SeededRng, createSeed, secureRandom, seedToHex, type AnyGameDefinition, type ChaChaSeed, type GameResult, type RngState } from '@bg/engine'; -import { botsAllowed, isBotId, makeBotId, botNumber, maskProfanity, type BotPick, type PublicUser, type RoomView, type ServerMessage, type SeatView } from '@bg/shared'; +import { botChatRequired, 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'; @@ -29,6 +29,8 @@ export interface RoomConfig { allowSpectators: boolean; chatEnabled: boolean; chatFilter: boolean; + /** Computers chat on their own (docs/06 §12.1). Off unless the host turns it on; rooms saved before it existed read as off. */ + botChat?: boolean; /** Seconds a disconnected player keeps their turn timer before auto actions kick in (docs/03 §6.2). */ graceSec: number; } @@ -189,6 +191,7 @@ export class Room { }, recentChat: () => this.chatLog.slice(-8).map((m) => ({ from: m.from?.nickname ?? '누군가', text: m.text })), smart: (bot) => botPersona(bot, this.profile(bot).base).smart, + chatty: () => this.botChatOn(), now: this.now, }, deps.ai ?? null, @@ -222,6 +225,11 @@ export class Room { ); } + /** The computers' own chat: the room setting, or always where the game needs it (마피아). */ + private botChatOn(): boolean { + return botChatRequired(this.config.gameId) || this.config.botChat === true; + } + get def(): AnyGameDefinition { const d = this.deps.games[this.config.gameId]; if (!d) throw new Error(`unknown game ${this.config.gameId}`); @@ -411,6 +419,7 @@ export class Room { allowSpectators: this.config.allowSpectators, chatEnabled: this.config.chatEnabled, chatFilter: this.config.chatFilter, + botChat: this.botChatOn(), seats, spectators: [...this.spectators].map(pub), status: this.status, @@ -689,7 +698,7 @@ export class Room { else if (next.gameId === this.config.gameId && this.config.maxPlayers === this.playerRange().max) next.maxPlayers = range.max; next.maxPlayers = Math.min(Math.max(next.maxPlayers, range.min), range.max); if (next.maxPlayers < this.seatedIds().length) return `이미 ${this.seatedIds().length}명이 앉아 있어요.`; - for (const k of ['visibility', 'allowSpectators', 'chatEnabled', 'chatFilter'] as const) { + for (const k of ['visibility', 'allowSpectators', 'chatEnabled', 'chatFilter', 'botChat'] as const) { if (patch[k] !== undefined) (next as unknown as Record)[k] = patch[k]; } // Resize seats, compacting occupied seats to the front if needed. diff --git a/apps/web/src/pages/RoomPage.tsx b/apps/web/src/pages/RoomPage.tsx index fe12e90..5c36b5c 100644 --- a/apps/web/src/pages/RoomPage.tsx +++ b/apps/web/src/pages/RoomPage.tsx @@ -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 { BOT_BANDS, BOT_PICKS, BOT_PICK_LABEL, bandOf, botsAllowed, formatRoomCode, isBotId, luckLabel, type PublicUser, type RoomView } from '@bg/shared/lite'; +import { BOT_BANDS, BOT_PICKS, BOT_PICK_LABEL, bandOf, botChatRequired, 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'; @@ -581,6 +581,21 @@ function SettingsForm({ room, ui, inline, readOnly, onDone }: { room: RoomView; 채팅 {readOnly ? {seg(room.chatEnabled, () => {}, '켜기', '끄기')} : seg(room.chatEnabled, (chatEnabled) => socket.send({ t: 'config', chatEnabled }), '켜기', '끄기')} + {botsAllowed(room.gameId) && ( +
+ 컴퓨터 채팅 + {botChatRequired(room.gameId) ? ( +

+ 항상 켜짐 · 이 게임은 컴퓨터도 말해야 할 수 있어요 +

+ ) : readOnly ? ( + {seg(room.botChat, () => {}, '켜기', '끄기')} + ) : ( + seg(room.botChat, (botChat) => socket.send({ t: 'config', botChat }), '켜기', '끄기') + )} + {!botChatRequired(room.gameId) && 켜면 컴퓨터가 게임하면서 먼저 말을 걸고, 채팅에 대답해요.} +
+ )} {!inline && (