제한 시간 보정 2: 같은 마감 안에서는 투표로 답할 사람이 줄어도 준 시간 유지, 마감은 남은 답할 사람 중 가장 늦은 화면 기준, 자체 시계를 쓰는 게임도 늘어난 마감을 표시

- room: reveal 단계 키를 게임 마감만으로, clockExtra = max(본인, 답할 사람들)
- 라이어·마피아·아발론 시계, 뱅 반응·차례 타이머, 바둑 계가·마작 울기 타이머가 방 마감(연출 시간 포함)을 따름
- 아발론 암살 마감: 당겨진 마감은 숨기고 늘어난 마감은 보여 줌(무제한이면 그대로 숨김)
- 테스트: 공통 재투표(대표자 A·느린 B·A 투표 후 유지), e2e 라이어 화면 시계 = 방 마감

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-08 12:09:36 +09:00
parent bc8cb7ae8c
commit f793391b79
8 changed files with 117 additions and 26 deletions

View File

@@ -107,6 +107,7 @@ describe('Room timers', () => {
room.settled('B', room.seq);
room.clearTimer();
// A plays; B (to move) has not reported this new state yet
clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, (room.def.legalActions!(room.game!.state, 'A') as unknown[])[0]);
room.clearTimer();
const base = clock.now() + 10_000;
@@ -127,6 +128,7 @@ describe('Room timers', () => {
room.start('A');
room.settled('A', room.seq);
room.settled('B', room.seq);
clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, (room.def.legalActions!(room.game!.state, 'A') as unknown[])[0]);
room.clearTimer();
const base = clock.now() + 10_000;
@@ -399,6 +401,7 @@ describe('Room clocks after the animation (shared steps)', () => {
room.start('A');
room.settled('A', room.seq);
room.settled('B', room.seq);
clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, { type: 'go' }); // → only B answers now, A is the timed stand-in
room.clearTimer();
const base = clock.now() + 10_000;
@@ -426,4 +429,44 @@ describe('Room clocks after the animation (shared steps)', () => {
room.clearTimer();
expect((room.game!.state as any).chats).toBe(1);
});
// A re-vote: A and B both vote under one shared clock that the room times through A.
const revote: AnyGameDefinition = {
...guess,
id: 'revote',
actionSchema: z.object({ type: z.enum(['go', 'vote', 'chat']) }),
setup: ({ players, now }) => ({ players, step: 'start', deadlineAt: now + 10_000, voted: [] as string[], chats: 0 }),
apply: (s: any, p, a: any, { now }) => ({
state: a.type === 'go' ? { ...s, step: 'vote', deadlineAt: now + 10_000 } : a.type === 'vote' ? { ...s, voted: [...s.voted, p] } : { ...s, chats: s.chats + 1 },
events: [],
}),
activePlayers: (s: any) => (s.step === 'vote' ? s.players.filter((p: string) => !s.voted.includes(p)) : s.players),
timeoutPlayers: (s: any) => (s.step === 'vote' ? [s.players[0]] : s.players),
};
test('a shared vote: the clock waits for the slowest voter\'s screen, and someone voting keeps that time', () => {
const { room, clock, conn } = harness({ revote });
const a = conn('A');
const b = conn('B');
room.join(a, 'player');
room.join(b, 'player');
room.start('A');
room.settled('A', room.seq);
room.settled('B', room.seq);
clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, { type: 'go' });
room.clearTimer();
const base = clock.now() + 10_000;
clock.advance(220);
room.settled('A', room.seq); // A (also the timed stand-in) is done in 0.22 s …
clock.advance(5_780);
room.settled('B', room.seq); // … B only after 6 s: the shared clock gives everybody those 6 s
room.clearTimer();
expect(room.effectiveDeadline()).toBe(base + 6_000);
expect(a.msgs.at(-1)).toEqual({ t: 'deadline', deadline: base + 6_000 });
// A votes: only B is left to answer, same clock: still 6 s more.
room.act('A', 2, { type: 'vote' });
room.clearTimer();
expect(room.effectiveDeadline()).toBe(base + 6_000);
expect((b.msgs.filter((m) => m.t === 'state').at(-1) as { deadline: number }).deadline).toBe(base + 6_000);
});
});

View File

@@ -1168,22 +1168,22 @@ export class Room {
return provisional ? Math.min(cap, Math.max(0, this.now() - r.at)) : cap;
}
/** What a step is: its clock and who acts / is timed in it. */
/**
* What a step is: its clock. Players answering one by one inside a shared clock (votes) or a chat line keep the
* time already given; a new clock (next turn, next phase) is a new step.
*/
private revealKey(): string {
const g = this.game!;
const def = this.def;
return JSON.stringify([def.deadline?.(g.state) ?? null, def.activePlayers(g.state), def.timeoutPlayers?.(g.state) ?? null]);
return JSON.stringify(this.def.deadline?.(this.game!.state) ?? null);
}
/**
* Extra time on `u`'s clock. A player who has to answer gets their own screen's animation time; a player timed for
* a step others answer (the room times one stand-in for a shared clock) gets the slowest answerer's, so the
* people who really answer are never cut short by someone else's faster screen.
* Extra time on `u`'s clock: the slowest screen among the players who still have to answer (and `u`). A shared
* clock (a vote, a stand-in the room times for everybody) thus never cuts short someone whose screen is still
* animating because another screen was faster.
*/
private clockExtra(u: string, provisional = false): number {
const answer = this.def.activePlayers(this.game!.state);
if (answer.includes(u)) return this.revealExtra(u, provisional);
return Math.max(0, ...answer.map((p) => this.revealExtra(p, provisional)));
return Math.max(this.revealExtra(u, provisional), ...answer.map((p) => this.revealExtra(p, provisional)));
}
/** A player's screen finished animating the state `seq` (or a later one): their clock starts now. */