Add optional catch-up pricing for auctions

This commit is contained in:
coyotte508 2026-11-18 20:42:09 +00:00
commit acf70b7002
16 changed files with 458 additions and 72 deletions

View file

@ -100,7 +100,9 @@ pnpm dev # viewer dev server + mock backend harness (human + bots)
pnpm check # fmt:check + lint + tsc + test + build
```
Dev harness URL params: `?players=4&seed=xyz&delay=700&auto=1&fastBid=1&kicker=1`.
An optional **Catch-up pricing** rule (`catchUp: true`) applies to auctions in Era II and III when at least four players remain. Based on current victory points (ties broken by seat), the top two players pay a surcharge of ◈ 10/5 in Era II or ◈ 20/10 in Era III; the bottom two receive the corresponding discounts. The adjustment applies to colony upgrades and Kicker cards, combines with existing card discounts, and cannot reduce payment below zero. Printed minimum bids are unchanged. Factories, colonists, and robots retain their normal costs. Games created without the option are unaffected. To expose it on BGS game creation, add `{ "name": "catchUp", "label": "Catch-up pricing (4+ players)", "type": "checkbox", "default": false, "requiredPlayers": [4, 5, 6, 7, 8, 9] }` to the `options` array of the Outpost gameinfo doc. This declaration only affects newly created games.
Dev harness URL params: `?players=4&seed=xyz&delay=700&auto=1&fastBid=1&kicker=1&catchUp=1`.
Node >= 24, pnpm 11 (see `packageManager`). All dependencies pinned.

View file

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

View file

@ -2,6 +2,7 @@ import { FACTORIES, KICKER_SPECS, MEGA_CARDS, PRODUCTION_DECKS, UPGRADE_SPECS }
import { applyMove } from "./moves.js";
import {
auctionCard,
auctionDiscount,
bestDiscard,
bestPayment,
canBuyFactory,
@ -13,7 +14,7 @@ import {
operators as availableOperators,
populationCost,
populationMax,
upgradeDiscount,
maxBid,
} from "./state.js";
import type { GameState, Move, PlayerState, Resource, TurnBuy, Upgrade } from "./types.js";
@ -39,7 +40,7 @@ export function chooseMove(state: GameState, seat: number): Move {
// fastBid: bid the max affordable when the list price can be exceeded,
// otherwise pass (the sealed bid keeps a weak hand hidden).
if (auction?.bids) {
const max = handValue(player) + (auction.upgrade ? upgradeDiscount(player, auction.upgrade) : 0);
const max = maxBid(state, seat, auction.upgrade, auction.kicker);
if (max > auctionCard(auction).price) {
return { action: "bid", amount: max };
}
@ -51,11 +52,11 @@ export function chooseMove(state: GameState, seat: number): Move {
if (!auction) {
throw new Error("no auction in progress");
}
const due = Math.max(0, auction.highBid - (auction.upgrade ? upgradeDiscount(player, auction.upgrade) : 0));
const due = Math.max(0, auction.highBid - auctionDiscount(state, seat, auction));
return { action: "pay", cards: bestPayment(player, due) ?? player.hand.map((_, i) => i) };
}
case "actions":
return chooseAction(state, player);
return chooseAction(state, seat, player);
default:
throw new Error(`no move expected in phase ${state.phase}`);
}
@ -130,7 +131,7 @@ function chooseDiscard(player: PlayerState): Move {
return { action: "discard", cards: bestDiscard(player) };
}
function chooseAction(state: GameState, player: PlayerState): Move {
function chooseAction(state: GameState, seat: number, player: PlayerState): Move {
const cash = handValue(player);
// 1. Auction the highest-VP card we can afford at list price (upgrades and
@ -139,7 +140,7 @@ function chooseAction(state: GameState, player: PlayerState): Move {
let bestVp = -1;
for (const [index, upgrade] of state.market.entries()) {
const spec = UPGRADE_SPECS[upgrade];
const due = Math.max(0, spec.price - upgradeDiscount(player, upgrade));
const due = Math.max(0, spec.price - auctionDiscount(state, seat, { upgrade }));
if (cash >= due && spec.vp > bestVp) {
bestVp = spec.vp;
best = { kicker: false, index, bid: spec.price };
@ -147,7 +148,7 @@ function chooseAction(state: GameState, player: PlayerState): Move {
}
for (const [index, kicker] of state.kickerMarket.entries()) {
const spec = KICKER_SPECS[kicker];
if (cash >= spec.price && spec.vp > bestVp) {
if (cash >= Math.max(0, spec.price - auctionDiscount(state, seat, { kicker })) && spec.vp > bestVp) {
bestVp = spec.vp;
best = { kicker: true, index, bid: spec.price };
}

View file

@ -133,3 +133,15 @@ test("bounced exchanges constrain the target's retained resource values", async
assert.ok(sample.players[0]!.hand.every((card) => card.t !== "water" || card.v <= 9));
}
});
test("analysis retains catchUp pricing and its active-player ranks", async () => {
const state = await init(4, [], { catchUp: true }, "analysis-catchup");
state.era = 2;
const scenario = createAnalysisScenario(state, { player: 0, seed: "simulation" });
assert.equal(scenario.options.catchUp, true);
assert.equal(scenario.era, 2);
assert.equal(
maxBid(scenario, 0, "heavyEquipment"),
scenario.players[0]!.hand.reduce((sum, card) => sum + card.v, 0) - 10
);
});

View file

@ -0,0 +1,46 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { applyMove, initGame } from "./moves.js";
import { replay } from "./replay.js";
import { stripSecret } from "../wrapper.js";
import { auctionDiscount } from "./state.js";
test("catchUp sealed and open payment replay from stripped logs", () => {
for (const fastBid of [false, true]) {
const s = initGame(4, { catchUp: true, fastBid }, `replay-catchup-${fastBid}`);
const round = s.log.find((e) => e.type === "round");
assert.ok(round && round.type === "round");
round.era = 2;
s.era = 2;
round.market = ["heavyEquipment"];
s.market = ["heavyEquipment"];
for (const { player, cards } of round.produced) {
cards.splice(0, cards.length, { t: "research", v: 20 }, { t: "research", v: 20 });
s.players[player]!.hand = cards.map((c) => ({ ...c }));
}
const opener = s.activeSeat;
assert.equal(auctionDiscount(s, opener, { upgrade: "heavyEquipment" }), -10);
applyMove(s, { action: "auction", marketIndex: 0, bid: 25 }, opener);
if (fastBid) {
for (let seat = 0; seat < 4; seat++) {
if (seat !== opener) {
applyMove(s, { action: "bidPass" }, seat);
}
}
} else {
while (s.phase === "auction") {
applyMove(s, { action: "bidPass" }, s.auction!.activeBidder);
}
}
assert.equal(s.phase, "auctionPayment");
applyMove(s, { action: "pay", cards: [0, 1] }, opener);
const stripped = stripSecret(s);
const restored = replay(stripped);
assert.equal(restored.players[opener]!.upgrades.heavyEquipment, s.players[opener]!.upgrades.heavyEquipment);
assert.equal(restored.era, 2);
assert.equal(
auctionDiscount(restored, opener, { upgrade: "heavyEquipment" }),
auctionDiscount(s, opener, { upgrade: "heavyEquipment" })
);
}
});

View file

@ -0,0 +1,196 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { chooseMove } from "./ai.js";
import { applyMove, initGame } from "./moves.js";
import { auctionDiscount, maxBid, mustAutoPassBid, publicMaxBid, rankAdjustment } from "./state.js";
import type { GameState } from "./types.js";
function game(count = 4, fastBid = false): GameState {
const s = initGame(count, { catchUp: true, fastBid, kicker: true }, "catchup-test");
s.era = 2;
s.market = ["scientists", "heavyEquipment"];
s.kickerMarket = ["smelter"];
for (const p of s.players) {
p.hand = [
{ t: "research", v: 30 },
{ t: "research", v: 30 },
];
}
// Distinct VP without using the auctioned cards.
s.players[0]!.upgrades.outpost = 3;
s.players[1]!.upgrades.outpost = 2;
s.players[2]!.upgrades.outpost = 1;
return s;
}
test("rank applies only to four active players in era II/III; VP ties use seat, not spent", () => {
const s = game();
assert.deepEqual(
s.players.map((_, i) => rankAdjustment(s, i)),
[-10, -5, 5, 10]
);
s.era = 3;
assert.deepEqual(
s.players.map((_, i) => rankAdjustment(s, i)),
[-20, -10, 10, 20]
);
s.era = 1;
assert.deepEqual(
s.players.map((_, i) => rankAdjustment(s, i)),
[0, 0, 0, 0]
);
s.era = 2;
for (const p of s.players) {
p.upgrades.outpost = 0;
p.spent = 100;
}
s.players[3]!.spent = 9999;
assert.deepEqual(
s.players.map((_, i) => rankAdjustment(s, i)),
[-10, -5, 5, 10]
);
s.players[1]!.dropped = true;
assert.deepEqual(
s.players.map((_, i) => rankAdjustment(s, i)),
[0, 0, 0, 0]
);
const three = game(3);
assert.deepEqual(
three.players.map((_, i) => rankAdjustment(three, i)),
[0, 0, 0]
);
s.players[1]!.dropped = false;
s.options.catchUp = false;
assert.equal(rankAdjustment(s, 0), 0);
});
test("signed discounts combine with existing upgrade discount, Kicker and zero floor", () => {
const s = game();
s.players[0]!.upgrades.dataLibrary = 2;
assert.equal(auctionDiscount(s, 0, { upgrade: "scientists" }), 10);
assert.equal(auctionDiscount(s, 0, { kicker: "smelter" }), -10);
assert.equal(auctionDiscount(s, 3, { kicker: "smelter" }), 10);
assert.equal(maxBid(s, 0, "scientists"), 70);
assert.equal(publicMaxBid(s, 0, "scientists"), 44); // two research cards, public max 17 each
s.players[3]!.upgrades.dataLibrary = 10;
assert.equal(auctionDiscount(s, 3, { upgrade: "scientists" }), 105); // VP ranking is recalculated after the upgrade change
});
test("open auction enforces surcharge for opening and raises, discounts payment and Kicker", () => {
const s = game();
s.activeSeat = 0;
s.players[0]!.hand = [{ t: "research", v: 30 }];
assert.throws(() => applyMove(s, { action: "auction", marketIndex: 1, bid: 25 }, 0), /cannot afford/);
s.players[0]!.hand.push({ t: "research", v: 10 });
applyMove(s, { action: "auction", marketIndex: 1, bid: 25 }, 0);
assert.equal(s.auction?.highBid, 25);
const bidder = s.auction?.activeBidder as number;
s.players[bidder]!.hand = [{ t: "research", v: 20 }];
assert.throws(() => applyMove(s, { action: "bid", amount: 26 }, bidder), /cannot afford/);
applyMove(s, { action: "bidPass" }, bidder);
while (s.phase === "auction") {
applyMove(s, { action: "bidPass" }, s.auction!.activeBidder);
}
assert.equal(s.phase, "auctionPayment");
assert.throws(() => applyMove(s, { action: "pay", cards: [0] }, 0), /pay|enough|cover/i);
applyMove(s, { action: "pay", cards: [0, 1] }, 0);
const last = s.log.at(-1);
assert.equal(last?.type === "move" ? last.info?.paid : undefined, 40);
s.activeSeat = 3;
s.players[3]!.hand = [];
// Kicker list price remains the minimum bid despite the buyer's discount.
const kickerPrice = 15;
assert.throws(
() => applyMove(s, { action: "auction", kicker: true, marketIndex: 0, bid: kickerPrice - 1 }, 3),
/at least/
);
});
test("public bounds and auto-pass account for signed Kicker adjustment", () => {
const s = game();
s.players[0]!.hand = [{ t: "ore", v: 5 }];
s.players[3]!.hand = [{ t: "ore", v: 5 }];
assert.equal(maxBid(s, 0, undefined, "smelter"), -5);
assert.equal(maxBid(s, 3, undefined, "smelter"), 15);
s.auction = {
marketIndex: 0,
kicker: "smelter",
auctioneer: 1,
highBid: 12,
highBidder: 1,
activeBidder: 0,
passed: [],
};
assert.equal(mustAutoPassBid(s, 0), true);
assert.equal(mustAutoPassBid(s, 3), false);
});
test("sealed auctions apply rank to bids and second-price payment; AI uses it", () => {
const s = game(4, true);
s.activeSeat = 0;
s.players[0]!.hand = [{ t: "research", v: 30 }];
assert.throws(() => applyMove(s, { action: "auction", marketIndex: 1, bid: 25 }, 0), /cannot afford/);
s.players[0]!.hand.push({ t: "research", v: 10 });
applyMove(s, { action: "auction", marketIndex: 1, bid: 25 }, 0);
assert.equal(chooseMove(s, 3).action, "bid");
applyMove(s, { action: "bid", amount: 60 }, 3);
for (const seat of [1, 2]) {
applyMove(s, { action: "bidPass" }, seat);
}
assert.equal(s.auction?.highBidder, 3);
assert.equal(s.auction?.highBid, 26);
assert.equal(chooseMove(s, 3).action, "pay");
assert.deepEqual(chooseMove(s, 3), { action: "pay", cards: [0] });
applyMove(s, { action: "pay", cards: [0] }, 3);
const last = s.log.at(-1);
assert.equal(last?.type === "move" ? last.info?.paid : undefined, 30);
});
test("discounts can offset surcharges and payment never goes below zero", () => {
const s = game();
s.activeSeat = 0;
s.players[0]!.upgrades.dataLibrary = 5;
s.players[0]!.hand = [];
assert.equal(auctionDiscount(s, 0, { upgrade: "scientists" }), 40);
applyMove(s, { action: "auction", marketIndex: 0, bid: 40 }, 0);
while (s.phase === "auction") {
applyMove(s, { action: "bidPass" }, s.auction!.activeBidder);
}
applyMove(s, { action: "pay", cards: [] }, 0);
assert.equal(s.players[0]!.upgrades.scientists, 1);
});
test("Kicker auction uses signed pricing for both open and sealed modes", () => {
for (const fastBid of [false, true]) {
const s = game(4, fastBid);
s.activeSeat = 0;
s.players[0]!.hand = [{ t: "research", v: 20 }];
assert.throws(() => applyMove(s, { action: "auction", kicker: true, marketIndex: 0, bid: 15 }, 0), /cannot afford/);
s.players[0]!.hand.push({ t: "research", v: 10 });
applyMove(s, { action: "auction", kicker: true, marketIndex: 0, bid: 15 }, 0);
if (fastBid) {
for (const seat of [1, 2, 3]) {
applyMove(s, { action: "bidPass" }, seat);
}
} else {
while (s.phase === "auction") {
applyMove(s, { action: "bidPass" }, s.auction!.activeBidder);
}
}
assert.equal(s.auction?.highBid, 15);
assert.deepEqual(chooseMove(s, 0), { action: "pay", cards: [0, 1] });
applyMove(s, { action: "pay", cards: [0, 1] }, 0);
assert.equal(s.players[0]!.kickers.smelter, 1);
}
});
test("sealed auto-pass uses public bounds after a rank surcharge", () => {
const s = game(4, true);
s.activeSeat = 3;
s.players[0]!.hand = [{ t: "ore", v: 5 }];
s.players[1]!.hand = [{ t: "ore", v: 5 }];
applyMove(s, { action: "auction", kicker: true, marketIndex: 0, bid: 15 }, 3);
assert.equal(s.auction?.bids?.[0], 0);
assert.equal(s.auction?.bids?.[1], 0);
assert.equal(s.auction?.bids?.[2], undefined);
});

View file

@ -3,6 +3,7 @@ import { FACTORIES, KICKER_SPECS, MEGA_CARDS, ROBOT_COST, UPGRADE_SPECS, VICTORY
import { colonyEra, refillKickers, refillMarket, updateEraStreaks } from "./market.js";
import { dealStartingHand, producePlayer } from "./production.js";
import {
auctionDiscount,
canBuyFactory,
computePurchaseOrder,
countingHandSize,
@ -21,7 +22,6 @@ import {
operators,
scores,
setup,
upgradeDiscount,
} from "./state.js";
import { sanitizeMove } from "./sanitize.js";
import type {
@ -580,8 +580,8 @@ function moveAuction(
if (!replayMode && (!Number.isInteger(bid) || bid < price)) {
err(`opening bid must be at least ${price}`);
}
// Kicker cards have no discounts; upgrades use the buyer's discount.
const discount = upgrade ? upgradeDiscount(player, upgrade) : 0;
// The list bid reserve is unchanged; adjust only the buyer's payment.
const discount = auctionDiscount(state, seat, { upgrade, kicker });
if (!replayMode && handValue(player) < Math.max(0, bid - discount)) {
err(`cannot afford a bid of ${bid} (needs ${Math.max(0, bid - discount)}, holds ${handValue(player)})`);
}
@ -617,27 +617,23 @@ function moveAuction(
return autoPassed.length > 0 ? { ...info, autoPassed } : info;
}
function assertCanPayBid(player: PlayerState, upgrade: Upgrade, bid: number): void {
if (replayMode) {
return;
}
const due = Math.max(0, bid - upgradeDiscount(player, upgrade));
if (handValue(player) < due) {
err(`cannot afford a bid of ${bid} (needs ${due}, holds ${handValue(player)})`);
}
}
/** The log info identifying the card under auction (a colony upgrade or a Kicker card). */
function auctionInfo(auction: NonNullable<GameState["auction"]>): MoveInfo {
return auction.kicker ? { kicker: auction.kicker } : { upgrade: auction.upgrade };
}
/** Kicker-aware affordability check for a bid on the card under auction. */
function assertCanPayBidFor(player: PlayerState, auction: NonNullable<GameState["auction"]>, bid: number): void {
function assertCanPayBidFor(
state: GameState,
seat: number,
auction: NonNullable<GameState["auction"]>,
bid: number
): void {
const player = state.players[seat] as PlayerState;
if (replayMode) {
return;
}
const discount = auction.upgrade ? upgradeDiscount(player, auction.upgrade) : 0;
const discount = auctionDiscount(state, seat, auction);
const due = Math.max(0, bid - discount);
if (handValue(player) < due) {
err(`cannot afford a bid of ${bid} (needs ${due}, holds ${handValue(player)})`);
@ -650,8 +646,8 @@ function auctionPrice(auction: NonNullable<GameState["auction"]>): number {
}
/** The winner's discount on the card under auction (Kicker cards have none). */
function auctionDue(state: GameState, auction: NonNullable<GameState["auction"]>, player: PlayerState): number {
const discount = auction.upgrade ? upgradeDiscount(player, auction.upgrade) : 0;
function auctionDue(state: GameState, auction: NonNullable<GameState["auction"]>, seat: number): number {
const discount = auctionDiscount(state, seat, auction);
return Math.max(0, auction.highBid - discount);
}
@ -717,7 +713,7 @@ function moveBid(state: GameState, move: Move & { action: "bid" }, seat: number,
if (!Number.isInteger(move.amount) || move.amount <= auction.highBid) {
err(`bid must be higher than ${auction.highBid}`);
}
assertCanPayBidFor(player, auction, move.amount);
assertCanPayBidFor(state, seat, auction, move.amount);
auction.highBid = move.amount;
auction.highBidder = seat;
const autoPassed: number[] = [];
@ -764,11 +760,11 @@ function fastAutoPass(state: GameState, auction: NonNullable<GameState["auction"
if (p.dropped || bids[seat] !== undefined) {
return [];
}
if (publicMaxBid(state, seat, auction.upgrade) < price) {
if (publicMaxBid(state, seat, auction.upgrade, auction.kicker) < price) {
return [seat];
}
// Optional chain: states saved before the settings field existed lack it.
if (p.settings?.autoPassBids === true && maxBid(state, seat, auction.upgrade) < price) {
if (p.settings?.autoPassBids === true && maxBid(state, seat, auction.upgrade, auction.kicker) < price) {
return [seat];
}
return [];
@ -810,7 +806,7 @@ function moveFastBid(
if (!Number.isInteger(move.amount) || move.amount < minimum) {
err(`bid must be at least ${minimum}`);
}
assertCanPayBidFor(player, auction, move.amount);
assertCanPayBidFor(state, seat, auction, move.amount);
}
bids[seat] = move.amount;
if (seat === auction.auctioneer) {
@ -878,7 +874,7 @@ function movePay(state: GameState, move: Move & { action: "pay" }, seat: number,
if (state.phase !== "auctionPayment" || !auction || auction.highBidder !== seat) {
err("no payment expected from this player");
}
const due = auctionDue(state, auction, player);
const due = auctionDue(state, auction, seat);
const indices = sanitizeIndices(move.cards, player.hand.length, "pay");
const paid = spendCards(state, player, indices, due);

View file

@ -443,9 +443,49 @@ export function auctionCard(auction: { upgrade?: Upgrade; kicker?: Kicker }): {
return { name: spec.name, price: spec.price, upgrade: auction.upgrade };
}
/** Discount a buyer gets on the card under auction (Kicker cards have none). */
export function auctionDiscount(player: PlayerState, auction: { upgrade?: Upgrade; kicker?: Kicker }): number {
return auction.upgrade ? upgradeDiscount(player, auction.upgrade) : 0;
/** Signed pricing adjustment: positive is a discount, negative a surcharge.
* Rank by live VP at each bid or payment (so a purchase can change later
* auctions in the same round) among active players only. Tied VP is broken by seat
* number (ascending), independent of spent or purchase order; ranks are unique.
* The current round's era is fixed at the colony ship's arrival.
*/
export function rankAdjustment(state: GameState, seat: number): number {
if (state.options.catchUp !== true || (state.era ?? 1) < 2 || state.players[seat]?.dropped) {
return 0;
}
const active = state.players.map((p, i) => ({ p, i })).filter(({ p }) => !p.dropped);
if (active.length < 4) {
return 0;
}
active.sort((a, b) => victoryPoints(b.p) - victoryPoints(a.p) || a.i - b.i);
const rank = active.findIndex(({ i }) => i === seat);
const unit = state.era === 3 ? 10 : 5;
if (rank === 0) {
return -2 * unit;
}
if (rank === 1) {
return -unit;
}
if (rank === active.length - 1) {
return 2 * unit;
}
if (rank === active.length - 2) {
return unit;
}
return 0;
}
/** Total signed discount on an auctioned card, including rank adjustment. */
export function auctionDiscount(
state: GameState,
seat: number,
auction: { upgrade?: Upgrade; kicker?: Kicker }
): number {
const player = state.players[seat];
if (!player) {
return 0;
}
return (auction.upgrade ? upgradeDiscount(player, auction.upgrade) : 0) + rankAdjustment(state, seat);
}
/** Resource types a Wily Trader owner may offer in an exchange. */
@ -569,13 +609,13 @@ export function drawCard(state: GameState, resource: Resource): number {
return state.decks[resource].pop() as number;
}
/** Max a player could pay for a card right now: hand value plus their discount on it (none for Kicker cards). */
export function maxBid(state: GameState, seat: number, upgrade?: Upgrade): number {
/** Highest affordable pre-adjustment bid: hand value plus the signed auction discount. */
export function maxBid(state: GameState, seat: number, upgrade?: Upgrade, kicker?: Kicker): number {
const player = state.players[seat];
if (!player) {
return 0;
}
return handValue(player) + (upgrade ? upgradeDiscount(player, upgrade) : 0);
return handValue(player) + auctionDiscount(state, seat, { upgrade, kicker });
}
/**
@ -585,7 +625,7 @@ export function maxBid(state: GameState, seat: number, upgrade?: Upgrade): numbe
* any hand they can see. Computed the same way from a stripped log (v = -1) as
* from the live state, so replay is identical and it never leaks hand values.
*/
export function publicMaxBid(state: GameState, seat: number, upgrade?: Upgrade): number {
export function publicMaxBid(state: GameState, seat: number, upgrade?: Upgrade, kicker?: Kicker): number {
const player = state.players[seat];
if (!player) {
return 0;
@ -596,7 +636,7 @@ export function publicMaxBid(state: GameState, seat: number, upgrade?: Upgrade):
// deck max (Mega Titanium 44 vs deck max 13) — use it, not the deck max.
value += card.m ? card.v : MAX_CARD_VALUE[card.t];
}
return value + (upgrade ? upgradeDiscount(player, upgrade) : 0);
return value + auctionDiscount(state, seat, { upgrade, kicker });
}
/** True when every card in the player's hand is hidden (v = -1), i.e. a stripped state. */
@ -620,11 +660,13 @@ export function mustAutoPassBid(state: GameState, seat: number): boolean {
if (!player) {
return false;
}
if (publicMaxBid(state, seat, auction.upgrade) <= auction.highBid) {
if (publicMaxBid(state, seat, auction.upgrade, auction.kicker) <= auction.highBid) {
return true;
}
// Optional chain: states saved before the settings field existed lack it.
return player.settings?.autoPassBids === true && maxBid(state, seat, auction.upgrade) <= auction.highBid;
return (
player.settings?.autoPassBids === true && maxBid(state, seat, auction.upgrade, auction.kicker) <= auction.highBid
);
}
/** Coarse list of the moves available to a player, for the BGS sidebar. */

View file

@ -510,7 +510,11 @@ export function createAnalysisScenario(
observed.rngCounter = 0;
observed.log = [];
observed.messages = [];
observed.options = { fastBid: data.options.fastBid === true, kicker: data.options.kicker === true };
observed.options = {
fastBid: data.options.fastBid === true,
kicker: data.options.kicker === true,
catchUp: data.options.catchUp === true,
};
for (const p of observed.players) {
p.dropped = false;
p.settings = { autoPassBids: false };
@ -571,17 +575,17 @@ export function createAnalysisScenario(
}
const a = copy.auction;
if (a) {
if (knowledge.bidFloors.some((amount, seat) => amount > maxBid(copy, seat, a.upgrade))) {
if (knowledge.bidFloors.some((amount, seat) => amount > maxBid(copy, seat, a.upgrade, a.kicker))) {
continue;
}
if (a.bids && copy.phase === "auction") {
const floor = a.kicker ? KICKER_SPECS[a.kicker].price : UPGRADE_SPECS[a.upgrade!].price;
if (maxBid(copy, a.auctioneer, a.upgrade) < floor) {
if (maxBid(copy, a.auctioneer, a.upgrade, a.kicker) < floor) {
continue;
}
let valid = true;
for (const [seat, amount] of Object.entries(a.bids)) {
const max = maxBid(copy, Number(seat), a.upgrade);
const max = maxBid(copy, Number(seat), a.upgrade, a.kicker);
if (amount < 0) {
a.bids[seat] =
Number(seat) === a.auctioneer
@ -600,7 +604,7 @@ export function createAnalysisScenario(
continue;
}
a.highBid = a.bids[String(a.auctioneer)]!;
} else if (maxBid(copy, a.highBidder, a.upgrade) < a.highBid) {
} else if (maxBid(copy, a.highBidder, a.upgrade, a.kicker) < a.highBid) {
continue;
}
}

View file

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

View file

@ -9,6 +9,7 @@ const auto = params.get("auto") === "1" || params.get("auto") === "true";
const delayMs = params.get("delay") ? Number(params.get("delay")) : undefined;
const fastBid = params.get("fastBid") === "1" || params.get("fastBid") === "true";
const kicker = params.get("kicker") === "1" || params.get("kicker") === "true";
const catchUp = params.get("catchUp") === "1" || params.get("catchUp") === "true";
const gameOptions: Record<string, unknown> = {};
if (fastBid) {
gameOptions.fastBid = true;
@ -16,6 +17,9 @@ if (fastBid) {
if (kicker) {
gameOptions.kicker = true;
}
if (catchUp) {
gameOptions.catchUp = true;
}
const emitter = window.outpost.launch("#app");
mountSoundTests((sound) => emitter.emit("preferences", { sound }));

View file

@ -22,9 +22,7 @@
);
const nameOf = (seat: number) => state.players[seat]?.name ?? formatText("Player {p0}", [seat + 1], locale);
const meIndex = $derived(store.playerIndex);
const discount = $derived(
auction && auction.upgrade && meIndex !== undefined ? store.discountOf(meIndex, auction.upgrade) : 0
);
const discount = $derived(auction && meIndex !== undefined ? store.discountOf(meIndex, auction) : 0);
const due = $derived(store.auctionDue());
const fast = $derived(!!auction?.bids);
const minBid = $derived(store.minBid);
@ -128,9 +126,9 @@
>
</div>
</div>
{#if discount > 0}
{#if discount !== 0}
<div class="bid-cost">
<span>{`Discount ◈ ${discount}`}</span>
<span>{discount > 0 ? `Discount ◈ ${discount}` : `+ ◈ ${-discount}`}</span>
<span class="net-cost" translate="no" dir={locale === "fa" ? "rtl" : "ltr"}>
{formatText(
fast ? "Pay at most ◈ {p0}" : "Pay ◈ {p0}",
@ -168,7 +166,15 @@
{#if store.myPayment}
{formatText(
"You won: select hand cards worth at least ◈ {p0} and confirm below (bid {p1}{p2}).",
[due, auction.highBid, discount > 0 ? ` ${formatText("− {p0} discount", [discount], locale)}` : ""],
[
due,
auction.highBid,
discount > 0
? ` ${formatText("− {p0} discount", [discount], locale)}`
: discount < 0
? ` + ${-discount}`
: "",
],
locale
)}
{:else}

View file

@ -1,6 +1,6 @@
<script lang="ts">
import { tick, untrack } from "svelte";
import { describeLogEntry, sealedAuctionHistory, upgradeDiscount, type LogFormatter } from "outpost-engine";
import { auctionDiscount, describeLogEntry, sealedAuctionHistory, type LogFormatter } from "outpost-engine";
import { formatText, resolveLocale } from "../localization";
import type { ViewerStore } from "./store.svelte";
@ -28,7 +28,7 @@
) {
return null;
}
const discount = auction.upgrade ? upgradeDiscount(winner, auction.upgrade) : 0;
const discount = auctionDiscount(state, auction.highBidder, auction);
return { index, due: Math.max(0, auction.highBid - discount) };
});
const recent = $derived.by(() => {

View file

@ -59,7 +59,7 @@
if (meIndex === undefined) {
return UPGRADE_SPECS[upgrade].price;
}
return Math.max(0, UPGRADE_SPECS[upgrade].price - store.discountOf(meIndex, upgrade));
return Math.max(0, UPGRADE_SPECS[upgrade].price - store.discountOf(meIndex, { upgrade }));
}
</script>
@ -141,7 +141,7 @@
{@const spec = UPGRADE_SPECS[upgrade]}
{@const open = pick?.marketIndex === i && pick.kicker !== true}
{@const due = myDue(upgrade)}
{@const discount = store.playerIndex === undefined ? 0 : store.discountOf(store.playerIndex, upgrade)}
{@const discount = store.playerIndex === undefined ? 0 : store.discountOf(store.playerIndex, { upgrade })}
{@const blocked = store.turnBuys.length > 0}
<div class="slot" class:expanded={open}>
<button
@ -169,7 +169,7 @@
<span class="uvp">{spec.vp} VP</span>
<span class="uprice">
min ◈ {spec.price}
{#if due < spec.price}
{#if due !== spec.price}
· you pay ◈ {due}{/if}
</span>
<UpgradeBadges {upgrade} />
@ -181,7 +181,8 @@
<div class="bidbox">
<div class="payment-preview">
Bid ◈ {pick.bid}{#if discount > 0}
− discount ◈ {discount}{/if}<br /><strong translate="no" dir="auto"
− discount ◈ {discount}{:else if discount < 0}
+ ◈ {-discount}{/if}<br /><strong translate="no" dir="auto"
>{text(store.fastBid ? "Pay at most ◈ {p0}" : "Pay ◈ {p0}", [
Math.max(0, pick.bid - discount),
])}</strong
@ -237,6 +238,7 @@
<div class="cards">
{#each state.kickerMarket as kicker, i (i)}
{@const spec = KICKER_SPECS[kicker]}
{@const discount = meIndex === undefined ? 0 : store.discountOf(meIndex, { kicker })}
{@const open = pick?.marketIndex === i && pick.kicker === true}
{@const blocked = store.turnBuys.length > 0}
<div class="slot" class:expanded={open}>
@ -260,7 +262,10 @@
</span>
<span class="art"><ColonyArt card={kicker} /></span>
<span class="uvp">{spec.vp} VP</span>
<span class="uprice">min ◈ {spec.price}</span>
<span class="uprice"
>min ◈ {spec.price}{#if discount !== 0}
· you pay ◈ {Math.max(0, spec.price - discount)}{/if}</span
>
<span class="ueffect"><CardEffect locale={store.preferences.locale} tokens={KICKER_EFFECTS[kicker]} /></span
>
</button>
@ -268,7 +273,9 @@
<div class="bidbox">
<div class="payment-preview">
<strong translate="no" dir="auto"
>{text(store.fastBid ? "Pay at most ◈ {p0}" : "Pay ◈ {p0}", [pick.bid])}</strong
>{text(store.fastBid ? "Pay at most ◈ {p0}" : "Pay ◈ {p0}", [
Math.max(0, pick.bid - discount),
])}</strong
>
· you hold ◈ {store.myHandValue}
</div>

View file

@ -8,6 +8,7 @@ import {
applyMove,
applyTurnBuy,
auctionCard,
auctionDiscount,
bestDiscard,
bestPayment,
canBuyFactory,
@ -30,7 +31,6 @@ import {
replay as replayEngine,
robotMax,
scores,
upgradeDiscount,
type FactoryType,
type GameState,
type Kicker,
@ -736,7 +736,7 @@ export class ViewerStore {
if (!me || !auction) {
return 0;
}
return handValue(me) + (auction.upgrade ? upgradeDiscount(me, auction.upgrade) : 0);
return handValue(me) + auctionDiscount(this.liveState!, this.playerIndex!, auction);
}
/** Max opening bid for the staged auction pick (hand value + that card's discount; Kicker cards have none). */
@ -747,11 +747,10 @@ export class ViewerStore {
if (!me || !s || !pick) {
return 0;
}
if (pick.kicker) {
return handValue(me);
}
const upgrade = s.market[pick.marketIndex] as Upgrade;
return handValue(me) + upgradeDiscount(me, upgrade);
const card = pick.kicker
? { kicker: s.kickerMarket[pick.marketIndex] as Kicker }
: { upgrade: s.market[pick.marketIndex] as Upgrade };
return handValue(me) + auctionDiscount(s, this.playerIndex!, card);
}
get finalRankings(): number[] {
@ -789,9 +788,9 @@ export class ViewerStore {
return p ? robotMax(p) : 0;
}
discountOf(index: number, upgrade: Upgrade): number {
const p = this.state?.players[index];
return p ? upgradeDiscount(p, upgrade) : 0;
discountOf(index: number, card: { upgrade?: Upgrade; kicker?: Kicker }): number {
const state = this.liveState;
return state ? auctionDiscount(state, index, card) : 0;
}
auctionDue(): number {
@ -800,7 +799,7 @@ export class ViewerStore {
if (!me || !auction) {
return 0;
}
return Math.max(0, auction.highBid - (auction.upgrade ? upgradeDiscount(me, auction.upgrade) : 0));
return Math.max(0, auction.highBid - auctionDiscount(this.liveState!, this.playerIndex!, auction));
}
pickTotal(): number {

View file

@ -0,0 +1,71 @@
import assert from "node:assert/strict";
import { chromium } from "playwright";
import { initGame } from "../packages/engine/dist/index.js";
import { stripSecret } from "../packages/engine/dist/wrapper.js";
import { previewServer } from "./tutorial-preview.mjs";
const server = previewServer();
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
const browser = await chromium.launch({ executablePath: process.env.OUTPOST_CHROMIUM_EXECUTABLE });
try {
for (const width of [390, 1400]) {
const page = await browser.newPage({ viewport: { width, height: 950 } });
const errors = [];
page.on("pageerror", (error) => errors.push(error.message));
await page.setContent('<meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div>');
await page.addStyleTag({ path: "packages/viewer/dist/outpost-viewer.css" });
await page.addScriptTag({ url: `http://127.0.0.1:${server.address().port}/bundle.js` });
const state = initGame(4, { catchUp: true, kicker: true }, "catch-up-browser");
state.era = 2;
state.phase = "actions";
state.activeSeat = 0;
state.market = ["dataLibrary"];
state.kickerMarket = ["smelter"];
state.players[0].upgrades.outpost = 3;
state.players[1].upgrades.outpost = 2;
state.players[2].upgrades.outpost = 1;
state.players[0].hand = [{ t: "water", v: 20 }];
await page.evaluate(
(state) => {
window.emitter = outpost.launch("#app");
emitter.emit("player", { index: 0 });
emitter.emit("state", state);
},
stripSecret(state, 0)
);
const market = page.locator(".market");
await market.locator(".ucard").filter({ hasText: "Data Library" }).first().waitFor();
assert.match(
await market.locator(".ucard").filter({ hasText: "Data Library" }).first().innerText(),
/you pay ◈ 25/
);
assert.match(await market.locator(".kcard").filter({ hasText: "Smelter" }).first().innerText(), /you pay ◈ 25/);
await market.locator(".kcard").filter({ hasText: "Smelter" }).first().click();
assert.match(await market.locator(".payment-preview").innerText(), /Pay ◈ 25/);
assert.equal(await market.locator(".maxhint").innerText(), "max ◈ 10");
assert.equal(await market.locator(".confirm").isDisabled(), true);
await page.evaluate(() => emitter.emit("player", { index: 3 }));
assert.match(await market.locator(".ucard").filter({ hasText: "Data Library" }).first().innerText(), /you pay ◈ 5/);
assert.match(await market.locator(".kcard").filter({ hasText: "Smelter" }).first().innerText(), /you pay ◈ 5/);
await page.evaluate(() => emitter.emit("player", { index: 0 }));
state.phase = "auctionPayment";
state.auction = {
marketIndex: 0,
kicker: "smelter",
auctioneer: 0,
highBid: 15,
highBidder: 0,
passed: [1, 2, 3],
activeBidder: 0,
};
await page.evaluate((state) => emitter.emit("state", state), stripSecret(state, 0));
assert.match(await page.locator('[data-tutorial="auction"] .turn').innerText(), /at least ◈ 25/);
assert.match(await page.locator(".actionbar").innerText(), /at least ◈ 25/);
assert.deepEqual(errors, []);
await page.close();
}
console.log("Catch-up pricing in the market and auction payment matches the engine on mobile and desktop.");
} finally {
await browser.close();
await new Promise((resolve) => server.close(resolve));
}