Reveal all completed sealed bids in auction history

This commit is contained in:
coyotte508 2026-10-04 14:04:05 +02:00
commit 2f57c74d56
25 changed files with 287 additions and 65 deletions

View file

@ -8,5 +8,6 @@ export * from "./src/production.js";
export * from "./src/moves.js";
export * from "./src/rankings.js";
export * from "./src/describe.js";
export * from "./src/auction-history.js";
export * from "./src/replay.js";
export * from "./src/ai.js";

View file

@ -1,6 +1,6 @@
{
"name": "outpost-engine",
"version": "0.10.20",
"version": "0.10.21",
"description": "Unofficial Outpost rules engine for boardgamers.space",
"license": "AGPL-3.0",
"files": [

View file

@ -0,0 +1,120 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { logSlice, stripSecret } from "../wrapper.js";
import { sealedAuctionHistory } from "./auction-history.js";
import { describeLog, describeLogEntry } from "./describe.js";
import { applyMove, initGame } from "./moves.js";
import { replay } from "./replay.js";
import type { GameState, ProductionCard } from "./types.js";
function game() {
const state = initGame(4, { fastBid: true }, "auction-history");
for (const player of state.players) {
player.hand = Array.from({ length: 6 }, (): ProductionCard => ({ t: "research", v: 10 }));
}
const round = state.log.find((entry) => entry.type === "round");
assert.ok(round?.type === "round");
for (const produced of round.produced) {
produced.cards = structuredClone(state.players[produced.player]!.hand);
}
return state;
}
function open(state: GameState) {
const seats = [state.activeSeat, ...state.purchaseOrder.filter((seat) => seat !== state.activeSeat)];
applyMove(state, { action: "auction", marketIndex: 0, bid: 25 }, seats[0]!);
return seats as [number, number, number, number];
}
test("sealed history stays private until completion, including passes and the opening bid", () => {
const state = game();
const [opener, winner, passer, last] = open(state);
applyMove(state, { action: "bid", amount: 40 }, winner);
applyMove(state, { action: "bidPass" }, passer);
for (const viewer of [undefined, opener, winner, passer, last]) {
const during = stripSecret(state, viewer);
assert.equal(sealedAuctionHistory(during.log).results.size, 0);
assert.equal(sealedAuctionHistory(during.log).revealed.size, 0);
assert.ok(describeLog(during).at(-1)?.includes("takes part"));
assert.ok(describeLog(during).at(-2)?.includes("takes part"));
}
applyMove(state, { action: "bid", amount: 30 }, last);
for (const viewer of [undefined, opener, winner, passer, last]) {
const after = stripSecret(state, viewer);
const history = sealedAuctionHistory(after.log);
assert.equal(history.revealed.size, 4);
assert.deepEqual(history.results.get(after.log.length - 1), {
winner,
bids: [
{ player: winner, amount: 40 },
{ player: last, amount: 30 },
{ player: opener, amount: 25 },
{ player: passer, amount: 0 },
],
});
}
});
test("completed bids remain public during the next sealed auction, including sliced descriptions", () => {
const state = game();
const [opener, winner, passer, last] = open(state);
const openingIndex = state.log.length - 1;
applyMove(state, { action: "bid", amount: 40 }, winner);
applyMove(state, { action: "bidPass" }, passer);
applyMove(state, { action: "bid", amount: 30 }, last);
const resultIndex = state.log.length - 1;
applyMove(state, { action: "pay", cards: [0, 1, 2, 3] }, winner);
open(state);
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$/);
assert.deepEqual([...sealedAuctionHistory(visible.log).results.keys()], [resultIndex]);
const slice = logSlice(state, { player: viewer, start: openingIndex + 1, end: openingIndex + 3 });
assert.deepEqual(
slice.log.map((entry) => entry.simple),
lines.slice(openingIndex + 1, openingIndex + 3)
);
}
const replayed = replay(stripSecret(state));
assert.deepEqual(sealedAuctionHistory(replayed.log), sealedAuctionHistory(stripSecret(state).log));
});
test("an immediately resolved auction reveals the opener and every automatic pass", () => {
const state = game();
const opener = state.activeSeat;
for (const [seat, player] of state.players.entries()) {
if (seat !== opener) {
player.hand = [];
}
}
open(state);
assert.equal(state.phase, "auctionPayment");
const visible = stripSecret(state);
const last = visible.log.at(-1);
assert.ok(last?.type === "move" && last.move.action === "auction");
assert.equal(last.move.bid, 25);
const result = sealedAuctionHistory(visible.log).results.get(visible.log.length - 1);
assert.equal(result?.bids.length, 4);
assert.equal(result?.bids.filter((bid) => bid.amount === 0).length, 3);
assert.deepEqual(result?.bids[0], { player: opener, amount: 25 });
});
test("a pass can resolve the result; tied bids put the winner first", () => {
const state = game();
const [opener, bidder, passer, last] = open(state);
applyMove(state, { action: "bid", amount: 40 }, bidder);
applyMove(state, { action: "bid", amount: 40 }, passer);
applyMove(state, { action: "bidPass" }, last);
const result = sealedAuctionHistory(stripSecret(state).log).results.get(state.log.length - 1)!;
assert.equal(result.bids[0]?.player, state.auction?.highBidder);
assert.equal(result.bids[0]?.amount, 40);
assert.equal(result.bids.find((bid) => bid.player === opener)?.amount, 25);
assert.equal(result.bids.find((bid) => bid.player === last)?.amount, 0);
});

