방 설정 "컴퓨터 채팅": 컴퓨터가 혼자 말하는 건 방장이 켤 때만(기본 끄기), 마피아는 항상 켜짐

- RoomConfig/RoomView.botChat, config 메시지에 botChat. 새 방·옛 방 모두 끄기.
- BotBrain: 꺼져 있으면 도발·반응·대답·시작 인사·끝 인사 안 함, 모델 미리 올리기도 안 함.
  바퀴벌레 포커 진짜/블러핑 판단은 그대로, 한마디만 뺌.
- BOT_CHAT_REQUIRED(마피아): 설정과 상관없이 항상 켜짐, 설정 칸에 "항상 켜짐" 표시.
- 대기실 설정에 컴퓨터 채팅 켜기/끄기(컴퓨터 상대가 있는 게임만).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-12 21:59:30 +09:00
parent bd179c7a43
commit 2ec622ebf6
9 changed files with 113 additions and 13 deletions

View File

@@ -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 ? '안녕하세요~ 오늘 마피아 꼭 잡아봐요!' : '저 경찰이에요 믿어주세요'));

View File

@@ -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)];