Add holdings visibility levels for cash and total share count
Replace the public holdings checkbox with a holdingsVisibility select: private, cash, cashAndShareCount or public. publicHoldings: true keeps meaning full public, and normalized options store holdingsVisibility only at the two new levels, so historical init logs are unchanged. stripSecret shows opponents' exact cash from the cash level and adds a total shareCount at the share-count level while per-chain holdings stay hidden. Net worth and scores still need fully public holdings. The buy step may skip for lack of cash whenever cash is public.
This commit is contained in:
parent
5f5aee5ac0
commit
defff1ab97
39 changed files with 489 additions and 79 deletions
|
|
@ -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).
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -134,7 +134,13 @@ 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
|
||||
|
||||
|
|
@ -148,7 +154,7 @@ Because replaying the game would show the full history, replay is only available
|
|||
- **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).
|
||||
- **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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import assert from "node:assert/strict";
|
|||
import { test } from "node:test";
|
||||
import { endConditionHolds } from "./board.js";
|
||||
import { applyMove } from "./moves.js";
|
||||
import { DEFAULT_OPTIONS, normalizeOptions } from "./options.js";
|
||||
import { legalMoves } from "./legal.js";
|
||||
import { DEFAULT_OPTIONS, PUBLIC_HOLDINGS_OVERRIDE, holdingsVisibility, normalizeOptions } from "./options.js";
|
||||
import { sharePrice } from "./prices.js";
|
||||
import { initGame } from "./setup.js";
|
||||
import { chainAt, checkInvariants, row, scenario } from "./test/helpers.js";
|
||||
|
|
@ -206,3 +207,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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -33,6 +39,23 @@ export const DEFAULT_OPTIONS: GameOptions = {
|
|||
|
||||
const END_SIZES = [41, 31];
|
||||
|
||||
/** 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
|
||||
|
|
@ -46,7 +69,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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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", () => {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,16 +13,41 @@ 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: "",
|
||||
|
|
@ -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),
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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. For reproducible screenshots: moves=N plays N random moves,
|
||||
// holdingsVisibility=cash|cashAndShareCount|public, twoPlayerMode=fourHands, teamPlay=1, autoEnd=1, endSize=31. 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"]) {
|
||||
for (const key of ["holdingsVisibility", "twoPlayerMode", "endSize", "stockSwap", "sharesPerTurn"]) {
|
||||
const value = params.get(key);
|
||||
if (value) {
|
||||
options[key] = value;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
|
|
|
|||
|
|
@ -132,6 +132,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",
|
||||
|
|
|
|||
|
|
@ -132,6 +132,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",
|
||||
|
|
|
|||
|
|
@ -132,6 +132,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": "Ημερολόγιο παιχνιδιού",
|
||||
|
|
|
|||
|
|
@ -142,6 +142,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})",
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,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": "گزارش بازی",
|
||||
|
|
|
|||
|
|
@ -137,6 +137,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",
|
||||
|
|
|
|||
|
|
@ -129,6 +129,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": "खेल का लॉग",
|
||||
|
|
|
|||
|
|
@ -137,6 +137,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",
|
||||
|
|
|
|||
|
|
@ -131,6 +131,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": "게임 기록",
|
||||
|
|
|
|||
|
|
@ -132,6 +132,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",
|
||||
|
|
|
|||
|
|
@ -136,6 +136,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",
|
||||
|
|
|
|||
|
|
@ -136,6 +136,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",
|
||||
|
|
|
|||
|
|
@ -137,6 +137,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",
|
||||
|
|
|
|||
|
|
@ -136,6 +136,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": "Журнал игры",
|
||||
|
|
|
|||
|
|
@ -132,6 +132,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",
|
||||
|
|
|
|||
|
|
@ -129,6 +129,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": "游戏记录",
|
||||
|
|
|
|||
|
|
@ -129,6 +129,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": "遊戲紀錄",
|
||||
|
|
|
|||
32
packages/viewer/src/lib/replay.spec.ts
Normal file
32
packages/viewer/src/lib/replay.spec.ts
Normal 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);
|
||||
});
|
||||
|
|
@ -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),
|
||||
};
|
||||
}),
|
||||
|
|
|
|||
38
rules.md
38
rules.md
|
|
@ -220,10 +220,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)
|
||||
|
||||
|
|
@ -331,9 +332,22 @@ 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
|
||||
|
|
@ -344,8 +358,9 @@ Each viewer must only receive information their player is entitled to.
|
|||
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,
|
||||
- **[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
|
||||
|
|
@ -379,8 +394,9 @@ 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. |
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue