Merge holdings visibility levels and shared limited-log window

# Conflicts:
#	docs/admin/rules.md
#	packages/engine/src/options.spec.ts
#	packages/viewer/src/dev.ts
#	rules.md
This commit is contained in:
Mike Isom 2026-11-04 07:05:36 -07:00
commit 2ddf04aa88
43 changed files with 576 additions and 128 deletions

View file

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

View file

@ -35,7 +35,7 @@ as each player sees it. With hot seat on, it switches to whoever must act, so on
play every seat. The toolbar plays random moves, jumps to the next merger, and switches
player, theme and language.
URL parameters: `players=2..6`, `seed=...`, `publicHoldings=1`, `teamPlay=1`, `autoEnd=1`,
URL parameters: `players=2..6`, `seed=...`, `holdingsVisibility=cash` (or `cashAndShareCount`, `public`; legacy `publicHoldings=1`), `teamPlay=1`, `autoEnd=1`,
`endSize=31`, `twoPlayerMode=fourHands`, `stockSwap=3` (or `5`, `7`, `unlimited`), `twoTiles=1`, `limitedLog=1`, `theme=light|dark`, `locale=de`, `moves=50` (random
moves on load), `merger=1` (continue to the next merger).

View file

@ -44,10 +44,28 @@
],
"options": [
{
"name": "publicHoldings",
"label": "Public holdings (everyone sees all stock and cash)",
"type": "checkbox",
"default": false
"name": "holdingsVisibility",
"label": "What players see of each other's cash and stock",
"type": "select",
"default": "private",
"items": [
{
"name": "private",
"label": "Private (standard)"
},
{
"name": "cash",
"label": "Cash only"
},
{
"name": "cashAndShareCount",
"label": "Cash and total share count"
},
{
"name": "public",
"label": "Everything (public holdings)"
}
]
},
{
"name": "teamPlay",

View file

@ -136,22 +136,28 @@ With two players, the bank also acts as a shareholder whenever bonuses are paid.
## What you can see
Your tiles are private. Unless the game was created with **public holdings**, each player's cash and shares are private too; the game log is public (unless the game uses a limited game log, below), so a careful player can work them out.
Your tiles are private. By default, each player's cash and shares are private too; the game log is public (unless the game uses a limited game log, below), so a careful player can work them out. The game's creator can make more visible:
- **Cash only:** everyone's exact cash is shown.
- **Cash and total share count:** everyone's exact cash and how many shares they hold in total are shown, but not which chains they are in.
- **Everything (public holdings):** everyone's cash and shares are shown, along with an estimated net worth.
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:** two tiles placed every turn (see above).
- **Tiles in hand:** 6 (standard), 8, 10 or 12 tiles in each hand, with or without two tiles per turn.
- **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).
- **Public holdings:** everyone's cash and shares are visible.
- **What players see of each other's cash and stock:** private (standard), cash only, cash and total share count, or everything (see above).
- **Team play** (4 players only): seats 1 and 3 play against seats 2 and 4; each team's money is added together at the end.
- **Two-player mode:** *Bank as third shareholder* (above) or *Four hands*, where each player controls two seats in a normal four-seat game and the player with the single richest seat wins.
- **End automatically when an end condition is met:** the game ends at the end of that turn, with no announcement.

View file

@ -146,7 +146,7 @@ do not replace other declarations from an old local snapshot.
Current declaration sources are in [admin/gameinfo.json](admin/gameinfo.json):
- Setup options include public holdings, team play, two-player mode, automatic ending, end size,
- Setup options include holdings visibility (private / cash / cash and share count / public), team play, two-player mode, automatic ending, end size,
**Shares per turn: 3 (standard) / 4 / 5**, **Stock swap: Off / 3 / 5 / 7 / Unlimited**,
two tiles per turn and limited game log.
Stock swaps, two tiles per turn and limited logs default Off.

View file

@ -8,7 +8,7 @@ import { parseTile } from "./tiles.js";
import { chainAt, scenario } from "./test/helpers.js";
import type { GameState, LogEntry } from "./types.js";
import { simpleLine } from "./simple.js";
import { HIDDEN, seatsOf } from "./view.js";
import { HIDDEN, seatsOf, visibilityNow } from "./view.js";
import * as wrapper from "../wrapper.js";
const OPTION_SETS: Record<string, unknown>[] = [
@ -17,8 +17,14 @@ const OPTION_SETS: Record<string, unknown>[] = [
{ teamPlay: true },
{ twoPlayerMode: "fourHands" },
{ twoPlayerMode: "fourHands", publicHoldings: true },
{ holdingsVisibility: "cash" },
{ holdingsVisibility: "cashAndShareCount" },
{ holdingsVisibility: "cashAndShareCount", teamPlay: true },
{ holdingsVisibility: "cashAndShareCount", twoPlayerMode: "fourHands" },
];
const totalShares = (shares: Record<string, number>) => Object.values(shares).reduce((sum, count) => sum + count, 0);
function lcg(seed: number): () => number {
let s = seed >>> 0;
return () => {
@ -61,21 +67,24 @@ function viewers(state: GameState): (number | undefined)[] {
/** The state with every field the viewer may not see replaced by a fixed marker, for comparison. */
function withoutSecrets(state: GameState, player: number | undefined): unknown {
const own = seatsOf(state, player);
const holdingsPublic = state.options.publicHoldings || state.ended;
const level = visibilityNow(state);
return {
...state,
seed: "",
rngCounter: 0,
pool: state.pool.length,
seats: state.seats.map((seat, index) =>
own.includes(index)
? seat
: {
...seat,
hand: seat.hand.length,
...(holdingsPublic ? {} : { cash: "hidden", shares: "hidden" }),
}
),
seats: state.seats.map((seat, index) => {
if (own.includes(index)) {
return seat;
}
const { shareCount: _, ...rest } = seat;
return {
...rest,
hand: seat.hand.length,
...(level === "private" ? { cash: "hidden" } : {}),
...(level === "public" ? {} : { shares: "hidden" }),
};
}),
};
}
@ -91,7 +100,7 @@ test("§13 each viewer's state hides exactly the private fields and passes every
for (const player of viewers(state)) {
const view = wrapper.stripSecret(state, player);
const own = seatsOf(state, player);
const holdingsPublic = state.options.publicHoldings || state.ended;
const level = visibilityNow(state);
assert.equal(view.seed, "", "§13 the seed (which fixes the pool order) is never sent");
assert.equal(view.rngCounter, 0);
@ -111,16 +120,24 @@ test("§13 each viewer's state hides exactly the private fields and passes every
seat.hand.every((tile) => tile === HIDDEN),
"§13 other players' hands are private"
);
if (holdingsPublic) {
assert.equal(seat.cash, state.seats[index]!.cash);
if (level === "private") {
assert.equal(seat.cash, HIDDEN, "§13 other players' cash is private");
} else {
assert.equal(seat.cash, state.seats[index]!.cash, "§13 cash is public above the private level");
}
if (level === "public") {
assert.deepEqual(seat.shares, state.seats[index]!.shares);
} else {
assert.equal(seat.cash, HIDDEN, "§13 other players' cash is private");
assert.ok(
CHAIN_IDS.every((chain) => seat.shares[chain] === HIDDEN),
"§13 other players' stock is private"
);
}
assert.equal(
seat.shareCount,
level === "cashAndShareCount" ? totalShares(state.seats[index]!.shares) : undefined,
"§13 only the share-count level adds the total"
);
});
const masked = withoutSecrets(view, player) as Record<string, unknown>;
@ -154,14 +171,25 @@ test("§13 a viewer cannot tell apart games that differ only in what is hidden f
const opponent = variant.seats[other]!;
[opponent.hand[0], variant.pool[0]] = [variant.pool[0]!, opponent.hand[0]!];
}
if (!state.options.publicHoldings && !state.ended) {
variant.seats.forEach((seat, index) => {
if (!own.includes(index)) {
seat.cash += 100;
seat.shares.tower += 1;
const level = visibilityNow(state);
variant.seats.forEach((seat, index) => {
if (own.includes(index) || level === "public") {
return;
}
if (level === "private") {
seat.cash += 100;
}
if (level === "cashAndShareCount") {
// Only the split between chains is hidden: move one share elsewhere.
const from = CHAIN_IDS.find((chain) => seat.shares[chain] > 0);
if (from) {
seat.shares[from] -= 1;
seat.shares[from === "tower" ? "luxor" : "tower"] += 1;
}
});
}
} else {
seat.shares.tower += 1;
}
});
assert.deepEqual(
JSON.stringify(wrapper.stripSecret(variant, player)),
JSON.stringify(wrapper.stripSecret(state, player)),

View file

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

View file

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

View file

@ -77,6 +77,21 @@ test("private or masked holdings cannot reveal net worth through helpers or publ
assert.deepEqual(total(state), [6000, 6000, 6000], "inactive shares have no liquidation value");
});
test("§13 the cash and share-count levels show no net worth or scores during play", () => {
for (const holdingsVisibility of ["cash", "cashAndShareCount"]) {
const state = scenario({
board: chainAt("tower", ["1A", "2A"]),
shares: [{ tower: 5 }, { tower: 2 }],
hands: [["12I"], ["11I"], ["10I"]],
options: { holdingsVisibility },
});
assert.equal(projectedNetWorth(state), undefined, holdingsVisibility);
assert.equal(projectedNetWorth(wrapper.stripSecret(state, 0)), undefined);
assert.equal(projectedNetWorth(wrapper.stripSecret(state)), undefined);
assert.deepEqual(wrapper.scores(state), [0, 0, 0]);
}
});
test("bank-mode forecasts omit uncertain bonuses and are independent of secret hands and draws", () => {
const state = scenario({
seats: 2,

View file

@ -11,7 +11,10 @@ export interface NetWorth {
total: number;
}
/** Public liquidation estimate, without inspecting hands, future draws or random state. */
/**
* Public liquidation estimate, without inspecting hands, future draws or random state. It needs
* per-chain holdings, so it exists only with fully public holdings or after the game.
*/
export function projectedNetWorth(state: GameState): NetWorth[] | undefined {
if (!state.ended && !state.options.publicHoldings) {
return undefined;

View file

@ -2,7 +2,14 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import { endConditionHolds } from "./board.js";
import { applyMove } from "./moves.js";
import { DEFAULT_OPTIONS, handSize, normalizeOptions } from "./options.js";
import { legalMoves } from "./legal.js";
import {
DEFAULT_OPTIONS,
PUBLIC_HOLDINGS_OVERRIDE,
handSize,
holdingsVisibility,
normalizeOptions,
} from "./options.js";
import { sharePrice } from "./prices.js";
import { initGame } from "./setup.js";
import { chainAt, checkInvariants, row, scenario } from "./test/helpers.js";
@ -245,3 +252,122 @@ test("§15 publicHoldings: everyone's cash and stock are visible, hands are not"
assert.equal(view.seats[1]!.shares.tower, 2);
assert.deepEqual(view.seats[1]!.hand, [-1]);
});
test("§15 holdingsVisibility: missing and private keep the historical options, intermediate levels are stored", () => {
const normalized = (raw: Record<string, unknown>) => normalizeOptions(3, raw);
for (const raw of [{}, { holdingsVisibility: "private" }]) {
assert.deepEqual(normalized(raw), { options: DEFAULT_OPTIONS, ignored: [] });
}
for (const level of ["cash", "cashAndShareCount"] as const) {
const { options, ignored } = normalized({ holdingsVisibility: level });
assert.deepEqual(options, { ...DEFAULT_OPTIONS, holdingsVisibility: level });
assert.deepEqual(ignored, []);
assert.equal(holdingsVisibility(options), level);
}
// Full public is stored exactly as the legacy checkbox stores it.
const legacy = normalized({ publicHoldings: true });
assert.deepEqual(legacy, { options: { ...DEFAULT_OPTIONS, publicHoldings: true }, ignored: [] });
assert.deepEqual(normalized({ holdingsVisibility: "public" }), legacy);
assert.equal(holdingsVisibility(legacy.options), "public");
assert.equal(holdingsVisibility(DEFAULT_OPTIONS), "private");
assert.equal("holdingsVisibility" in initGame(3, { publicHoldings: true }, "legacy").options, false);
});
test("§15 holdingsVisibility: invalid values are ignored and logged, falling back to the checkbox", () => {
for (const value of ["everything", "Cash", true, 2, null]) {
const { options, ignored } = normalizeOptions(3, { holdingsVisibility: value });
assert.deepEqual(options, DEFAULT_OPTIONS);
assert.deepEqual(ignored, [{ option: "holdingsVisibility", value, reason: "unknown value" }]);
assert.equal(normalizeOptions(3, { holdingsVisibility: value, publicHoldings: true }).options.publicHoldings, true);
}
assert.equal(normalizeOptions(3, { publicHoldings: "true" }).options.publicHoldings, false);
});
test("§15 holdingsVisibility: the legacy publicHoldings checkbox wins, and only a real conflict is logged", () => {
for (const level of ["private", "public"]) {
assert.deepEqual(normalizeOptions(3, { publicHoldings: true, holdingsVisibility: level }), {
options: { ...DEFAULT_OPTIONS, publicHoldings: true },
ignored: [],
});
}
for (const level of ["cash", "cashAndShareCount"]) {
const state = initGame(3, { publicHoldings: true, holdingsVisibility: level }, "conflict");
assert.deepEqual(state.options, { ...DEFAULT_OPTIONS, publicHoldings: true });
assert.deepEqual(ignoredLog(state), [
{ type: "optionIgnored", option: "holdingsVisibility", value: level, reason: PUBLIC_HOLDINGS_OVERRIDE },
]);
}
});
test("§13 holdingsVisibility cash: opponents' exact cash is visible, their stock is not", () => {
const state = scenario({
board: chainAt("tower", ["1A", "2A"]),
hands: [["9G"], ["9I"], ["11I"]],
shares: [{ tower: 1 }, { tower: 2, luxor: 3 }],
cash: [6000, 4300, 5100],
options: { holdingsVisibility: "cash" },
});
for (const player of [0, undefined]) {
const view = wrapper.stripSecret(state, player);
assert.equal(view.seats[1]!.cash, 4300);
assert.equal(view.seats[2]!.cash, 5100);
assert.equal(view.seats[1]!.shares.tower, -1);
assert.equal(view.seats[1]!.shares.luxor, -1);
assert.equal("shareCount" in view.seats[1]!, false);
assert.deepEqual(view.seats[1]!.hand, [-1]);
}
assert.deepEqual(wrapper.stripSecret(state, 0).seats[0], state.seats[0], "your own seat is complete");
});
test("§13 holdingsVisibility cashAndShareCount: exact cash and total shares, never the chains", () => {
const state = scenario({
board: chainAt("tower", ["1A", "2A"]),
hands: [["9G"], ["9I"], ["11I"]],
// Kept shares of a chain not on the board still count.
shares: [{ tower: 1 }, { tower: 2, luxor: 3 }],
cash: [6000, 4300, 5100],
options: { holdingsVisibility: "cashAndShareCount" },
});
for (const player of [0, undefined]) {
const view = wrapper.stripSecret(state, player);
assert.equal(view.seats[1]!.cash, 4300);
assert.equal(view.seats[1]!.shareCount, 5);
assert.equal(view.seats[2]!.shareCount, 0);
assert.ok(Object.values(view.seats[1]!.shares).every((count) => count === -1));
assert.deepEqual(view.seats[1]!.hand, [-1]);
}
const own = wrapper.stripSecret(state, 0).seats[0]!;
assert.deepEqual(own, state.seats[0], "your own seat is complete, without a share count");
assert.deepEqual(legalMoves(wrapper.stripSecret(state, 0)), legalMoves(state));
});
test("§13 holdingsVisibility: every level reveals everything once the game ends", () => {
for (const holdingsVisibility of ["cash", "cashAndShareCount"]) {
const state = scenario({
board: chainAt("tower", ["1A", "2A", "3A", "4A", "5A", "6A", "7A", "8A", "9A", "10A", "11A"]),
hands: [["9G"], ["9I", "12A"], ["11G"]],
shares: [{}, { luxor: 3 }],
cash: [6000, 4100, 6000],
options: { holdingsVisibility },
});
applyMove(state, { type: "announce" }, 0);
applyMove(state, { type: "place", tile: "9G" }, 0);
applyMove(state, { type: "buy", shares: {} }, 0);
assert.equal(state.ended, true);
const seat = wrapper.stripSecret(state, 0).seats[1]!;
assert.equal(seat.cash, 4100);
assert.equal(seat.shares.luxor, 3);
assert.equal("shareCount" in seat, false);
}
});
test("§15 holdingsVisibility games replay identically", () => {
for (const holdingsVisibility of ["cash", "cashAndShareCount", "public"]) {
const state = initGame(4, { holdingsVisibility }, `replay-${holdingsVisibility}`);
for (let step = 1; !state.ended && step < 200; step++) {
const moves = legalMoves(state).filter((move) => move.type !== "announce");
wrapper.move(state, moves[(step * 7919) % moves.length]!, wrapper.currentPlayer(state)!);
}
assert.deepEqual(wrapper.replay(structuredClone(state)), state);
}
});

View file

@ -2,7 +2,13 @@ import { END_SIZE, HAND_SIZE, MAX_BUY, TWO_TILE_HAND_SIZE } from "./config.js";
/** rules.md §15, after normalisation against the player count. */
export interface GameOptions {
/** Full public holdings (rules.md §13), also the highest holdingsVisibility level. */
publicHoldings: boolean;
/**
* Only the intermediate levels are stored: private and public remain publicHoldings
* false/true, preserving the init log of games created before this option.
*/
holdingsVisibility?: "cash" | "cashAndShareCount";
teamPlay: boolean;
twoPlayerMode: "bank" | "fourHands";
autoEnd: boolean;
@ -41,6 +47,23 @@ export const DEFAULT_OPTIONS: GameOptions = {
const END_SIZES = [41, 31];
const HAND_SIZES = [6, 8, 10, 12, "6", "8", "10", "12"];
/** The optionIgnored reason when the legacy checkbox already makes holdings public. */
export const PUBLIC_HOLDINGS_OVERRIDE = "publicHoldings makes all holdings public";
/** rules.md §13: how much of other players' holdings everyone sees, from least to most. */
export const HOLDINGS_VISIBILITY = ["private", "cash", "cashAndShareCount", "public"] as const;
export type HoldingsVisibility = (typeof HOLDINGS_VISIBILITY)[number];
/** The holdings level during play; everything becomes public when the game ends. */
export function holdingsVisibility(options: GameOptions): HoldingsVisibility {
return options.publicHoldings ? "public" : (options.holdingsVisibility ?? "private");
}
/** Whether exact cash is public, so decisions that depend only on cash may reveal it. */
export function cashIsPublic(options: GameOptions): boolean {
return holdingsVisibility(options) !== "private";
}
/**
* Reads the creator's options defensively. BGS omits unticked checkboxes and always sends
* selects (as strings), so a missing checkbox means false. Options are never rejected
@ -56,7 +79,25 @@ export function normalizeOptions(
const options: GameOptions = { ...DEFAULT_OPTIONS };
const ignored: IgnoredOption[] = [];
options.publicHoldings = raw.publicHoldings === true;
// The legacy publicHoldings checkbox always means full public holdings and wins over the
// holdingsVisibility select. Only an intermediate level it overrides is reported: the
// select's default "private" is always sent.
let visibility: HoldingsVisibility = "private";
if (HOLDINGS_VISIBILITY.includes(raw.holdingsVisibility as HoldingsVisibility)) {
visibility = raw.holdingsVisibility as HoldingsVisibility;
} else if (raw.holdingsVisibility !== undefined) {
ignored.push({ option: "holdingsVisibility", value: raw.holdingsVisibility, reason: "unknown value" });
}
if (raw.publicHoldings === true) {
if (visibility === "cash" || visibility === "cashAndShareCount") {
ignored.push({ option: "holdingsVisibility", value: visibility, reason: PUBLIC_HOLDINGS_OVERRIDE });
}
visibility = "public";
}
options.publicHoldings = visibility === "public";
if (visibility === "cash" || visibility === "cashAndShareCount") {
options.holdingsVisibility = visibility;
}
options.autoEnd = raw.autoEnd === true;
if (raw.teamPlay === true) {

View file

@ -81,7 +81,10 @@ export function playerRankings(state: GameState): number[] {
return players.map((player) => (hasDropped(state, player) ? lastStayed + 1 : ranks[player]!));
}
/** rules.md §13: scores stay 0 during play while holdings are private. */
/**
* rules.md §13: scores stay 0 during play unless holdings are fully public. Net worth needs
* per-chain holdings, so the cash and share-count levels keep 0 too.
*/
export function playerScores(state: GameState): number[] {
if (!state.ended && !state.options.publicHoldings) {
return Array.from({ length: state.players }, () => 0);

View file

@ -241,16 +241,18 @@ test("§9.6 with private holdings the buy step is not skipped for lack of cash",
assert.equal(state.activeSeat, 1);
});
test("§9.6 with public holdings the buy step is skipped when the player cannot afford any share", () => {
const state = scenario({
board: chainAt("tower", ["1A", "2A"]),
hands: [["9G"], ["11G"]],
cash: [100],
options: { publicHoldings: true },
});
play(state, 0, place("9G"));
assert.equal(state.activeSeat, 1);
assert.equal(state.phase, "place");
test("§9.6 with public cash the buy step is skipped when the player cannot afford any share", () => {
for (const options of [
{ publicHoldings: true },
{ holdingsVisibility: "public" },
{ holdingsVisibility: "cash" },
{ holdingsVisibility: "cashAndShareCount" },
]) {
const state = scenario({ board: chainAt("tower", ["1A", "2A"]), hands: [["9G"], ["11G"]], cash: [100], options });
play(state, 0, place("9G"));
assert.equal(state.activeSeat, 1, JSON.stringify(options));
assert.equal(state.phase, "place");
}
});
test("§9.6 the buy step is skipped when no chain is on the board", () => {

View file

@ -1,6 +1,6 @@
import { activeChains, chainSize, playableTiles, tileLegality } from "./board.js";
import { AUTO_TURN_LIMIT } from "./config.js";
import { handSize } from "./options.js";
import { cashIsPublic, handSize } from "./options.js";
import { sharePrice } from "./prices.js";
import { canAnnounce, endConditionMet, endGame } from "./scoring.js";
import type { Tile } from "./tiles.js";
@ -13,7 +13,7 @@ export function drawTile(state: GameState): Tile | undefined {
/**
* rules.md §9.6: whether the buy step has anything to offer. Only public facts count unless
* holdings are public, so skipping the step never reveals a player's cash.
* cash is public (holdings level cash or above), so skipping the step never reveals it.
*/
export function buyStepAvailable(state: GameState): boolean {
const seat = state.seats[state.activeSeat]!;
@ -23,9 +23,9 @@ export function buyStepAvailable(state: GameState): boolean {
if (state.options.stockSwap && active.length > 1 && active.some((chain) => state.bank[chain] > 0)) {
return true;
}
const cashIsPublic = state.options.publicHoldings;
const cashKnown = cashIsPublic(state.options);
return activeChains(state.board).some(
(chain) => state.bank[chain] > 0 && (!cashIsPublic || sharePrice(chain, chainSize(state.board, chain)) <= seat.cash)
(chain) => state.bank[chain] > 0 && (!cashKnown || sharePrice(chain, chainSize(state.board, chain)) <= seat.cash)
);
}

View file

@ -11,6 +11,11 @@ export interface SeatState {
name: string;
cash: number;
shares: Shares;
/**
* Only in a viewer's state at the cashAndShareCount holdings level (rules.md §13): another
* seat's total shares across all chains, while `shares` is hidden.
*/
shareCount?: number;
hand: Tile[];
dropped: boolean;
}

View file

@ -1,5 +1,6 @@
import { CHAIN_IDS } from "./config.js";
import { visibleLog } from "./limited-log.js";
import { holdingsVisibility, type HoldingsVisibility } from "./options.js";
import type { GameState, Shares } from "./types.js";
/** Value sent in place of anything the viewer may not see. */
@ -12,22 +13,47 @@ export function seatsOf(state: GameState, player: number | undefined): number[]
return state.seatOwner.flatMap((owner, seat) => (owner === player ? [seat] : []));
}
/** The holdings level everyone sees now: all of them once the game has ended. */
export function visibilityNow(state: GameState): HoldingsVisibility {
return state.ended ? "public" : holdingsVisibility(state.options);
}
/**
* rules.md §13: another seat's cash and shares as shown at `level`. Below public, the
* per-chain holdings are hidden; cashAndShareCount adds their total as `shareCount`.
*/
export function maskHoldings(
holdings: { cash: number; shares: Shares },
level: HoldingsVisibility
): { cash: number; shares: Shares; shareCount?: number } {
if (level === "public") {
return { cash: holdings.cash, shares: { ...holdings.shares } };
}
return {
cash: level === "private" ? HIDDEN : holdings.cash,
shares: { ...HIDDEN_SHARES },
...(level === "cashAndShareCount"
? { shareCount: Object.values(holdings.shares).reduce((sum, count) => sum + count, 0) }
: {}),
};
}
/**
* rules.md §13: the state as `player` may see it (undefined for a spectator). Hidden numbers
* are replaced by HIDDEN so the shape stays the same. Hands and the pool order are always
* private; holdings and cash are private unless publicHoldings is on or the game has ended.
* With limitedLog, older log entries are replaced. The seed is removed because it determines
* the pool order.
* private; other seats' cash and holdings are shown as far as the holdings level allows
* (maskHoldings), and fully once the game has ended. With limitedLog, older log entries are
* replaced. The seed is removed because it determines the pool order.
*/
export function viewFor(state: GameState, player: number | undefined): GameState {
const own = seatsOf(state, player);
const holdingsPublic = state.options.publicHoldings || state.ended;
const level = visibilityNow(state);
return {
...structuredClone(state),
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);
@ -35,7 +61,7 @@ export function viewFor(state: GameState, player: number | undefined): GameState
return {
...structuredClone(seat),
hand: seat.hand.map(() => HIDDEN),
...(holdingsPublic ? {} : { cash: HIDDEN, shares: { ...HIDDEN_SHARES } }),
...maskHoldings(seat, level),
};
}),
};

View file

@ -45,3 +45,22 @@ test("wrapper: setPlayerMetaData stores the player name", () => {
const state = wrapper.setPlayerMetaData(wrapper.init(2, [], {}, "seed"), 1, { name: "Ada" });
assert.equal(state.seats[1]?.name, "Ada");
});
test("wrapper: BGS setup values for holdingsVisibility reach stripSecret, and scores stay private", () => {
for (const [raw, cash, shareCount] of [
[{ holdingsVisibility: "private" }, -1, undefined],
[{ holdingsVisibility: "cash" }, 6000, undefined],
[{ holdingsVisibility: "cashAndShareCount" }, 6000, 0],
] as const) {
const state = wrapper.init(3, [], raw, "seed");
const opponent = wrapper.stripSecret(state, 0).seats[1]!;
assert.equal(opponent.cash, cash, JSON.stringify(raw));
assert.equal(opponent.shareCount, shareCount);
assert.deepEqual(wrapper.scores(state), [0, 0, 0]);
}
for (const raw of [{ publicHoldings: true }, { holdingsVisibility: "public" }]) {
const state = wrapper.init(3, [], raw, "seed");
assert.deepEqual(wrapper.stripSecret(state, 0).seats[1]!.shares, state.seats[1]!.shares);
assert.deepEqual(wrapper.scores(state), [6000, 6000, 6000]);
}
});

View file

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

View file

@ -1,7 +1,7 @@
// Local dev harness (not part of the BGS bundle): runs the real engine in the page, plays
// random moves on request, and lets you view the game as any player or as a spectator.
// URL parameters: players=2..6, seed=..., view=N, hotseat=0, theme=light|dark, locale=de, and any game option, e.g. publicHoldings=1,
// twoPlayerMode=fourHands, teamPlay=1, autoEnd=1, endSize=31, twoTiles=1, handSize=12. For reproducible screenshots: moves=N plays N random moves,
// holdingsVisibility=cash|cashAndShareCount|public, twoPlayerMode=fourHands, teamPlay=1, autoEnd=1, endSize=31, twoTiles=1, handSize=12. For reproducible screenshots: moves=N plays N random moves,
// merger=1 then plays on to the next merger decision, bar=0 hides this toolbar.
import * as rules from "acquire-engine";
import { currentSeat, legalMoves, type GameState } from "acquire-engine";
@ -34,7 +34,7 @@ for (const key of ["publicHoldings", "teamPlay", "autoEnd", "twoTiles", "limited
options[key] = true;
}
}
for (const key of ["twoPlayerMode", "endSize", "stockSwap", "sharesPerTurn", "handSize"]) {
for (const key of ["holdingsVisibility", "twoPlayerMode", "endSize", "stockSwap", "sharesPerTurn", "handSize"]) {
const value = params.get(key);
if (value) {
options[key] = value;

View file

@ -30,7 +30,8 @@
<tbody>
{#each state.seats as seat, index (index)}
{@const held = CHAIN_IDS.filter((chain) => seat.shares[chain] !== 0)}
{@const hidden = seat.cash === HIDDEN}
{@const cashHidden = seat.cash === HIDDEN}
{@const sharesHidden = CHAIN_IDS.some((chain) => seat.shares[chain] === HIDDEN)}
<tr class:you={seats.includes(index)}>
<td>
{#if index === acting}<span class="turn" aria-label={t("players.acting")}>▶</span>{/if}
@ -47,10 +48,14 @@
><small>{store.lang.money(seat.cash)}</small></td
>
{:else}
<td class="num" class:hidden-value={hidden}>{store.lang.money(seat.cash)}</td>
<td class="num" class:hidden-value={cashHidden}>{store.lang.money(seat.cash)}</td>
{/if}
<td>
{#if hidden}
{#if sharesHidden && seat.shareCount !== undefined}
<span class="share-count" title={t("players.shareCountHint")}
>{t("players.shareCount", { count: seat.shareCount })}</span
>
{:else if sharesHidden}
<span class="hidden-value">{t("hidden")}</span>
{:else if held.length === 0}
<span class="none">{t("players.none")}</span>
@ -149,4 +154,7 @@
.none {
color: var(--ink-muted);
}
.share-count {
font-variant-numeric: tabular-nums;
}
</style>

View file

@ -64,3 +64,14 @@ test("player names cannot be mistaken for chain names, markup or formatting toke
);
}
});
test("a holdings level overridden by the legacy publicHoldings checkbox is explained, not called unknown", () => {
const state = initGame(3, { publicHoldings: true, holdingsVisibility: "cash" }, "override");
const entry = state.log.find((e) => e.type === "optionIgnored")!;
assert.equal(
describeEntry(state, entry, langFor("en")),
"Option holdingsVisibility was ignored: publicHoldings already shows all holdings"
);
const unknown = initGame(3, { holdingsVisibility: "some" }, "unknown").log.find((e) => e.type === "optionIgnored")!;
assert.equal(describeEntry(state, unknown, langFor("en")), "Option holdingsVisibility was ignored: unknown value");
});

View file

@ -1,6 +1,7 @@
import {
CHAINS,
HIDDEN,
PUBLIC_HOLDINGS_OVERRIDE,
currentSeat,
merger,
secondPlacementDue,
@ -98,6 +99,9 @@ export function describeEntry(
case "init":
return t("log.init", { count: entry.players });
case "optionIgnored": {
if (entry.reason === PUBLIC_HOLDINGS_OVERRIDE) {
return t("log.optionIgnored.publicHoldings", { option: entry.option });
}
const count = entry.option === "teamPlay" ? 4 : entry.option === "twoPlayerMode" ? 2 : undefined;
return count !== undefined && entry.reason.startsWith("only applies")
? t("log.optionIgnored.players", { option: entry.option, count })

View file

@ -133,6 +133,10 @@ export const da: Catalog = {
"players.turn": "tur",
"players.left": "forladt",
"players.none": "ingen",
"players.shareCount": { one: "{count} aktie", other: "{count} aktier" },
"players.shareCountHint": "I alt på tværs af alle kæder; beholdningen pr. kæde er skjult",
"log.optionIgnored.publicHoldings":
"Indstillingen {option} blev ignoreret: publicHoldings viser allerede alle beholdninger",
hidden: "skjult",
"seat.name": "{name} (plads {seat})",
"log.label": "Spillets log",

View file

@ -133,6 +133,10 @@ export const de: Catalog = {
"players.turn": "am Zug",
"players.left": "ausgeschieden",
"players.none": "keine",
"players.shareCount": { one: "{count} Aktie", other: "{count} Aktien" },
"players.shareCountHint": "Summe über alle Ketten; der Besitz je Kette ist verdeckt",
"log.optionIgnored.publicHoldings":
"Option {option} wurde ignoriert: publicHoldings zeigt bereits den gesamten Besitz",
hidden: "verdeckt",
"seat.name": "{name} (Platz {seat})",
"log.label": "Spielprotokoll",

View file

@ -133,6 +133,10 @@ export const el: Catalog = {
"players.turn": "σειρά",
"players.left": "αποχώρησε",
"players.none": "καμία",
"players.shareCount": { one: "{count} μετοχή", other: "{count} μετοχές" },
"players.shareCountHint": "Σύνολο σε όλες τις αλυσίδες· οι μετοχές ανά αλυσίδα είναι κρυφές",
"log.optionIgnored.publicHoldings":
"Η επιλογή {option} αγνοήθηκε: το publicHoldings δείχνει ήδη όλες τις μετοχές και τα μετρητά",
hidden: "κρυφό",
"seat.name": "{name} (θέση {seat})",
"log.label": "Ημερολόγιο παιχνιδιού",

View file

@ -143,6 +143,9 @@ export const en = {
"players.turn": "turn",
"players.left": "left",
"players.none": "none",
"players.shareCount": { one: "{count} share", other: "{count} shares" },
"players.shareCountHint": "Total across all chains; holdings per chain are hidden",
"log.optionIgnored.publicHoldings": "Option {option} was ignored: publicHoldings already shows all holdings",
hidden: "hidden",
"seat.name": "{name} (seat {seat})",

View file

@ -132,6 +132,10 @@ export const fa: Catalog = {
"players.turn": "نوبت",
"players.left": "رفته",
"players.none": "هیچ",
"players.shareCount": { one: "{count} سهم", other: "{count} سهم" },
"players.shareCountHint": "مجموع در همه‌ی زنجیره‌ها؛ سهام هر زنجیره پنهان است",
"log.optionIgnored.publicHoldings":
"گزینه‌ی {option} نادیده گرفته شد: publicHoldings از قبل همه‌ی دارایی‌ها را نشان می‌دهد",
hidden: "پنهان",
"seat.name": "{name} (جایگاه {seat})",
"log.label": "گزارش بازی",

View file

@ -138,6 +138,9 @@ export const fr: Catalog = {
"players.turn": "son tour",
"players.left": "parti",
"players.none": "aucune",
"players.shareCount": { one: "{count} action", many: "{count} actions", other: "{count} actions" },
"players.shareCountHint": "Total sur toutes les chaînes ; le détail par chaîne est caché",
"log.optionIgnored.publicHoldings": "L’option {option} a été ignorée : publicHoldings montre déjà tous les avoirs",
hidden: "caché",
"seat.name": "{name} (place {seat})",
"log.label": "Journal de la partie",

View file

@ -130,6 +130,9 @@ export const hi: Catalog = {
"players.turn": "बारी",
"players.left": "छोड़ गए",
"players.none": "कोई नहीं",
"players.shareCount": { one: "{count} शेयर", other: "{count} शेयर" },
"players.shareCountHint": "सभी श्रृंखलाओं में कुल; हर श्रृंखला के शेयर छिपे हैं",
"log.optionIgnored.publicHoldings": "विकल्प {option} अनदेखा किया गया: publicHoldings पहले से सारी होल्डिंग दिखाता है",
hidden: "छिपा",
"seat.name": "{name} (सीट {seat})",
"log.label": "खेल का लॉग",

View file

@ -138,6 +138,9 @@ export const it: Catalog = {
"players.turn": "turno",
"players.left": "uscito",
"players.none": "nessuna",
"players.shareCount": { one: "{count} azione", many: "{count} azioni", other: "{count} azioni" },
"players.shareCountHint": "Totale su tutte le catene; il dettaglio per catena è nascosto",
"log.optionIgnored.publicHoldings": "Opzione {option} ignorata: publicHoldings mostra già tutte le partecipazioni",
hidden: "nascosto",
"seat.name": "{name} (posto {seat})",
"log.label": "Registro della partita",

View file

@ -132,6 +132,9 @@ export const ko: Catalog = {
"players.turn": "차례",
"players.left": "나감",
"players.none": "없음",
"players.shareCount": { other: "{count}주" },
"players.shareCountHint": "모든 체인의 합계이며, 체인별 보유량은 비공개입니다",
"log.optionIgnored.publicHoldings": "{option} 옵션 무시됨: publicHoldings가 이미 모든 보유량을 공개함",
hidden: "비공개",
"seat.name": "{name} ({seat}번 자리)",
"log.label": "게임 기록",

View file

@ -133,6 +133,9 @@ export const nl: Catalog = {
"players.turn": "beurt",
"players.left": "vertrokken",
"players.none": "geen",
"players.shareCount": { one: "{count} aandeel", other: "{count} aandelen" },
"players.shareCountHint": "Totaal over alle ketens; het bezit per keten is verborgen",
"log.optionIgnored.publicHoldings": "Optie {option} genegeerd: publicHoldings toont al het volledige bezit",
hidden: "verborgen",
"seat.name": "{name} (plaats {seat})",
"log.label": "Spelverslag",

View file

@ -137,6 +137,9 @@ export const pl: Catalog = {
"players.turn": "tura",
"players.left": "odszedł",
"players.none": "brak",
"players.shareCount": { one: "{count} akcja", few: "{count} akcje", many: "{count} akcji", other: "{count} akcji" },
"players.shareCountHint": "Suma we wszystkich sieciach; akcje poszczególnych sieci są ukryte",
"log.optionIgnored.publicHoldings": "Opcję {option} pominięto: publicHoldings już pokazuje wszystkie aktywa",
hidden: "ukryte",
"seat.name": "{name} (miejsce {seat})",
"log.label": "Dziennik gry",

View file

@ -137,6 +137,9 @@ export const ptBR: Catalog = {
"players.turn": "vez",
"players.left": "saiu",
"players.none": "nenhuma",
"players.shareCount": { one: "{count} ação", many: "{count} ações", other: "{count} ações" },
"players.shareCountHint": "Total em todas as redes; as ações de cada rede ficam ocultas",
"log.optionIgnored.publicHoldings": "A opção {option} foi ignorada: publicHoldings já mostra todos os ativos",
hidden: "oculto",
"seat.name": "{name} (lugar {seat})",
"log.label": "Registro do jogo",

View file

@ -138,6 +138,9 @@ export const ro: Catalog = {
"players.turn": "la rând",
"players.left": "a plecat",
"players.none": "niciuna",
"players.shareCount": { one: "{count} acțiune", few: "{count} acțiuni", other: "{count} de acțiuni" },
"players.shareCountHint": "Total în toate lanțurile; acțiunile pe fiecare lanț sunt ascunse",
"log.optionIgnored.publicHoldings": "Opțiunea {option} a fost ignorată: publicHoldings arată deja toate deținerile",
hidden: "ascuns",
"seat.name": "{name} (locul {seat})",
"log.label": "Jurnalul jocului",

View file

@ -137,6 +137,9 @@ export const ru: Catalog = {
"players.turn": "ход",
"players.left": "вышел",
"players.none": "нет",
"players.shareCount": { one: "{count} акция", few: "{count} акции", many: "{count} акций", other: "{count} акции" },
"players.shareCountHint": "Всего по всем сетям; акции по сетям скрыты",
"log.optionIgnored.publicHoldings": "Опция {option} пропущена: publicHoldings уже показывает все активы",
hidden: "скрыто",
"seat.name": "{name} (место {seat})",
"log.label": "Журнал игры",

View file

@ -133,6 +133,9 @@ export const vi: Catalog = {
"players.turn": "lượt",
"players.left": "đã rời",
"players.none": "không có",
"players.shareCount": { other: "{count} cổ phiếu" },
"players.shareCountHint": "Tổng trên mọi chuỗi; số cổ phiếu của từng chuỗi được ẩn",
"log.optionIgnored.publicHoldings": "Bỏ qua tùy chọn {option}: publicHoldings đã hiển thị mọi tài sản",
hidden: "ẩn",
"seat.name": "{name} (ghế {seat})",
"log.label": "Nhật ký ván chơi",

View file

@ -130,6 +130,9 @@ export const zhCN: Catalog = {
"players.turn": "回合",
"players.left": "已离开",
"players.none": "无",
"players.shareCount": { other: "{count} 股" },
"players.shareCountHint": "所有连锁的合计;各连锁的持股不公开",
"log.optionIgnored.publicHoldings": "已忽略选项 {option}:publicHoldings 已公开全部持股",
hidden: "隐藏",
"seat.name": "{name}(座位 {seat})",
"log.label": "游戏记录",

View file

@ -130,6 +130,9 @@ export const zhTW: Catalog = {
"players.turn": "回合",
"players.left": "已離開",
"players.none": "無",
"players.shareCount": { other: "{count} 股" },
"players.shareCountHint": "所有連鎖的合計;各連鎖的持股不公開",
"log.optionIgnored.publicHoldings": "已忽略選項 {option}:publicHoldings 已公開全部持股",
hidden: "隱藏",
"seat.name": "{name}(座位 {seat})",
"log.label": "遊戲紀錄",

View file

@ -0,0 +1,32 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { HIDDEN, initGame, legalMoves, applyMove, currentSeat, type GameState } from "acquire-engine";
import { replayView } from "./replay.ts";
function played(options: Record<string, unknown>): GameState {
const state = initGame(3, options, "replay-levels");
for (let step = 1; step < 120 && !state.ended; step++) {
const moves = legalMoves(state).filter((move) => move.type !== "announce");
applyMove(state, moves[(step * 7919) % moves.length]!, currentSeat(state)!);
}
return state;
}
test("replay positions show other seats' holdings only as far as the holdings level allows", () => {
const at = (state: GameState) => state.log.length;
const cases: [Record<string, unknown>, (seat: GameState["seats"][number]) => void][] = [
[{}, (seat) => assert.equal(seat.cash, HIDDEN)],
[{ holdingsVisibility: "cash" }, (seat) => assert.ok(seat.cash > 0 && seat.shareCount === undefined)],
[{ holdingsVisibility: "cashAndShareCount" }, (seat) => assert.equal(typeof seat.shareCount, "number")],
];
for (const [options, check] of cases) {
const state = played(options);
const view = replayView(state, 0, at(state));
check(view.seats[1]!);
assert.equal(view.seats[1]!.shares.tower, HIDDEN);
assert.deepEqual(view.seats[0]!.shares, state.seats[0]!.shares, "your own holdings are shown");
assert.equal(view.seats[0]!.shareCount, undefined);
}
const open = played({ holdingsVisibility: "public" });
assert.deepEqual(replayView(open, 0, at(open)).seats[1]!.shares, open.seats[1]!.shares);
});

View file

@ -1,8 +1,6 @@
// BGS replay controls: the state to display at a log position, built from the engine's
// positionAt (the public log replayed with the engine's own placement functions).
import { CHAIN_IDS, HIDDEN, positionAt, seatsOf, type GameState, type Shares } from "acquire-engine";
const HIDDEN_SHARES = Object.fromEntries(CHAIN_IDS.map((chain) => [chain, HIDDEN])) as Shares;
import { HIDDEN, maskHoldings, positionAt, seatsOf, visibilityNow, type GameState } from "acquire-engine";
/** The first replay position: the board after setup, at the start of the first turn. */
export function replayStart(state: GameState): number {
@ -11,24 +9,24 @@ export function replayStart(state: GameState): number {
}
/**
* The game as it stood after `at` log entries. Holdings show only where they are public now:
* public holdings, a finished game, or the viewer's own seats. Tiles in hand are never shown.
* The game as it stood after `at` log entries. Holdings show only as far as they are public now
* (the holdings level, or all of them in a finished game), except on the viewer's own seats.
* Tiles in hand are never shown.
*/
export function replayView(state: GameState, player: number | undefined, at: number): GameState {
const position = positionAt(state, at);
const own = seatsOf(state, player);
const holdingsPublic = state.options.publicHoldings || state.ended;
const level = visibilityNow(state);
return {
...state,
board: position.board,
bank: position.bank,
seats: state.seats.map((seat, index) => {
const shown = position.seats[index]!;
const visible = holdingsPublic || own.includes(index);
const { shareCount: _, ...rest } = seat;
return {
...seat,
cash: visible ? shown.cash : HIDDEN,
shares: visible ? shown.shares : { ...HIDDEN_SHARES },
...rest,
...maskHoldings(shown, own.includes(index) ? "public" : level),
hand: Array.from({ length: shown.tiles }, () => HIDDEN),
};
}),

View file

@ -227,10 +227,11 @@ can be renamed later without touching game logic.
5. Players can never sell stock except during merger disposal (§7.2) and final scoring
(§11.2). There is no trading between players.
6. **[DECISION]** The buy step is skipped automatically only for public reasons: no chain
is on the board, or the bank has no shares left in any active chain. When
`publicHoldings` is off (§13), it is never skipped because the player cannot afford a
share, since that would reveal their cash; they get the step and may buy nothing. When
`publicHoldings` is on, it is also skipped when the player cannot afford any share.
is on the board, or the bank has no shares left in any active chain. While cash is
private (`holdingsVisibility` `private`, §13), it is never skipped because the player
cannot afford a share, since that would reveal their cash; they get the step and may buy
nothing. When cash is public (every other level), it is also skipped when the player
cannot afford any share.
### 9.1 Optional stock swaps (house rule)
@ -338,21 +339,36 @@ Each viewer must only receive information their player is entitled to.
- **Always private:** each player's hand of tiles, and the order of the draw pool.
- **Always public:** the board, chain names and sizes, current prices, and the number of
shares left in the bank for each chain.
- **[DECISION] Game option `publicHoldings` (default: `false`):** When off, each player's
current share holdings and cash are visible only to that player. When on, they are
public.
- **[DECISION] Game option `holdingsVisibility` (default: `private`):** what everyone sees
of other players' current cash and share holdings during play.
- `private`: nothing; each player's cash and holdings are visible only to that player.
- `cash`: every player's exact cash is public; holdings stay private.
- `cashAndShareCount`: exact cash and each player's total number of shares across all
chains (including kept shares of chains not on the board) are public; how many shares
of each chain stays private.
- `public`: cash and every holding are public.
The legacy checkbox `publicHoldings: true` means `public` and wins over the select; an
intermediate level it overrides is logged as ignored. Normalized options keep
`publicHoldings` (true only at `public`) and store `holdingsVisibility` only for `cash`
and `cashAndShareCount`, so games created before this option keep identical init logs.
Projected net worth and scores need per-chain holdings, so they are shown only at
`public` (below). Summary lines say how many shares a player kept in a merger only at
`public`. The log is the same at every level.
- **[DECISION] The game log is public** unless `limitedLog` is on (below). It records
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.
- **[DECISION] Scores during play:** When `publicHoldings` is off, every player's score
is 0 until the game ends. When it is on, the score is projected net worth: cash,
- **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,
current share sale values and majority/minority bonuses at current holdings (including
ties and rounding). Future bonuses are excluded in two-player bank mode because the
bank's holding is drawn only at payout. In-progress mergers never count paid bonuses
@ -386,15 +402,16 @@ switches on one engine, not as separate code paths. Defaults reproduce the stand
| Option | Values | Default | Effect |
|---|---|---|---|
| `publicHoldings` | true / false | false | See §13. When false, share holdings and cash are private. |
| `teamPlay` | true / false | false | Only applies with exactly 4 players. Seats 1 and 3 form one team, seats 2 and 4 the other. All rules are unchanged; at final scoring each team's cash is added together and the team with more wins. **[DECISION]** With `publicHoldings` off, teammates still cannot see each other's holdings. |
| `holdingsVisibility` | `private` / `cash` / `cashAndShareCount` / `public` | `private` | See §13. What everyone sees of other players' cash and holdings during play. |
| `publicHoldings` | true / false | false | Legacy checkbox, kept for existing games: true means `holdingsVisibility: public`. See §13. |
| `teamPlay` | true / false | false | Only applies with exactly 4 players. Seats 1 and 3 form one team, seats 2 and 4 the other. All rules are unchanged; at final scoring each team's cash is added together and the team with more wins. **[DECISION]** Below `public` holdings, teammates see each other's cash and holdings only as far as everyone does. |
| `twoPlayerMode` | `bank` / `fourHands` | `bank` | Only has an effect with exactly 2 players. `bank` uses §12. `fourHands` runs a normal 4-seat game where each player controls two seats (player A has seats 1 and 3, player B has seats 2 and 4), with no bank shareholder. **[DECISION]** The player who controls the single richest seat wins; seats are not combined. |
| `autoEnd` | true / false | false | When true, the game ends automatically at the end of the turn in which an end condition (§11.1) first holds, instead of waiting for an announcement. |
| `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 | Two placements per turn (house rule). See §4.1. |
| `handSize` | 6 / 8 / 10 / 12 | 6 | Tiles each seat draws at setup and refills to (house rule), with or without `twoTiles`. **[DECISION]** Without `handSize` in the init options (games created before it), hands hold 6, or 8 with `twoTiles`; normalized options omit `handSize` at that legacy size so those games replay identically. Twelve tiles for each of 6 players use 78 of the 108 tiles at setup, counting turn-order tiles. |
| `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