View file

@ -0,0 +1,54 @@
import type { LogEntry } from "./types.js";
export interface SealedAuctionResult {
winner: number;
bids: { player: number; amount: number }[];
}
export function sealedAuctionHistory(log: LogEntry[]): {
revealed: Set<number>;
results: Map<number, SealedAuctionResult>;
} {
const revealed = new Set<number>();
const results = new Map<number, SealedAuctionResult>();
let pending: number[] = [];
let bids = new Map<number, number>();
for (const [index, entry] of log.entries()) {
if (entry.type !== "move") {
continue;
}
if (entry.move.action === "auction") {
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 {
continue;
}
pending.push(index);
for (const seat of entry.info?.autoPassed ?? []) {
bids.set(seat, 0);
}
if (entry.info?.winningBid !== undefined) {
for (const bidIndex of pending) {
revealed.add(bidIndex);
}
const winner = entry.info.winner ?? entry.player;
results.set(index, {
winner,
bids: [...bids]
.filter(([, amount]) => amount >= 0)
.map(([player, amount]) => ({ player, amount }))
.sort(
(a, b) =>
b.amount - a.amount || Number(b.player === winner) - Number(a.player === winner) || a.player - b.player
),
});
pending = [];
bids.clear();
}
}
return { revealed, results };
}

View file

@ -1,4 +1,5 @@
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). */
@ -43,11 +44,15 @@ function autoPassSuffix(state: GameState, info: MoveInfo | undefined): string {
* 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): boolean {
return state.phase === "auction" && state.auction?.bids !== undefined;
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): string {
export function describeLogEntry(state: GameState, entry: LogEntry, sealedBidVisible?: boolean): string {
switch (entry.type) {
case "init":
return `Game started with ${entry.players} players`;
@ -82,7 +87,7 @@ export function describeLogEntry(state: GameState, entry: LogEntry): string {
// 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) || move.bid < 0) {
if (sealedQuiet(state, entry, sealedBidVisible) || move.bid < 0) {
return `${name} puts ${cardName(info, "an upgrade")} up for sealed auction`;
}
return (
@ -94,7 +99,7 @@ export function describeLogEntry(state: GameState, entry: LogEntry): string {
const won = playerName(state, info.winner ?? entry.player);
return `${name} bids ${move.amount} (sealed) — ${won} wins at ${sealedPrice(info)}`;
}
if (sealedQuiet(state) || move.amount < 0) {
if (sealedQuiet(state, entry, sealedBidVisible) || move.amount < 0) {
return `${name} takes part in the sealed auction`;
}
return `${name} bids ${move.amount}` + autoPassSuffix(state, info);
@ -105,7 +110,7 @@ export function describeLogEntry(state: GameState, entry: LogEntry): string {
const won = playerName(state, info.winner ?? entry.player);
return `${name} passes — ${won} wins the sealed auction at ${sealedPrice(info)}`;
}
if (sealedQuiet(state)) {
if (sealedQuiet(state, entry, sealedBidVisible)) {
return `${name} takes part in the sealed auction`;
}
return `${name} passes on the auction` + autoPassSuffix(state, info);
@ -158,5 +163,6 @@ export function describeLogEntry(state: GameState, entry: LogEntry): string {
}
export function describeLog(state: GameState): string[] {
return state.log.map((entry) => describeLogEntry(state, entry));
const { revealed } = sealedAuctionHistory(state.log);
return state.log.map((entry, index) => describeLogEntry(state, entry, revealed.has(index)));
}

View file

@ -4,6 +4,7 @@ import { RESOURCES } from "./src/types.js";
import { maxBid, needsMegaChoice } from "./src/state.js";
import { moveAI as moveAICore } from "./src/ai.js";
import { describeLogEntry } from "./src/describe.js";
import { sealedAuctionHistory } from "./src/auction-history.js";
import { applyMove, dropPlayer as dropPlayerCore, initGame } from "./src/moves.js";
import { rankings as computeRankings } from "./src/rankings.js";
import { replay as replayCore } from "./src/replay.js";
@ -183,43 +184,6 @@ function hideProduced(
};
}
/**
* fastBid reveal: the log indexes whose sealed bids are public because their
* auction has already resolved by that point. The resolving move itself (the
* one carrying info.winningBid) is where the bids turn visible, so its own
* index is included. A stripped log is the source of truth for replays, so
* the reveal must be derivable from the stripped entries alone — it is: the
* resolution outcome (winningBid/secondBid/winner) is deliberately never
* masked, and auction boundaries are marked by "auction" moves.
*/
function revealedBidIndexes(log: LogEntry[]): Set<number> {
const revealed = new Set<number>();
// Indexes of the bid moves of the auction currently collecting sealed bids.
let pending: number[] = [];
for (let i = 0; i < log.length; i++) {
const entry = log[i] as LogEntry;
if (entry.type !== "move") {
continue;
}
if (entry.move.action === "auction") {
pending = [i];
continue;
}
if (entry.move.action === "bid") {
pending.push(i);
}
if (entry.info?.winningBid !== undefined) {
// The auction resolves here: every sealed bid of it is revealed.
for (const j of pending) {
revealed.add(j);
}
revealed.add(i);
pending = [];
}
}
return revealed;
}
export function stripSecret(data: GameState, player?: number): GameState {
const viewer = player !== undefined && player >= 0 ? player : undefined;
// fastBid: other players' sealed bids are hidden while the auction runs.
@ -303,7 +267,7 @@ function maskLog(
start = 0,
end = data.log.length
): (LogEntry & { simple?: string })[] {
const revealed = revealedBidIndexes(data.log);
const { revealed } = sealedAuctionHistory(data.log);
const hideOwn = hideOwnProduction(data, viewer);
// An exchange's received card is parked on the upgrade until the exchange
// step (end of the discard phase) closes, i.e. while data.exchange is set.
@ -357,9 +321,10 @@ 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 log = maskLog(data, viewer, start, end).map((masked) => ({
const { revealed } = sealedAuctionHistory(data.log);
const log = maskLog(data, viewer, start, end).map((masked, index) => ({
...masked,
simple: describeLogEntry(data, masked),
simple: describeLogEntry(data, masked, revealed.has(start + index)),
}));
const result: LogSliceResult = { log };
if (options?.end === undefined) {

View file

@ -1,6 +1,6 @@
{
"name": "outpost-viewer",
"version": "0.1.16",
"version": "0.1.17",
"description": "Browser viewer for the Outpost game on boardgamers.space",
"license": "AGPL-3.0",
"files": [

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { tick, untrack } from "svelte";
import { sealedAuctionHistory } from "outpost-engine";
import type { ViewerStore } from "./store.svelte";
interface Props {
@ -8,6 +9,7 @@
let { store }: Props = $props();
const lines = $derived(store.logLines);
const results = $derived(sealedAuctionHistory(store.liveState?.log ?? []).results);
const recent = $derived(lines.map((line, index) => ({ line, index })).slice(-150));
let feed = $state<HTMLDivElement>();
let content = $state<HTMLDivElement>();
@ -68,6 +70,22 @@
{:else}
<div class="entry" class:latest={item.index === lines.length - 1}>{item.line}</div>
{/if}
{#if results.get(item.index)}
{@const result = results.get(item.index)!}
<div class="auction-result">
<div class="result-label">Revealed bids</div>
<ul>
{#each result.bids as bid (bid.player)}
<li class:winner={bid.player === result.winner}>
<span class="bidder" translate="no"
>{store.liveState?.players[bid.player]?.name ?? `Player ${bid.player + 1}`}</span
>
<strong>{bid.amount === 0 ? "Pass" : `◈ ${bid.amount}`}</strong>
</li>
{/each}
</ul>
</div>
{/if}
{/each}
{#if recent.length === 0}
<div class="entry dim">No events yet</div>
@ -77,6 +95,43 @@
</div>
<style>
.auction-result {
border-left: 2px solid var(--gold);
padding: 5px 8px;
margin: 1px 0 5px;
background: color-mix(in srgb, var(--gold) 5%, transparent);
font-size: 12px;
}
.result-label {
color: var(--text-mid);
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.04em;
}
.auction-result ul {
list-style: none;
margin: 3px 0 0;
padding: 0;
}
.auction-result li {
display: flex;
justify-content: space-between;
gap: 12px;
color: var(--text);
}
.bidder {
min-width: 0;
overflow-wrap: anywhere;
}
.auction-result strong {
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.auction-result .winner {
color: var(--gold);
font-weight: 600;
}
.side {
display: flex;
flex-direction: column;

View file

@ -355,6 +355,11 @@ export class ViewerStore {
this.commands.fetchState();
return;
}
if (entries.some((entry) => entry.type === "move" && entry.info?.winningBid !== undefined)) {
// The resolution also reveals earlier bid entries, so refresh the full log.
this.commands.fetchState();
return;
}
if (payload.start >= this.logLines.length) {
const appended = entries.map((entry) => describeLogEntry(base, entry));
this.logLines = [...this.logLines, ...appended];

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} mangler",
"Discount ◈ {p0}": "Rabat ◈ {p0}",
"Bid submitted": "Bud afgivet",
"Auction details": "Auktionsdetaljer"
"Auction details": "Auktionsdetaljer",
"Revealed bids": "Afslørede bud"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} ausstehend",
"Discount ◈ {p0}": "Rabatt ◈ {p0}",
"Bid submitted": "Gebot abgegeben",
"Auction details": "Auktionsdetails"
"Auction details": "Auktionsdetails",
"Revealed bids": "Aufgedeckte Gebote"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "Σε αναμονή: {p0}",
"Discount ◈ {p0}": "Έκπτωση ◈ {p0}",
"Bid submitted": "Η προσφορά υποβλήθηκε",
"Auction details": "Λεπτομέρειες δημοπρασίας"
"Auction details": "Λεπτομέρειες δημοπρασίας",
"Revealed bids": "Αποκαλυμμένες προσφορές"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} pending",
"Discount ◈ {p0}": "Discount ◈ {p0}",
"Bid submitted": "Bid submitted",
"Auction details": "Auction details"
"Auction details": "Auction details",
"Revealed bids": "Revealed bids"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} در انتظار",
"Discount ◈ {p0}": "تخفیف ◈ {p0}",
"Bid submitted": "پیشنهاد ثبت شد",
"Auction details": "جزئیات حراج"
"Auction details": "جزئیات حراج",
"Revealed bids": "پیشنهادهای آشکارشده"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} en attente",
"Discount ◈ {p0}": "Réduction ◈ {p0}",
"Bid submitted": "Enchère envoyée",
"Auction details": "Détails de l’enchère"
"Auction details": "Détails de l’enchère",
"Revealed bids": "Enchères révélées"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} बाकी",
"Discount ◈ {p0}": "छूट ◈ {p0}",
"Bid submitted": "बोली भेजी गई",
"Auction details": "नीलामी का विवरण"
"Auction details": "नीलामी का विवरण",
"Revealed bids": "प्रकट की गई बोलियाँ"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "In attesa: {p0}",
"Discount ◈ {p0}": "Sconto ◈ {p0}",
"Bid submitted": "Offerta inviata",
"Auction details": "Dettagli dell’asta"
"Auction details": "Dettagli dell’asta",
"Revealed bids": "Offerte rivelate"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0}명 대기 중",
"Discount ◈ {p0}": "할인 ◈ {p0}",
"Bid submitted": "입찰 제출 완료",
"Auction details": "경매 안내"
"Auction details": "경매 안내",
"Revealed bids": "공개된 입찰"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "Nog te bieden: {p0}",
"Discount ◈ {p0}": "Korting ◈ {p0}",
"Bid submitted": "Bod ingediend",
"Auction details": "Veilingdetails"
"Auction details": "Veilingdetails",
"Revealed bids": "Onthulde biedingen"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "Oczekuje: {p0}",
"Discount ◈ {p0}": "Zniżka ◈ {p0}",
"Bid submitted": "Oferta wysłana",
"Auction details": "Szczegóły aukcji"
"Auction details": "Szczegóły aukcji",
"Revealed bids": "Ujawnione oferty"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} pendentes",
"Discount ◈ {p0}": "Desconto ◈ {p0}",
"Bid submitted": "Lance enviado",
"Auction details": "Detalhes do leilão"
"Auction details": "Detalhes do leilão",
"Revealed bids": "Lances revelados"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "În așteptare: {p0}",
"Discount ◈ {p0}": "Reducere ◈ {p0}",
"Bid submitted": "Ofertă trimisă",
"Auction details": "Detaliile licitației"
"Auction details": "Detaliile licitației",
"Revealed bids": "Oferte dezvăluite"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "Ожидается: {p0}",
"Discount ◈ {p0}": "Скидка ◈ {p0}",
"Bid submitted": "Ставка отправлена",
"Auction details": "Подробности аукциона"
"Auction details": "Подробности аукциона",
"Revealed bids": "Раскрытые ставки"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "Còn chờ: {p0}",
"Discount ◈ {p0}": "Giảm giá ◈ {p0}",
"Bid submitted": "Đã gửi giá đấu",
"Auction details": "Chi tiết đấu giá"
"Auction details": "Chi tiết đấu giá",
"Revealed bids": "Giá đấu đã công bố"
}

View file

@ -1195,5 +1195,6 @@
"{p0} pending": "{p0} 人待出價",
"Discount ◈ {p0}": "折扣 ◈ {p0}",
"Bid submitted": "已提交出價",
"Auction details": "拍賣詳情"
"Auction details": "拍賣詳情",
"Revealed bids": "已揭曉的出價"
}