From a32c085aede33ef75f86d697c04b0fb9c3e93869 Mon Sep 17 00:00:00 2001 From: Mike Isom <103458985+MikeIsom@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:03:34 -0700 Subject: [PATCH] Show every viewer the same limited-log window The limited log started at each player's own last turn, so how much history you saw depended on your seat: right after your turn you saw almost nothing. Everyone, spectators included, now sees the current turn and the full round of turns before it (one turn per seat). This matches the old window on your own turn and is never shorter. --- AGENTS.md | 3 +- docs/admin/rules.md | 4 +- packages/engine/src/limited-log.spec.ts | 72 ++++++++++++++++++------- packages/engine/src/limited-log.ts | 28 ++++------ packages/engine/src/view.ts | 2 +- packages/engine/wrapper.ts | 6 +-- rules.md | 15 +++--- 7 files changed, 81 insertions(+), 49 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 59b0fb9..bfd5d18 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,7 +56,8 @@ Use Node 24 and pnpm 11. Inspect the working tree before editing and preserve un after all merger resolution. Keep the default Off. - Two tiles per turn and limited game log are optional, default Off. Two-tile turns retain private undo and one turn increment. Limited logs must filter both entries and BGS summaries; - four-hands spectators use the active player's window. Replay unlocks at game end. + every viewer sees the same window (current turn plus the previous round, one turn per seat). + Replay unlocks at game end. ## Setup options and player preferences diff --git a/docs/admin/rules.md b/docs/admin/rules.md index fc78fbb..cc02f19 100644 --- a/docs/admin/rules.md +++ b/docs/admin/rules.md @@ -144,13 +144,13 @@ Everything is shown once the game ends. ### Limited game log -Much of Acquire is remembering who bought what. If the game uses **Limited game log**, the log only shows what has happened since your last turn. During a merger, the log still shows everything about that merger, even if it started before your last turn. The full log opens up once the game ends. +Much of Acquire is remembering who bought what. If the game uses **Limited game log**, the log only shows the current turn and the full round of turns before it: one turn for each seat, so you always see what every other player did since your last turn. Everyone, including spectators, sees the same part of the log. A merger in progress is always shown in full. The full log opens up once the game ends. Because replaying the game would show the full history, replay is only available after the game ends when this setting is on. ## Game options -- **Limited game log:** the log shows only what happened since your last turn, until the game ends (see above). +- **Limited game log:** the log shows only the current turn and the round before it, until the game ends (see above). - **Two tiles per turn:** hands of 8 tiles and two tiles placed every turn (see above). - **Shares per turn:** buy up to 3 (standard), 4 or 5 shares in total per turn, independently of stock swaps. - **Stock swap:** optional 1:1 exchanges with the bank before buying; Off / 3 / 5 / 7 / Unlimited shares per turn (see above). diff --git a/packages/engine/src/limited-log.spec.ts b/packages/engine/src/limited-log.spec.ts index e871678..3e43023 100644 --- a/packages/engine/src/limited-log.spec.ts +++ b/packages/engine/src/limited-log.spec.ts @@ -44,28 +44,71 @@ test("§15 limitedLog defaults off: every viewer gets the whole log", () => { } }); -test("§13 limitedLog: a player sees the log from the start of their last turn, with setup kept", () => { +/** Index of the `count`-th last turn entry (1 = the current turn). */ +function nthLastTurn(state: GameState, count: number): number { + return state.log.flatMap((entry, index) => (entry.type === "turn" ? [index] : [])).at(-count)!; +} + +test("§13 limitedLog: everyone sees the current turn and the full round before it, with setup kept", () => { const state = initGame(4, LIMITED, "window"); playUntil(state, lcg(2), (s) => s.turn > 14 && s.phase === "place"); - const active = state.activeSeat; - for (let player = 0; player < 4; player++) { + const start = nthLastTurn(state, 5); + assert.equal(logWindowStart(state), start); + const spectator = wrapper.stripSecret(state, undefined).log; + for (const player of [0, 1, 2, 3]) { const view = wrapper.stripSecret(state, player); assert.equal(view.log.length, state.log.length, "the log keeps its length for turn drafts"); - const turns = turnIndexes(state, player); - // While it is your turn, the window starts at your previous one. - const start = player === active ? turns.at(-2)! : turns.at(-1)!; - assert.equal(logWindowStart(state, player), start); view.log.forEach((entry, index) => { const setup = ["init", "optionIgnored", "turnOrder"].includes(state.log[index]!.type); assert.deepEqual(entry, index >= start || setup ? state.log[index] : { type: "hidden" }, `entry ${index}`); }); + assert.deepEqual(view.log, spectator, "every seat and spectators see the same window"); assert.ok(hiddenCount(view.log) > 0); + // The window always reaches back to the start of your own previous turn. + assert.ok(start <= turnIndexes(state, player).at(player === state.activeSeat ? -2 : -1)!); } +}); + +test("§13 limitedLog: seat 0 sees the full previous round during seat 1's turn (owner's report)", () => { + const state = initGame(4, LIMITED, "first-seat"); + playUntil(state, lcg(7), (s) => s.turn > 8 && s.activeSeat === 1 && s.phase === "place"); + const start = nthLastTurn(state, 5); + const view = wrapper.stripSecret(state, 0).log; + assert.deepEqual(view.slice(start), state.log.slice(start)); assert.deepEqual( - wrapper.stripSecret(state, undefined).log, - wrapper.stripSecret(state, active).log, - "spectators see what the active player sees" + state.log.slice(start).flatMap((entry) => (entry.type === "turn" ? [entry.seat] : [])), + [1, 2, 3, 0, 1], + "seat 0 sees seats 1, 2 and 3's turns as well as its own" ); + assert.ok(start < turnIndexes(state, 0).at(-1)!, "the old rule started at seat 0's own turn, hiding the others"); +}); + +test("§13 limitedLog: four-hands uses all four seats for the round, for players and spectators", () => { + const state = initGame(2, { ...LIMITED, twoPlayerMode: "fourHands" }, "four-hands-window"); + playUntil(state, lcg(2), (s) => s.turn > 14 && s.phase === "place"); + assert.equal(logWindowStart(state), nthLastTurn(state, 5)); + assert.deepEqual(wrapper.stripSecret(state).log, wrapper.stripSecret(state, 0).log); + assert.deepEqual(wrapper.stripSecret(state, 1).log, wrapper.stripSecret(state, 0).log); +}); + +test("§13 limitedLog: the window is never shorter than the old one from your own last turn", () => { + for (let players = 2; players <= 6; players++) { + for (const options of [LIMITED, { ...LIMITED, twoPlayerMode: "fourHands" }]) { + const state = initGame(players, options, `never-less-${players}`); + const random = lcg(players * 13); + while (!state.ended) { + const start = logWindowStart(state); + for (let seat = 0; seat < state.seats.length; seat++) { + const own = turnIndexes(state, seat).filter((index) => index < nthLastTurn(state, 1)); + if (own.length > 0) { + assert.ok(start <= own.at(-1)!, `${players} players, seat ${seat}`); + } + } + const moves = legalMoves(state).filter((move) => move.type !== "announce"); + applyMove(state, moves[Math.floor(random() * moves.length)]!, currentSeat(state)!); + } + } + } }); test("§13 limitedLog: a merger in progress stays fully visible to every disposer", () => { @@ -88,8 +131,8 @@ test("§13 limitedLog: a merger in progress stays fully visible to every dispose test("§13 limitedLog: visible turn summaries cannot reveal an earlier hidden turn", () => { const state = initGame(4, LIMITED, "summary-window"); playUntil(state, lcg(2), (s) => s.turn > 14 && s.phase === "place"); + const start = logWindowStart(state); for (const player of [0, 1, 2, 3, undefined]) { - const start = logWindowStart(state, player); assert.ok(start > 0); const view = wrapper.stripSecret(state, player); assert.equal(view.log[start - 1]!.type, "hidden"); @@ -98,13 +141,6 @@ test("§13 limitedLog: visible turn summaries cannot reveal an earlier hidden tu } }); -test("§13 limitedLog: four-hands spectators use both seats of the active player", () => { - const state = initGame(2, { ...LIMITED, twoPlayerMode: "fourHands" }, "spectator-window"); - playUntil(state, lcg(2), (s) => s.turn > 14 && s.phase === "place"); - const owner = state.seatOwner[state.activeSeat]!; - assert.deepEqual(wrapper.stripSecret(state).log, wrapper.stripSecret(state, owner).log); -}); - test("§13 limitedLog: the whole log is revealed once the game ends", () => { const state = initGame(3, LIMITED, "revealed"); playUntil(state, lcg(3)); diff --git a/packages/engine/src/limited-log.ts b/packages/engine/src/limited-log.ts index 4735880..ad3cc9e 100644 --- a/packages/engine/src/limited-log.ts +++ b/packages/engine/src/limited-log.ts @@ -1,37 +1,31 @@ import type { GameState, LogEntry } from "./types.js"; -import { seatsOf } from "./view.js"; /** Setup entries describe options and turn order, not play, so they always stay visible. */ const SETUP: LogEntry["type"][] = ["init", "optionIgnored", "turnOrder"]; /** - * rules.md §13 limitedLog: the first log index `player` may read (undefined for a - * spectator). Players see from the start of their own last turn before the current one, so - * the current turn, including a merger in progress, is always visible. Spectators see as much - * as the active player. The whole log is visible when the option is off or the game is over. + * rules.md §13 limitedLog: the first log index anyone may read. Every player and spectator + * sees the same window: the current turn, including a merger in progress, and the full round + * of turns before it (one turn per seat, so four in fourHands). It always reaches back at least + * to the start of each player's own previous turn, wherever they sit. The whole log is visible + * when the option is off or the game is over. */ -export function logWindowStart(state: GameState, player: number | undefined): number { +export function logWindowStart(state: GameState): number { if (!state.options.limitedLog || state.ended) { return 0; } - const own = seatsOf(state, player ?? state.seatOwner[state.activeSeat]); - let current = true; + let turns = 0; for (let index = state.log.length - 1; index >= 0; index--) { - const entry = state.log[index]!; - if (entry.type !== "turn") { - continue; - } - if (!current && own.includes(entry.seat)) { + if (state.log[index]!.type === "turn" && ++turns > state.seats.length) { return index; } - current = false; } return 0; } -/** The log as `player` may read it: earlier entries become placeholders, keeping its length. */ -export function visibleLog(state: GameState, player: number | undefined): LogEntry[] { - const start = logWindowStart(state, player); +/** The log as anyone may read it: earlier entries become placeholders, keeping its length. */ +export function visibleLog(state: GameState): LogEntry[] { + const start = logWindowStart(state); return state.log.map((entry, index) => index >= start || SETUP.includes(entry.type) ? structuredClone(entry) : { type: "hidden" } ); diff --git a/packages/engine/src/view.ts b/packages/engine/src/view.ts index c362685..e8747af 100644 --- a/packages/engine/src/view.ts +++ b/packages/engine/src/view.ts @@ -53,7 +53,7 @@ export function viewFor(state: GameState, player: number | undefined): GameState seed: "", rngCounter: 0, pool: state.pool.map(() => HIDDEN), - log: visibleLog(state, player), + log: visibleLog(state), seats: state.seats.map((seat, index) => { if (own.includes(index)) { return structuredClone(seat); diff --git a/packages/engine/wrapper.ts b/packages/engine/wrapper.ts index cd7e9db..1f5c5ce 100644 --- a/packages/engine/wrapper.ts +++ b/packages/engine/wrapper.ts @@ -73,8 +73,8 @@ export interface LogSliceOptions { } // Both endpoints are inclusive. The log is public (rules.md §13) except with limitedLog, where -// entries before the player's window are placeholders. Each entry gets a `simple` line for -// BGS's last-move display. +// entries before the shared window (the current turn and the round before it) are placeholders +// for every viewer. Each entry gets a `simple` line for BGS's last-move display. export function logSlice( data: GameState, options?: LogSliceOptions @@ -84,7 +84,7 @@ export function logSlice( } { const start = Math.max(0, options?.start ?? 0); const end = options?.end ?? data.log.length - 1; - const log = visibleLog(data, options?.player); + const log = visibleLog(data); // Summaries must use the same filtered history: a visible turn can follow hidden moves. const shown = { ...data, log }; return { diff --git a/rules.md b/rules.md index 5c512f0..482bc34 100644 --- a/rules.md +++ b/rules.md @@ -352,12 +352,13 @@ Each viewer must only receive information their player is entitled to. every action: tile placements, stock purchases, bonuses paid, and each player's disposal choices. Only the *current* holdings and cash are hidden, even though they can be reconstructed from the log. -- **Game option `limitedLog` (default: `false`):** each player sees only the log from the - start of their own last turn before the current one, so the current turn, including a - merger in progress, is always shown. Spectators see as much as the active player. - Setup entries (options, turn order) stay visible. Earlier entries are replaced by - placeholders, keeping the log's length. The whole log is revealed when the game ends, - and replay is only available after that. +- **Game option `limitedLog` (default: `false`):** everyone sees the same part of the log: + the current turn, including a merger in progress, and the full round of turns before it + (one turn per seat, so four turns in four-hands games). **[DECISION]** Every player and + spectator gets this same window, wherever they sit, and it always reaches back at least to + the start of their own previous turn. Setup entries (options, turn order) stay visible. + Earlier entries are replaced by placeholders, keeping the log's length. The whole log is + revealed when the game ends, and replay is only available after that. - **[DECISION] Scores during play:** Unless holdings are `public`, every player's score is 0 until the game ends, including at the `cash` and `cashAndShareCount` levels. At `public`, the score is projected net worth: cash, @@ -402,7 +403,7 @@ switches on one engine, not as separate code paths. Defaults reproduce the stand | `sharesPerTurn` | 3 / 4 / 5 | 3 | Maximum shares purchased per turn in total across all active chains (house rule). Independent of stock swaps; see §9. | | `stockSwap` | `off` / 3 / 5 / 7 / `unlimited` | `off` | Optional 1:1 exchanges with the bank before buying, paying or receiving the price difference. See §9.1. | | `twoTiles` | true / false | false | Hands of 8 tiles and two placements per turn (house rule). See §4.1. | -| `limitedLog` | true / false | false | The log shows only what happened since your last turn until the game ends (house rule). See §13. | +| `limitedLog` | true / false | false | The log shows only the current turn and the round before it until the game ends (house rule). See §13. | | `endSize` | 41 / 31 | 41 | The chain size that triggers the end condition in §11.1. Setting 31 gives a shorter game (house rule). Does not change the safe size (11) or the price table. | **[DECISION]** Invalid combinations are never rejected. An option that does not apply to