Keep sealed-bid results in seat order

This commit is contained in:
coyotte508 2026-11-12 21:53:18 +00:00
commit cf54ffc039
4 changed files with 52 additions and 15 deletions

View file

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

View file

@ -50,7 +50,7 @@ test("sealed history stays private until completion, including passes and the op
{ player: last, amount: 30 },
{ player: opener, amount: 25 },
{ player: passer, amount: 0 },
],
].sort((a, b) => a.player - b.player),
});
}
});
@ -85,10 +85,13 @@ test("completed results keep every bid while descriptions show only the viewer's
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]
sealedAuctionHistory(visible.log).results.get(resultIndex)?.bids,
[
{ player: opener, amount: 25 },
{ player: winner, amount: 40 },
{ player: passer, amount: 0 },
{ player: last, amount: 30 },
].sort((a, b) => a.player - b.player)
);
assert.equal(sealedAuctionHistory(visible.log).results.get(resultIndex)?.paid, 40);
const slice = logSlice(state, { player: viewer, start: openingIndex + 1, end: openingIndex + 3 });
@ -138,18 +141,55 @@ test("an immediately resolved auction reveals the opener and every automatic pas
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 });
assert.deepEqual(
result?.bids,
state.players.map((_, player) => ({ player, amount: player === opener ? 25 : 0 }))
);
});
test("a pass can resolve the result; tied bids put the winner first", () => {
test("a pass can resolve the result; tied bids remain in seat order", () => {
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.winner, state.auction?.highBidder);
assert.deepEqual(
result.bids.map((bid) => bid.player),
[0, 1, 2, 3]
);
assert.equal(result.bids.find((bid) => bid.player === result.winner)?.amount, 40);
assert.equal(result.bids.find((bid) => bid.player === opener)?.amount, 25);
assert.equal(result.bids.find((bid) => bid.player === last)?.amount, 0);
});
test("sealed results use seat order regardless of submission order or bid amount", () => {
for (const submissions of [
[3, 1, 0],
[0, 3, 1],
[1, 0, 3],
]) {
const state = game();
state.purchaseOrder = [2, 3, 0, 1];
state.activeSeat = 2;
open(state);
for (const player of submissions) {
applyMove(
state,
player === 1 ? { action: "bidPass" } : { action: "bid", amount: player === 3 ? 40 : 30 },
player
);
}
const before = structuredClone(state.log);
const result = sealedAuctionHistory(stripSecret(state).log).results.get(state.log.length - 1)!;
assert.deepEqual(result.bids, [
{ player: 0, amount: 30 },
{ player: 1, amount: 0 },
{ player: 2, amount: 25 },
{ player: 3, amount: 40 },
]);
assert.equal(result.winner, 3);
assert.deepEqual(state.log, before);
}
});

View file

@ -50,10 +50,7 @@ export function sealedAuctionHistory(log: LogEntry[]): {
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
),
.sort((a, b) => a.player - b.player),
};
results.set(index, awaitingPayment);
pending = new Map();

View file

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