같은 판 경주: 포기·실패한 사람에게는 다른 사람이 푸는 동안 정답을 보내지 않음(다 풀었거나 게임이 끝났을 때만), 지뢰찾기는 밟은 지뢰만 바로 표시

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-24 14:36:21 +09:00
parent 9f9d20a641
commit c2aaff5762
7 changed files with 39 additions and 11 deletions

View File

@@ -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' : '#';

View File

@@ -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')!;

View File

@@ -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);
}
});
});

View File

@@ -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,

View File

@@ -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);