할리갈리·도블·사과 게임: 뒤집기 시간 무제한·사과 게임 무제한(여기까지), 소리·움직임

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 04:16:54 +09:00
parent f12cf12b84
commit bafbf95d98
13 changed files with 476 additions and 94 deletions

View File

@@ -80,7 +80,7 @@ describe('판 만들기', () => {
}
const s = make(['A', 'B', 'C']);
expect(new Set(Object.values(s.boards))).toEqual(new Set([s.initial]));
expect(s.endsAt).toBe(START + 120_000);
expect(s.endsAt!).toBe(START + 120_000);
expect(make(['A'], { timeLimitSec: 60 }).endsAt).toBe(START + 60_000);
});
@@ -160,10 +160,10 @@ describe('진행', () => {
s = act(s, 'A', sel(m1!), START + 1000);
s = act(s, 'B', sel(m1!), START + 1000);
s = act(s, 'B', sel(findMoves(s.boards.B!)[0]!), START + 2000);
expect(apple.deadline!(s)).toBe(s.endsAt);
expect(apple.timeoutNotBefore!(s)).toBe(s.endsAt);
expect(reason(s, 'C', sel(m1!), s.endsAt)).toBe('시간이 다 됐어요.');
s = tick(s, s.endsAt);
expect(apple.deadline!(s)).toBe(s.endsAt!);
expect(apple.timeoutNotBefore!(s)).toBe(s.endsAt!);
expect(reason(s, 'C', sel(m1!), s.endsAt!)).toBe('시간이 다 됐어요.');
s = tick(s, s.endsAt!);
expect(s.phase).toBe('ended');
const r = apple.result(s)!;
expect(r.ranking).toEqual([['B'], ['A'], ['C']]);
@@ -178,7 +178,7 @@ describe('진행', () => {
let s = make(['A']);
s = tick(s, START);
s = act(s, 'A', sel(findMoves(s.initial)[0]!), START + 500);
s = tick(s, s.endsAt + 5);
s = tick(s, s.endsAt! + 5);
const r = apple.result(s)!;
expect(r.ranking).toEqual([['A']]);
expect(r.summary).toBe(`시간이 다 됐어요. 사과 ${s.score.A}개를 지웠어요`);
@@ -220,7 +220,8 @@ describe('진행', () => {
expect(solo.phase).toBe('ended');
});
test('클라이언트 액션 스키마에는 select만(tick/leave는 시스템 전용)', () => {
test('클라이언트 액션 스키마에는 select·stop만(tick/leave는 시스템 전용)', () => {
expect(apple.actionSchema.safeParse({ type: 'stop' }).success).toBe(true);
expect(apple.actionSchema.safeParse({ type: 'tick' }).success).toBe(false);
expect(apple.actionSchema.safeParse({ type: 'leave' }).success).toBe(false);
expect(apple.actionSchema.safeParse({ type: 'select', r0: 0, c0: 0, r1: 9, c1: 16 }).success).toBe(true);
@@ -229,6 +230,47 @@ describe('진행', () => {
});
});
describe('제한 시간 무제한', () => {
test('마감 없음: 모두 막히거나 「여기까지」하면 끝, 시간 제한 방에서는 여기까지 거절', () => {
let s = make(['A', 'B'], { timeLimitSec: null });
expect(s.endsAt).toBeNull();
expect(apple.deadline!(s)).toBe(s.countdownEndsAt);
expect(reason(s, 'A', { type: 'stop' }, T0 + 100)).toBe('곧 시작해요. 잠시만 기다려 주세요.');
s = tick(s, START);
expect(s.phase).toBe('playing');
expect(s.status.A).toBe('playing'); // the start tick is not an away tick
expect(apple.deadline!(s)).toBeNull();
expect(apple.timeoutNotBefore!(s)).toBeNull();
// Hours later the board still takes moves.
const m = findMoves(s.initial)[0]!;
s = act(s, 'A', sel(m), START + 3_600_000);
expect(s.score.A).toBeGreaterThan(0);
s = act(s, 'A', { type: 'stop' }, START + 3_600_100);
expect(s.status.A).toBe('done');
expect(reason(s, 'A', { type: 'stop' }, START + 3_600_200)).toBe('이미 끝냈어요.');
expect(apple.activePlayers(s)).toEqual(['B']);
expect(apple.timeoutPlayers!(s)).toEqual(['B']);
s = act(s, 'B', { type: 'stop' }, START + 3_600_300);
expect(s.phase).toBe('ended');
const r = apple.result(s)!;
expect(r.ranking).toEqual([['A'], ['B']]);
expect(r.summary).toContain('모두 끝냈어요');
expect(reason(tick(make(['A']), START), 'A', { type: 'stop' }, START + 10)).toBe('제한 시간이 있는 방에서는 끝날 때까지 해요.');
});
test('자리 비움: 방이 유예 뒤 tick을 보내면 그 사람은 여기까지(점수 유지), 혼자면 바로 끝', () => {
let s = tick(make(['A', 'B'], { timeLimitSec: null }), START);
s = act(s, 'B', sel(findMoves(s.initial)[0]!), START + 500);
s = apple.apply(s, 'B', { type: 'tick' }, { rng: rng(), now: START + 60_000 }).state;
expect(s.status.B).toBe('done');
expect(s.score.B).toBeGreaterThan(0);
expect(s.phase).toBe('playing');
const solo = apple.apply(tick(make(['A'], { timeLimitSec: null }), START), 'A', { type: 'tick' }, { rng: rng(), now: START + 60_000 }).state;
expect(solo.phase).toBe('ended');
expect(apple.result(solo)!.summary).toBe('여기까지 했어요. 사과 0개를 지웠어요');
});
});
describe('무작위 대국', () => {
test.each([1, 2, 5, 8])('%i명: 엔진 randomPlayout(유출·JSON·결정성) 끝까지', (n) => {
const players = Array.from({ length: n }, (_, i) => `p${i + 1}`);
@@ -244,4 +286,11 @@ describe('무작위 대국', () => {
for (const p of players) expect(s.score[p]).toBe([...s.boards[p]!].filter((c) => c === '0').length);
}
});
test.each([1, 3])('무제한 %i명: 끝까지(여기까지·자리 비움 tick 포함)', (n) => {
const players = Array.from({ length: n }, (_, i) => `p${i + 1}`);
for (let i = 0; i < playoutSeeds(10); i++) {
const a = randomPlayout(apple, { players, options: apple.optionsSchema.parse({ timeLimitSec: null }), seed: seedN(900 + n * 10 + i), maxSteps: 1000, maxApplyMs: 20 });
expect(a.finished).toBe(true);
}
});
});