diff --git a/packages/engine/package.json b/packages/engine/package.json index 9f5c234..39aa367 100644 --- a/packages/engine/package.json +++ b/packages/engine/package.json @@ -1,6 +1,6 @@ { "name": "outpost-engine", - "version": "0.10.21", + "version": "0.10.22", "description": "Unofficial Outpost rules engine for boardgamers.space", "license": "AGPL-3.0", "files": [ diff --git a/packages/engine/src/auction-history.spec.ts b/packages/engine/src/auction-history.spec.ts index f779f56..d8b1767 100644 --- a/packages/engine/src/auction-history.spec.ts +++ b/packages/engine/src/auction-history.spec.ts @@ -55,7 +55,7 @@ test("sealed history stays private until completion, including passes and the op } }); -test("completed bids remain public during the next sealed auction, including sliced descriptions", () => { +test("completed results keep every bid while descriptions show only the viewer's own amount", () => { const state = game(); const [opener, winner, passer, last] = open(state); const openingIndex = state.log.length - 1; @@ -68,14 +68,29 @@ test("completed bids remain public during the next sealed auction, including sli applyMove(state, { action: "bidPass" }, winner); for (const viewer of [undefined, opener, winner, passer, last]) { const visible = stripSecret(state, viewer); - const lines = describeLog(visible); - assert.match(lines[openingIndex]!, /up for auction at 25/); - assert.equal(lines[openingIndex + 1], `${state.players[winner]!.name} bids 40`); - assert.equal(lines[openingIndex + 2], `${state.players[passer]!.name} passes on the auction`); - assert.equal(describeLogEntry(visible, visible.log[openingIndex + 1]!), lines[openingIndex + 1]); - assert.match(lines.at(-2)!, /up for sealed auction$/); - assert.match(lines.at(-1)!, /takes part in the sealed auction$/); + const lines = describeLog(visible, viewer); + assert.match(lines[openingIndex]!, viewer === opener ? /up for auction at 25$/ : /up for sealed auction$/); + assert.equal( + lines[openingIndex + 1], + `${state.players[winner]!.name} ${viewer === winner ? "bids 40" : "takes part in the sealed auction"}` + ); + assert.equal( + lines[openingIndex + 2], + `${state.players[passer]!.name} ${viewer === passer ? "passes on the auction" : "takes part in the sealed auction"}` + ); + assert.equal(describeLogEntry(visible, visible.log[openingIndex + 1]!, viewer), lines[openingIndex + 1]); + assert.match(lines.at(-2)!, viewer === opener ? /up for auction at 25$/ : /up for sealed auction$/); + assert.match(lines.at(-1)!, viewer === winner ? /passes on the auction$/ : /takes part in the sealed auction$/); + assert.ok(lines.every((line) => !line.includes(" wins "))); + assert.match(lines[resultIndex + 1]!, /buys .* \(paid 40\)$/); assert.deepEqual([...sealedAuctionHistory(visible.log).results.keys()], [resultIndex]); + assert.deepEqual( + sealedAuctionHistory(visible.log) + .results.get(resultIndex) + ?.bids.map((bid) => bid.amount), + [40, 30, 25, 0] + ); + assert.equal(sealedAuctionHistory(visible.log).results.get(resultIndex)?.paid, 40); const slice = logSlice(state, { player: viewer, start: openingIndex + 1, end: openingIndex + 3 }); assert.deepEqual( slice.log.map((entry) => entry.simple), @@ -86,6 +101,26 @@ test("completed bids remain public during the next sealed auction, including sli assert.deepEqual(sealedAuctionHistory(replayed.log), sealedAuctionHistory(stripSecret(state).log)); }); +test("own sealed bids remain visible while collecting bids without revealing other players' actions", () => { + const state = game(); + const [opener, bidder, passer] = open(state); + const openingIndex = state.log.length - 1; + applyMove(state, { action: "bid", amount: 40 }, bidder); + applyMove(state, { action: "bidPass" }, passer); + for (const viewer of [undefined, opener, bidder, passer]) { + const visible = stripSecret(state, viewer); + const lines = describeLog(visible, viewer); + assert.match(lines[openingIndex]!, viewer === opener ? /up for auction at 25$/ : /up for sealed auction$/); + assert.match(lines.at(-2)!, viewer === bidder ? /bids 40$/ : /takes part in the sealed auction$/); + assert.match(lines.at(-1)!, viewer === passer ? /passes on the auction$/ : /takes part in the sealed auction$/); + assert.equal(sealedAuctionHistory(visible.log).results.size, 0); + assert.deepEqual( + logSlice(state, { player: viewer }).log.map((entry) => entry.simple), + lines + ); + } +}); + test("an immediately resolved auction reveals the opener and every automatic pass", () => { const state = game(); const opener = state.activeSeat; diff --git a/packages/engine/src/auction-history.ts b/packages/engine/src/auction-history.ts index 8c5525e..bae8217 100644 --- a/packages/engine/src/auction-history.ts +++ b/packages/engine/src/auction-history.ts @@ -3,6 +3,7 @@ import type { LogEntry } from "./types.js"; export interface SealedAuctionResult { winner: number; bids: { player: number; amount: number }[]; + paid?: number; } export function sealedAuctionHistory(log: LogEntry[]): { @@ -13,17 +14,25 @@ export function sealedAuctionHistory(log: LogEntry[]): { const results = new Map(); let pending: number[] = []; let bids = new Map(); + let awaitingPayment: SealedAuctionResult | undefined; for (const [index, entry] of log.entries()) { if (entry.type !== "move") { continue; } if (entry.move.action === "auction") { + awaitingPayment = undefined; pending = []; bids = new Map([[entry.player, entry.move.bid]]); } else if (entry.move.action === "bid") { bids.set(entry.player, entry.move.amount); } else if (entry.move.action === "bidPass") { bids.set(entry.player, 0); + } else if (entry.move.action === "pay") { + if (awaitingPayment?.winner === entry.player && entry.info?.paid !== undefined) { + awaitingPayment.paid = entry.info.paid; + } + awaitingPayment = undefined; + continue; } else { continue; } @@ -36,7 +45,7 @@ export function sealedAuctionHistory(log: LogEntry[]): { revealed.add(bidIndex); } const winner = entry.info.winner ?? entry.player; - results.set(index, { + awaitingPayment = { winner, bids: [...bids] .filter(([, amount]) => amount >= 0) @@ -45,7 +54,8 @@ export function sealedAuctionHistory(log: LogEntry[]): { (a, b) => b.amount - a.amount || Number(b.player === winner) - Number(a.player === winner) || a.player - b.player ), - }); + }; + results.set(index, awaitingPayment); pending = []; bids.clear(); } diff --git a/packages/engine/src/describe.ts b/packages/engine/src/describe.ts index 3d3a1d0..b9f6547 100644 --- a/packages/engine/src/describe.ts +++ b/packages/engine/src/describe.ts @@ -1,5 +1,4 @@ import { FACTORIES, KICKER_SPECS, UPGRADE_SPECS } from "./data.js"; -import { sealedAuctionHistory } from "./auction-history.js"; import type { GameState, LogEntry, MoveInfo } from "./types.js"; /** Display name of the card a move concerns (colony upgrade or Kicker card). */ @@ -13,11 +12,6 @@ function cardName(info: MoveInfo | undefined, fallback: string): string { return fallback; } -function sealedPrice(info: MoveInfo): number { - const floor = info.kicker ? KICKER_SPECS[info.kicker].price : info.upgrade ? UPGRADE_SPECS[info.upgrade].price : 0; - return Math.min(info.winningBid ?? 0, Math.max(floor, (info.secondBid ?? 0) + 1)); -} - function playerName(state: GameState, seat: number): string { return state.players[seat]?.name ?? `Player ${seat + 1}`; } @@ -37,22 +31,7 @@ function autoPassSuffix(state: GameState, info: MoveInfo | undefined): string { return ` — ${seats.map((s) => playerName(state, s)).join(", ")} auto-pass${seats.length === 1 ? "es" : ""} (can't reach the price)`; } -/** - * fastBid keeps its moveset quiet while an auction collects sealed bids: - * the opening, every bid and every pass of an unresolved auction all read - * as a neutral "sealed auction in progress" — no amounts, no pass-vs-bid, - * no auto-pass names. Once the resolving move is logged the real moves are - * revealed (amounts, passes) by the wrapper's unmasking and described fully. - */ -function sealedQuiet(state: GameState, entry: LogEntry, revealed?: boolean): boolean { - return ( - state.phase === "auction" && - state.auction?.bids !== undefined && - !(revealed ?? sealedAuctionHistory(state.log).revealed.has(state.log.indexOf(entry))) - ); -} - -export function describeLogEntry(state: GameState, entry: LogEntry, sealedBidVisible?: boolean): string { +export function describeLogEntry(state: GameState, entry: LogEntry, viewer?: number): string { switch (entry.type) { case "init": return `Game started with ${entry.players} players`; @@ -71,6 +50,7 @@ export function describeLogEntry(state: GameState, entry: LogEntry, sealedBidVis const name = playerName(state, entry.player); const move = entry.move; const info = entry.info; + const sealed = state.options.fastBid === true; switch (move.action) { case "mega": { if (info?.megaSealed) { @@ -84,36 +64,24 @@ export function describeLogEntry(state: GameState, entry: LogEntry, sealedBidVis case "discard": return `${name} discards ${info?.discarded ?? move.cards.length} card(s)`; case "auction": - // fastBid: while the sealed bids are collected, the opening is - // neutral for everyone (even the auctioneer — the amount is - // sealed). After resolution the wrapper reveals the bid. - if (sealedQuiet(state, entry, sealedBidVisible) || move.bid < 0) { + if ((sealed && entry.player !== viewer) || move.bid < 0) { return `${name} puts ${cardName(info, "an upgrade")} up for sealed auction`; } return ( - `${name} puts ${cardName(info, "an upgrade")} up for auction at ${move.bid}` + autoPassSuffix(state, info) + `${name} puts ${cardName(info, "an upgrade")} up for auction at ${move.bid}` + + (sealed ? "" : autoPassSuffix(state, info)) ); case "bid": { - // fastBid: the resolving move carries the outcome in its info. - if (info?.winningBid !== undefined) { - const won = playerName(state, info.winner ?? entry.player); - return `${name} bids ${move.amount} (sealed) — ${won} wins at ${sealedPrice(info)}`; - } - if (sealedQuiet(state, entry, sealedBidVisible) || move.amount < 0) { + if ((sealed && entry.player !== viewer) || move.amount < 0) { return `${name} takes part in the sealed auction`; } - return `${name} bids ${move.amount}` + autoPassSuffix(state, info); + return `${name} bids ${move.amount}` + (sealed ? "" : autoPassSuffix(state, info)); } case "bidPass": - // fastBid: a pass can be the resolving move — it carries the outcome. - if (info?.winningBid !== undefined) { - const won = playerName(state, info.winner ?? entry.player); - return `${name} passes — ${won} wins the sealed auction at ${sealedPrice(info)}`; - } - if (sealedQuiet(state, entry, sealedBidVisible)) { + if (sealed && entry.player !== viewer) { return `${name} takes part in the sealed auction`; } - return `${name} passes on the auction` + autoPassSuffix(state, info); + return `${name} passes on the auction` + (sealed ? "" : autoPassSuffix(state, info)); case "pay": return `${name} buys ${cardName(info, "the upgrade")} (paid ${info?.paid ?? 0})`; case "exchange": { @@ -162,7 +130,6 @@ export function describeLogEntry(state: GameState, entry: LogEntry, sealedBidVis } } -export function describeLog(state: GameState): string[] { - const { revealed } = sealedAuctionHistory(state.log); - return state.log.map((entry, index) => describeLogEntry(state, entry, revealed.has(index))); +export function describeLog(state: GameState, viewer?: number): string[] { + return state.log.map((entry) => describeLogEntry(state, entry, viewer)); } diff --git a/packages/engine/src/fastbid.spec.ts b/packages/engine/src/fastbid.spec.ts index 5c12917..81bcfba 100644 --- a/packages/engine/src/fastbid.spec.ts +++ b/packages/engine/src/fastbid.spec.ts @@ -162,7 +162,7 @@ test("fastBid: a sole bidder pays the list price", () => { assert.equal(state.phase, "auctionPayment"); assert.equal(state.auction?.highBidder, opener); assert.equal(state.auction?.highBid, 25); - assert.match(describeLogEntry(state, state.log.at(-1)!), /wins the sealed auction at 25$/); + assert.match(describeLogEntry(state, state.log.at(-1)!), /takes part in the sealed auction$/); }); test("fastBid: overbidding the opening still pays only the list price when everyone passes", () => { @@ -177,7 +177,7 @@ test("fastBid: overbidding the opening still pays only the list price when every assert.equal(state.phase, "auctionPayment"); assert.equal(state.auction?.highBidder, opener); assert.equal(state.auction?.highBid, 25); - assert.match(describeLogEntry(state, state.log.at(-1)!), /wins the sealed auction at 25$/); + assert.match(describeLogEntry(state, state.log.at(-1)!), /takes part in the sealed auction$/); }); test("fastBid: bid below list price is rejected", () => { diff --git a/packages/engine/src/replay.ts b/packages/engine/src/replay.ts index 1a50164..a8ba00c 100644 --- a/packages/engine/src/replay.ts +++ b/packages/engine/src/replay.ts @@ -67,6 +67,13 @@ export function replay(state: GameState, options?: { to?: number; trackKnowledge } setReplayExchangeTake(entry.info?.exchangeTake ?? -1); applyMove(replayed, entry.move, entry.player); + if (entry.move.action === "pay" && entry.info?.paid !== undefined) { + // The public payment is known even when the replay's card values are masked. + const applied = replayed.log[i]; + if (applied?.type === "move") { + applied.info = { ...applied.info, paid: entry.info.paid }; + } + } if (entry.info?.megaSealed) { const applied = replayed.log.at(-1); if (applied?.type === "move") { diff --git a/packages/engine/wrapper.ts b/packages/engine/wrapper.ts index 96d6089..4c50b4c 100644 --- a/packages/engine/wrapper.ts +++ b/packages/engine/wrapper.ts @@ -321,10 +321,9 @@ export function logSlice(data: GameState, options?: LogSliceOptions): LogSliceRe // in the game list, and our structured entries otherwise stringify to noise. // describeLogEntry never reveals hidden values (unresolved sealed bids, // exchange takes). - const { revealed } = sealedAuctionHistory(data.log); - const log = maskLog(data, viewer, start, end).map((masked, index) => ({ + const log = maskLog(data, viewer, start, end).map((masked) => ({ ...masked, - simple: describeLogEntry(data, masked, revealed.has(start + index)), + simple: describeLogEntry(data, masked, viewer), })); const result: LogSliceResult = { log }; if (options?.end === undefined) { diff --git a/packages/viewer/package.json b/packages/viewer/package.json index 88ef6f0..59ce182 100644 --- a/packages/viewer/package.json +++ b/packages/viewer/package.json @@ -1,6 +1,6 @@ { "name": "outpost-viewer", - "version": "0.1.17", + "version": "0.1.18", "description": "Browser viewer for the Outpost game on boardgamers.space", "license": "AGPL-3.0", "files": [ diff --git a/packages/viewer/src/App.svelte b/packages/viewer/src/App.svelte index 2ef4bef..839e0ed 100644 --- a/packages/viewer/src/App.svelte +++ b/packages/viewer/src/App.svelte @@ -26,7 +26,7 @@ {#if state}
- + {#if __DEV__}{/if} diff --git a/packages/viewer/src/lib/LogFeed.svelte b/packages/viewer/src/lib/LogFeed.svelte index 5389dd7..964621d 100644 --- a/packages/viewer/src/lib/LogFeed.svelte +++ b/packages/viewer/src/lib/LogFeed.svelte @@ -1,6 +1,6 @@