라이어 게임: 토론 채팅을 게임 내내 열기, 설명은 별도 describe 액션으로

- chat은 확인 시간·설명 중(말하는 사람 포함)·토론·투표·정답 맞히기 내내 모두 쓸 수 있다
- 설명은 새 describe 액션(차례인 사람만, 80자). 채팅에 쓴 말은 설명으로 치지 않는다
- 자기 제시어 금지·고운 말 검사는 설명과 채팅 모두 그대로
- 컴퓨터 설명도 describe로 보내고, 모델이 켜져 있으면 "입력 중…" 뒤에 보낸다
- 화면: 채팅 입력칸을 항상 보이게, 설명 차례인 사람에게는 채팅 칸 안내 문구
- 문서(docs/games/liar.md)와 테스트 갱신

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 01:20:38 +09:00
parent e9bc366305
commit fcc79f05bc
10 changed files with 81 additions and 61 deletions

View File

@@ -117,8 +117,8 @@ describe('reading', () => {
const rng = SeededRng.fromSeed(seedN(4));
let now = 0;
st = liar.apply(st, players[0]!, { type: 'phaseTimeout' }, { rng, now: (now = st.phase.kind === 'reveal' ? st.phase.endsAt : 0) }).state;
for (let i = 0; i < 4; i++) st = liar.apply(st, players[i]!, { type: 'chat', text: hints[i]! }, { rng, now: (now += 2000) }).state;
st = liar.apply(st, players[4]!, { type: 'chat', text: '저는 좋아하는 편이에요' }, { rng, now: (now += 2000) }).state;
for (let i = 0; i < 4; i++) st = liar.apply(st, players[i]!, { type: 'describe', text: hints[i]! }, { rng, now: (now += 2000) }).state;
st = liar.apply(st, players[4]!, { type: 'describe', text: '저는 좋아하는 편이에요' }, { rng, now: (now += 2000) }).state;
const names = Object.fromEntries(players.map((p, i) => [p, `컴퓨터 ${i + 1}`]));
return { st, players, names, now };
}

View File

@@ -370,7 +370,7 @@ class LiarBot {
key: key('describe'),
// Leave room for typing ("입력 중…" up to ~6초 on the server) inside the turn.
due: this.inPhase(1.5, 5, 'describe', 0.3),
make: () => ({ type: 'chat', text: this.description() }),
make: () => ({ type: 'describe', text: this.description() }),
});
}
break;

View File

