같은 판 경주: 포기·실패한 사람에게는 다른 사람이 푸는 동안 정답을 보내지 않음(다 풀었거나 게임이 끝났을 때만), 지뢰찾기는 밟은 지뢰만 바로 표시
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 | 검증 |
|
||||
|---|---|---|
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
- `GameResult.scores` = 진행도.
|
||||
|
||||
## 3. 보기(view)·타이머
|
||||
- 내 view: 내 판(게임이 정한 모양, 내가 끝났거나 게임이 끝나면 정답까지 보여 줌 `reveal`) + 모두의 상태·진행도·진행 문구·걸린 시간. 다른 사람 판은 보내지 않는다. 관전자는 판 없이 진행 상황만.
|
||||
- 내 view: 내 판(게임이 정한 모양, 내가 다 풀었거나 게임이 끝나면 정답까지 보여 줌 `reveal`. 실패·포기한 사람에게는 게임이 끝날 때까지 정답을 보내지 않는다 — 보조 참가자가 포기해 정답을 받아 다른 사람에게 알려 주는 것을 막기 위해) + 모두의 상태·진행도·진행 문구·걸린 시간. 다른 사람 판은 보내지 않는다. 관전자는 판 없이 진행 상황만.
|
||||
- 같은 판을 푸는 게임이라 "남의 비밀"은 없고, 숨길 것은 **아직 열지 않은 정답**(지뢰 위치, 뒤집힌 카드, 스도쿠·노노그램 답)뿐이다. 그래서 엔진 공통 검사(`checkNoLeak`)는 카운트다운만 보고, 각 게임 테스트가 "끝나기 전 내 view에 정답이 없다"를 따로 확인한다.
|
||||
- `deadline`: 카운트다운 끝 / 마감. `timeoutNotBefore` = 같은 값이라 연결이 끊긴 사람이 일찍 시간 초과되지 않는다. 무제한이면 진행 중 마감이 없고, 끊긴 채 유예 시간이 지난 사람만 `tick`으로 포기(`done`) 처리.
|
||||
- 컴퓨터 연습방이 사람 없이도 끝나도록 게임마다 **기본 제한 시간이 있다**(무제한은 고를 때만).
|
||||
|
||||
@@ -164,7 +164,7 @@ export const minesweeper = makeRaceGame<MinesweeperPuzzle, MinesweeperBoard, Min
|
||||
const f = b.flags[i] === '1';
|
||||
if (f) flags++;
|
||||
if (b.open[i] === '1') cells += p.field[i];
|
||||
else if (reveal && b.boom === i) cells += '!';
|
||||
else if (b.boom === i) cells += '!'; // my own mine, shown at once (it says nothing about the others)
|
||||
else if (reveal && f) cells += p.field[i] === '*' ? 'F' : 'x';
|
||||
else if (reveal && p.field[i] === '*') cells += '*';
|
||||
else cells += f ? 'F' : '#';
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('열기·깃발·한꺼번에 열기', () => {
|
||||
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')!;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,7 +109,10 @@ export interface RaceSpec<P, B, M extends { type: string }, BV, O extends { time
|
||||
/** Korean reason the move is refused, or null. Only called while the player is playing. */
|
||||
checkMove(puzzle: P, board: B, move: M, options: O): string | null;
|
||||
applyMove(puzzle: P, board: B, move: M, ctx: { rng: Rng; now: number; options: O }): MoveOutcome<B>;
|
||||
/** 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<P, B, M extends { type: string }, BV, O extends { t
|
||||
|
||||
view(s, viewer) {
|
||||
const me = viewer && s.order.includes(viewer) ? viewer : null;
|
||||
const reveal = !!me && (s.phase === 'ended' || s.status[me] !== 'playing');
|
||||
const reveal = !!me && (s.phase === 'ended' || s.status[me] === 'solved');
|
||||
return {
|
||||
options: s.options,
|
||||
me,
|
||||
|
||||
@@ -152,6 +152,16 @@ describe('sudoku · 숫자·지우기·메모·힌트', () => {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user