From c2aaff5762934d3d9481e3d5a259e7b7dce07f4c Mon Sep 17 00:00:00 2001 From: EJClaw Date: Tue, 24 Nov 2026 14:36:21 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=99=EC=9D=80=20=ED=8C=90=20=EA=B2=BD?= =?UTF-8?q?=EC=A3=BC:=20=ED=8F=AC=EA=B8=B0=C2=B7=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=ED=95=9C=20=EC=82=AC=EB=9E=8C=EC=97=90=EA=B2=8C=EB=8A=94=20?= =?UTF-8?q?=EB=8B=A4=EB=A5=B8=20=EC=82=AC=EB=9E=8C=EC=9D=B4=20=ED=91=B8?= =?UTF-8?q?=EB=8A=94=20=EB=8F=99=EC=95=88=20=EC=A0=95=EB=8B=B5=EC=9D=84=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EC=A7=80=20=EC=95=8A=EC=9D=8C(=EB=8B=A4=20?= =?UTF-8?q?=ED=92=80=EC=97=88=EA=B1=B0=EB=82=98=20=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=EC=9D=B4=20=EB=81=9D=EB=82=AC=EC=9D=84=20=EB=95=8C=EB=A7=8C),?= =?UTF-8?q?=20=EC=A7=80=EB=A2=B0=EC=B0=BE=EA=B8=B0=EB=8A=94=20=EB=B0=9F?= =?UTF-8?q?=EC=9D=80=20=EC=A7=80=EB=A2=B0=EB=A7=8C=20=EB=B0=94=EB=A1=9C=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- docs/games/minesweeper.md | 2 +- docs/games/race.md | 2 +- packages/games/src/minesweeper/index.ts | 2 +- .../games/src/minesweeper/minesweeper.test.ts | 15 +++++++++++++-- packages/games/src/nonogram/nonogram.test.ts | 8 ++++++-- packages/games/src/race/index.ts | 7 +++++-- packages/games/src/sudoku/sudoku.test.ts | 14 ++++++++++++-- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/games/minesweeper.md b/docs/games/minesweeper.md index 8b6525c..a80dfb6 100644 --- a/docs/games/minesweeper.md +++ b/docs/games/minesweeper.md @@ -34,7 +34,7 @@ puzzle: { rows, cols, mines, field: string /* '*' 또는 '0'..'8' */, start: number } board: { open: string /* '1' 연 칸 */, flags: string, opened: number, boom: number | null } view.board: { rows, cols, mines, cells: string, flags } -// cells: '#' 닫힘, 'F' 깃발, '0'..'8' 연 칸; 내가 끝났거나 게임이 끝나면 '*' 지뢰, '!' 터진 지뢰, 'x' 잘못 꽂은 깃발 +// cells: '#' 닫힘, 'F' 깃발, '0'..'8' 연 칸, '!' 내가 밟은 지뢰; 게임이 끝나면(다 풀었으면 바로) '*' 지뢰, 'x' 잘못 꽂은 깃발 ``` | type | payload | 검증 | |---|---|---| diff --git a/docs/games/race.md b/docs/games/race.md index 018ed4f..07665ec 100644 --- a/docs/games/race.md +++ b/docs/games/race.md @@ -22,7 +22,7 @@ - `GameResult.scores` = 진행도. ## 3. 보기(view)·타이머 -- 내 view: 내 판(게임이 정한 모양, 내가 끝났거나 게임이 끝나면 정답까지 보여 줌 `reveal`) + 모두의 상태·진행도·진행 문구·걸린 시간. 다른 사람 판은 보내지 않는다. 관전자는 판 없이 진행 상황만. +- 내 view: 내 판(게임이 정한 모양, 내가 다 풀었거나 게임이 끝나면 정답까지 보여 줌 `reveal`. 실패·포기한 사람에게는 게임이 끝날 때까지 정답을 보내지 않는다 — 보조 참가자가 포기해 정답을 받아 다른 사람에게 알려 주는 것을 막기 위해) + 모두의 상태·진행도·진행 문구·걸린 시간. 다른 사람 판은 보내지 않는다. 관전자는 판 없이 진행 상황만. - 같은 판을 푸는 게임이라 "남의 비밀"은 없고, 숨길 것은 **아직 열지 않은 정답**(지뢰 위치, 뒤집힌 카드, 스도쿠·노노그램 답)뿐이다. 그래서 엔진 공통 검사(`checkNoLeak`)는 카운트다운만 보고, 각 게임 테스트가 "끝나기 전 내 view에 정답이 없다"를 따로 확인한다. - `deadline`: 카운트다운 끝 / 마감. `timeoutNotBefore` = 같은 값이라 연결이 끊긴 사람이 일찍 시간 초과되지 않는다. 무제한이면 진행 중 마감이 없고, 끊긴 채 유예 시간이 지난 사람만 `tick`으로 포기(`done`) 처리. - 컴퓨터 연습방이 사람 없이도 끝나도록 게임마다 **기본 제한 시간이 있다**(무제한은 고를 때만). diff --git a/packages/games/src/minesweeper/index.ts b/packages/games/src/minesweeper/index.ts index 096c5cb..95b52e9 100644 --- a/packages/games/src/minesweeper/index.ts +++ b/packages/games/src/minesweeper/index.ts @@ -164,7 +164,7 @@ export const minesweeper = makeRaceGame { expect(reason(s, 'A', { type: 'flag', i: s.puzzle.start })).toContain('이미 연 칸'); }); - test('지뢰를 밟으면 실패(시간 멈춤), 내 화면에 지뢰가 모두 보이고 다른 사람은 계속', () => { + test('지뢰를 밟으면 실패(시간 멈춤), 다른 사람이 푸는 동안에는 밟은 지뢰만 보이고 끝나면 모두 보임', () => { let s = started(); const m = mines(s)[0]!; s = act(s, 'A', { type: 'open', i: m }, START + 5000); @@ -83,8 +83,12 @@ describe('열기·깃발·한꺼번에 열기', () => { expect(s.status.B).toBe('playing'); const v = minesweeper.view(s, 'A'); expect(v.board!.cells[m]).toBe('!'); - expect([...v.board!.cells].filter((c) => c === '*' || c === '!')).toHaveLength(s.puzzle.mines); + // The other mines stay hidden from A while B still plays (A could pass them on). + expect(v.board!.cells).not.toContain('*'); expect(v.seats.find((x) => x.id === 'A')!.timeMs).toBe(5000); + const ended = act(s, 'B', { type: 'stop' }, START + 6000); + expect(ended.phase).toBe('ended'); + expect([...minesweeper.view(ended, 'A').board!.cells].filter((c) => c === '*' || c === '!')).toHaveLength(s.puzzle.mines); // B's screen still shows nothing of the mines. expect(minesweeper.view(s, 'B').board!.cells).not.toContain('*'); expect(reason(s, 'A', { type: 'open', i: safe(s)[0]! })).toBe('이미 끝냈어요.'); @@ -161,6 +165,13 @@ describe('순위·끝', () => { expect(minesweeper.result(s)!.scoreText!.C).toContain('포기'); }); + test('포기한 사람도 다른 사람이 푸는 동안에는 지뢰 위치를 받지 않아요', () => { + let s = started(['A', 'B']); + s = act(s, 'A', { type: 'stop' }); + expect(s.status.A).toBe('done'); + expect(minesweeper.view(s, 'A').board!.cells).not.toMatch(/[*!x]/); + }); + test('제한 시간: 마감 tick으로 끝, 마감 뒤 거절, 아무도 못 풀면 연 칸 많은 사람이 이김', () => { let s = started(['A', 'B'], { timeLimitSec: 180 }); const i = safe(s).find((j) => s.puzzle.field[j] !== '0')!; diff --git a/packages/games/src/nonogram/nonogram.test.ts b/packages/games/src/nonogram/nonogram.test.ts index 56ba6f6..2a504e1 100644 --- a/packages/games/src/nonogram/nonogram.test.ts +++ b/packages/games/src/nonogram/nonogram.test.ts @@ -272,7 +272,7 @@ describe('nonogram · 순위·끝', () => { }); describe('nonogram · 숨긴 답', () => { - test('끝내기 전 내 화면(과 관전 화면)에는 답 문자열도 그림 이름도 없고, 끝낸 뒤에만 보임', () => { + test('다 풀거나 게임이 끝나기 전에는 내 화면(과 관전 화면)에 답 문자열도 그림 이름도 없음, 포기해도 남이 푸는 동안은 안 보임', () => { for (let seed = 1; seed <= 12; seed++) { const size = ([5, 10, 15] as const)[seed % 3]!; let s = started(['A', 'B'], { size }, seed); @@ -293,9 +293,13 @@ describe('nonogram · 숨긴 답', () => { } if (s.status.A !== 'playing') continue; s = act(s, 'B', { type: 'stop' }, START + 60_000); - expect(JSON.stringify(nonogram.view(s, 'B'))).toContain(s.puzzle.name); + // B gave up but A is still solving: B must not get the answer to pass on. + hidden('B'); hidden('A'); hidden(null); + s = act(s, 'A', { type: 'stop' }, START + 61_000); + expect(s.phase).toBe('ended'); + expect(JSON.stringify(nonogram.view(s, 'B'))).toContain(s.puzzle.name); } }); }); diff --git a/packages/games/src/race/index.ts b/packages/games/src/race/index.ts index 6aafd4b..88ec5eb 100644 --- a/packages/games/src/race/index.ts +++ b/packages/games/src/race/index.ts @@ -109,7 +109,10 @@ export interface RaceSpec; - /** What the player sees of their own board. `reveal` = they are finished or the game is over (show the answer). */ + /** + * What the player sees of their own board. `reveal` = they solved it or the game is over (show the answer). Not after + * failing or giving up while others still play: they could pass the answer on. + */ boardView(puzzle: P, board: B, reveal: boolean, options: O): BV; /** Bigger is better; ranks players who did not solve. */ progress(puzzle: P, board: B): number; @@ -316,7 +319,7 @@ export function makeRaceGame { expect(s.phase).toBe('ended'); expect(sudoku.view(s, 'B').board!.solution).toBe(s.puzzle.solution); }); + + test('포기한 사람은 다른 사람이 푸는 동안 정답을 받지 않고, 게임이 끝나면 받아요', () => { + let s = started(['A', 'B']); + s = act(s, 'B', { type: 'stop' }); + expect(s.status.B).toBe('done'); + expect(JSON.stringify(sudoku.view(s, 'B'))).not.toContain(s.puzzle.solution); + s = act(s, 'A', { type: 'stop' }); + expect(s.phase).toBe('ended'); + expect(sudoku.view(s, 'B').board!.solution).toBe(s.puzzle.solution); + }); }); describe('sudoku · 순위·끝', () => { @@ -210,7 +220,7 @@ describe('sudoku · 순위·끝', () => { }); describe('sudoku · 무작위 대국', () => { - test('1·2·5·8명, 난이도 셋: 유출·JSON·결정성, 다 풀기 전 내 화면에 정답 없음', () => { + test('1·2·5·8명, 난이도 셋: 유출·JSON·결정성, 다 풀거나 게임이 끝나기 전 내 화면에 정답 없음(포기해도)', () => { for (let k = 1; k <= playoutSeeds(60); k++) { for (const n of [1, 2, 5, 8]) { const difficulty = (['easy', 'normal', 'hard'] as const)[k % 3]!; @@ -218,7 +228,7 @@ describe('sudoku · 무작위 대국', () => { const options = sudoku.optionsSchema.parse({ difficulty, hints: k % 2 === 0, timeLimitSec: k % 2 ? null : 600 }); const invariant = (st: unknown) => { const s = st as SudokuState; - for (const p of players) if (s.phase !== 'ended' && s.status[p] === 'playing') expect(JSON.stringify(sudoku.view(s, p))).not.toContain(s.puzzle.solution); + for (const p of players) if (s.phase !== 'ended' && s.status[p] !== 'solved') expect(JSON.stringify(sudoku.view(s, p))).not.toContain(s.puzzle.solution); }; const a = randomPlayout(sudoku, { players, options, seed: seedN(k * 10 + n), maxSteps: 3000, invariant }); expect(a.finished).toBe(true);