@@ -291,21 +291,20 @@ function wordOf(s: LiarState, id: PlayerId): string | null {
return id === s.liar ? s.liarWord : s.word;
}
/** Why `p` cannot write now (Korean), or null. */
/** Why `p` cannot write in the free-talk chat now (Korean), or null. The chat stays open for the whole game. */
function chatBlock(s: LiarState, p: PlayerState): string | null {
const ph = s.phase;
if (ph.kind === 'ended') return '게임이 끝났어요.';
if (s.phase.kind === 'ended') return '게임이 끝났어요.';
if (p.left) return '게임에서 나갔어요.';
switch (ph.kind) {
case 'reveal':
return '제시어를 확인하는 중이에요. 곧 설명이 시작돼요.';
case 'describe':
return speakerOf(s) === p.id ? null : '지금은 설명 차례인 사람만 말할 수 있어요.';
case 'guess':
return '라이어가 제시어를 맞히는 중이에요.';
default:
return null;
}
return null;
}
/** Shared text checks of a description and a chat line: 고운 말, and not one's own word. */
function textProblem(s: LiarState, actor: PlayerId, text: string): string | null {
const why = chatProblem(text, s.options.kidSafeChat);
if (why) return why;
const mine = wordOf(s, actor);
if (mine && saysWord(text, s.topic, mine)) return '제시어를 직접 말하면 안 돼요.';
return null;
}
// ---------------------------------------------------------------- validate
@@ -331,13 +330,16 @@ function validate(s: LiarState, actor: PlayerId, a: LiarAction, ctx?: { now: num
const block = chatBlock(s, p);
if (block) return fail(block);
const text = cleanChat(a.text);
const max = ph.kind === 'describe' ? DESCRIBE_MAX : CHAT_MAX;
if (ph.kind === 'describe' && [...text].length > max) return fail(`설명은 한 문장, ${max}자까지 쓸 수 있어요.`);
const why = chatProblem(text, s.options.kidSafeChat);
if (why) return fail(why);
const mine = wordOf(s, actor);
if (mine && saysWord(text, s.topic, mine)) return fail('제시어를 직접 말하면 안 돼요.');
return ok;
const why = textProblem(s, actor, text);
return why ? fail(why) : ok;
}
case 'describe': {
if (ph.kind !== 'describe') return fail('지금은 설명하는 때가 아니에요.');
if (speakerOf(s) !== actor) return fail('지금은 설명 차례인 사람만 설명할 수 있어요.');
const text = cleanChat(a.text);
if ([...text].length > DESCRIBE_MAX) return fail(`설명은 한 문장, ${DESCRIBE_MAX}자까지 쓸 수 있어요.`);
const why = textProblem(s, actor, text);
return why ? fail(why) : ok;
}
case 'ready':
if (ph.kind !== 'reveal' && ph.kind !== 'discussion') return fail('지금은 넘길 수 있는 때가 아니에요.');
@@ -504,17 +506,15 @@ export const liar: Def = {
case 'leave':
leave(s, now, p);
break;
case 'chat': {
const text = cleanChat(a.text);
if (ph.kind === 'describe') {
s.descriptions.push({ n: s.descriptions.length + 1, round: ph.round, from: actor, text, at: now });
nextTurn(s, now, ph.round, ph.turn + 1);
} else {
s.chat.push({ n: (s.chat.at(-1)?.n ?? 0) + 1, from: actor, text, at: now });
if (s.chat.length > CHAT_KEEP) s.chat.splice(0, s.chat.length - CHAT_KEEP);
}
case 'chat':
s.chat.push({ n: (s.chat.at(-1)?.n ?? 0) + 1, from: actor, text: cleanChat(a.text), at: now });
if (s.chat.length > CHAT_KEEP) s.chat.splice(0, s.chat.length - CHAT_KEEP);
break;
case 'describe':
if (ph.kind !== 'describe') throw new Error('liar: describe outside the describe phase');
s.descriptions.push({ n: s.descriptions.length + 1, round: ph.round, from: actor, text: cleanChat(a.text), at: now });
nextTurn(s, now, ph.round, ph.turn + 1);
break;
}
case 'ready':
if (ph.kind !== 'reveal' && ph.kind !== 'discussion') throw new Error('liar: ready outside reveal/discussion');
ph.ready.push(actor);
@@ -587,6 +587,7 @@ export const liar: Def = {
if (p.left) return out.filter((a) => validate(s, player, a).ok);
const me = myView(s, p);
if (me.canChat) out.push({ type: 'chat', text: `m${s.seq}-${player}` });
if (me.canDescribe) out.push({ type: 'describe', text: `d${s.seq}-${player}` });
if (me.canReady) out.push({ type: 'ready' });
for (const t of me.voteTargets) out.push({ type: 'vote', target: t });
if (me.canGuess) {

View File

@@ -156,7 +156,7 @@ describe('준비와 비밀 (§4, §8.3)', () => {
b = f(b);
};
step(tick);
step((s) => act(s, speaker(s)!, { type: 'chat', text: '여름에 생각나요' }));
step((s) => act(s, speaker(s)!, { type: 'describe', text: '여름에 생각나요' }));
step(tick);
step((s) => until(s, 'discussion'));
step((s) => act(s, 'P1', { type: 'chat', text: '다들 애매하네요' }));
@@ -205,8 +205,8 @@ describe('차례대로 설명 (§5.2)', () => {
while (s.phase.kind === 'describe') {
const sp = speaker(s)!;
spoken.push(sp);
for (const other of ids(3).filter((x) => x !== sp)) expect(reject(s, other, { type: 'chat', text: '저도요' })).toBe('지금은 설명 차례인 사람만 말할 수 있어요.');
s = act(s, sp, { type: 'chat', text: `설명 ${spoken.length}` });
for (const other of ids(3).filter((x) => x !== sp)) expect(reject(s, other, { type: 'describe', text: '저도요' })).toBe('지금은 설명 차례인 사람만 설명할 수 있어요.');
s = act(s, sp, { type: 'describe', text: `설명 ${spoken.length}` });
}
expect(spoken).toEqual(['P0', 'P1', 'P2', 'P2', 'P1', 'P0']);
expect(roundOrder(s, 2)).toEqual(['P2', 'P1', 'P0']);
@@ -223,40 +223,54 @@ describe('차례대로 설명 (§5.2)', () => {
test('첫 바퀴 마지막 사람은 바로 이어서 두 번째 바퀴 첫 설명을 할 수 있어요(채팅 간격 제한 없음)', () => {
let s = tick(rig(3));
for (const p of ['P0', 'P1', 'P2']) s = act(s, p, { type: 'chat', text: `${p} 설명` }, T0 + 20_000);
for (const p of ['P0', 'P1', 'P2']) s = act(s, p, { type: 'describe', text: `${p} 설명` }, T0 + 20_000);
expect(speaker(s)).toBe('P2');
s = act(s, 'P2', { type: 'chat', text: '또 설명' }, T0 + 20_000);
s = act(s, 'P2', { type: 'describe', text: '또 설명' }, T0 + 20_000);
expect(speaker(s)).toBe('P1');
});
test('한 바퀴 옵션, 시간 초과는 넘김, 설명은 80자까지', () => {
let s = tick(rig(3, { rounds: 1, describeSeconds: 15 }));
expect(s.phase.kind === 'describe' && s.phase.endsAt! - s.phase.startedAt).toBe(15_000);
expect(reject(s, 'P0', { type: 'chat', text: '가'.repeat(81) })).toContain('80자');
expect(reject(s, 'P0', { type: 'describe', text: '가'.repeat(81) })).toContain('80자');
s = tick(s);
expect(s.descriptions[0]).toMatchObject({ from: 'P0', text: null });
s = act(s, 'P1', { type: 'chat', text: '좋아요' });
s = act(s, 'P1', { type: 'describe', text: '좋아요' });
s = tick(s);
expect(s.phase.kind).toBe('discussion');
});
test('제시어를 직접 말하면 안 돼요(띄어쓰기 무시). 라이어는 막지 않아요(막으면 정답이 새요)', () => {
let s = tick(rig(3, { rounds: 1 }, { liarIdx: 1 }));
expect(reject(s, 'P0', { type: 'chat', text: '수 박 맛있어요' })).toBe('제시어를 직접 말하면 안 돼요.');
s = act(s, 'P0', { type: 'chat', text: '여름이면 생각나요' });
s = act(s, 'P1', { type: 'chat', text: '수박 같아요' }); // the liar's guess-like line goes through
expect(reject(s, 'P0', { type: 'describe', text: '수 박 맛있어요' })).toBe('제시어를 직접 말하면 안 돼요.');
expect(reject(s, 'P2', { type: 'chat', text: '수 박 맛있어요' })).toBe('제시어를 직접 말하면 안 돼요.');
s = act(s, 'P0', { type: 'describe', text: '여름이면 생각나요' });
s = act(s, 'P1', { type: 'describe', text: '수박 같아요' }); // the liar's guess-like line goes through
expect(s.descriptions.at(-1)!.text).toBe('수박 같아요');
});
test('바보 모드 라이어는 자기 단어를 직접 말하면 막혀요(시민과 똑같이)', () => {
const s = tick(rig(3, { foolMode: true, rounds: 1 }, { liarIdx: 0 }));
expect(reject(s, 'P0', { type: 'describe', text: '참외' })).toBe('제시어를 직접 말하면 안 돼요.');
expect(reject(s, 'P0', { type: 'chat', text: '참외' })).toBe('제시어를 직접 말하면 안 돼요.');
});
test('확인 시간·정답 맞히기 중에는 채팅을 못 쓰고, 토론·투표 중에는 모두 써요', () => {
test('토론 채팅은 게임 내내 열려 있어요: 확인 시간·설명 중(말하는 사람 포함)에도 쓰고, 설명으로 치지 않아요', () => {
let s = rig(3);
expect(reject(s, 'P0', { type: 'chat', text: '안녕' })).toContain('확인하는 중');
s = act(s, 'P0', { type: 'chat', text: '안녕' });
expect(s.phase.kind).toBe('reveal');
s = tick(s);
expect(speaker(s)).toBe('P0');
s = act(s, 'P1', { type: 'chat', text: '첫 사람 누구예요' });
s = act(s, 'P0', { type: 'chat', text: '저요 잠깐만요' });
expect(speaker(s)).toBe('P0');
expect(s.descriptions).toEqual([]);
expect(liar.view(s, 'P2').my).toMatchObject({ canChat: true, chatWhy: null, canDescribe: false });
expect(reject(s, 'P1', { type: 'describe', text: '저도요' })).toBe('지금은 설명 차례인 사람만 설명할 수 있어요.');
expect(s.chat.map((m) => m.text)).toEqual(['안녕', '첫 사람 누구예요', '저요 잠깐만요']);
s = until(s, 'discussion');
expect(reject(s, 'P0', { type: 'describe', text: '늦은 설명' })).toBe('지금은 설명하는 때가 아니에요.');
s = { ...s, chat: [] };
const t = at(s);
// No pace limit: any number of lines at the same moment all go through.
for (let i = 0; i < 20; i++) s = act(s, 'P1', { type: 'chat', text: `누구지 ${i}` }, t);
@@ -324,7 +338,8 @@ describe('토론과 투표 (§5.3~5.5)', () => {
expect(s.phase.kind).toBe('guess');
expect(lastEv(s, 'accused')).toMatchObject({ p: 'P3', liar: true });
expect(reject(s, 'P0', { type: 'guess', text: '수박' })).toBe('라이어만 맞힐 수 있어요.');
expect(reject(s, 'P0', { type: 'chat', text: '힌트' })).toContain('맞히는 중');
s = act(s, 'P0', { type: 'chat', text: '못 맞힐걸요' }); // the chat stays open while the liar guesses
expect(s.phase.kind).toBe('guess');
const right = act(s, 'P3', { type: 'guess', text: ' 수 박 ' });
expect(right.final).toMatchObject({ winner: 'liar', reason: 'guessed', guess: '수 박' });
expect(liar.result(right)!.ranking).toEqual([['P3'], ['P0', 'P1', 'P2']]);
@@ -391,7 +406,7 @@ describe('시간 무제한 (§8.5)', () => {
expect(liar.deadline!(s)).toBeNull();
expect(liar.timeoutPlayers!(s)).toEqual(['P0']);
expect(reject(s, 'P1', { type: 'phaseTimeout' })).toBe('아직 기다리는 중이에요.');
for (const p of ['P0', 'P1', 'P2']) s = act(s, p, { type: 'chat', text: `${p} 설명` }, T0 + 3_600_000);
for (const p of ['P0', 'P1', 'P2']) s = act(s, p, { type: 'describe', text: `${p} 설명` }, T0 + 3_600_000);
expect(s.phase.kind).toBe('discussion');
expect(liar.timeoutPlayers!(s)).toEqual(['P0', 'P1', 'P2']);
for (const p of ['P0', 'P1', 'P2']) s = act(s, p, { type: 'ready' });
@@ -409,7 +424,7 @@ describe('시간 무제한 (§8.5)', () => {
let s = tick(rig(4, { ...U, rounds: 1 }));
s = act(s, 'P0', liar.onTimeout(s, 'P0'));
expect(s.descriptions[0]).toMatchObject({ from: 'P0', text: null });
for (const p of ['P1', 'P2', 'P3']) s = act(s, p, { type: 'chat', text: `${p} 설명` });
for (const p of ['P1', 'P2', 'P3']) s = act(s, p, { type: 'describe', text: `${p} 설명` });
for (const p of ['P1', 'P2', 'P3']) s = act(s, p, { type: 'ready' });
s = act(s, 'P0', liar.onTimeout(s, 'P0'));
expect(s.phase.kind).toBe('vote');

View File

@@ -43,8 +43,10 @@ export type LiarOptions = z.infer<typeof liarOptionsSchema>;
const pid = z.string().min(1).max(64);
export const liarActionSchema = z.discriminatedUnion('type', [
/** Describe phase: the speaker's one sentence. Discussion / vote: free talk. */
/** Free talk: open to every player for the whole game. */
z.object({ type: z.literal('chat'), text: z.string().max(400) }),
/** Describe phase: the speaker's one sentence. */
z.object({ type: z.literal('describe'), text: z.string().max(400) }),
z.object({ type: z.literal('ready') }),
z.object({ type: z.literal('vote'), target: pid }),
z.object({ type: z.literal('guess'), text: z.string().max(60) }),