Era transitions take effect at the colony ship, fix the era display

Rules check for kicker eras (reported: 'era 2, kicker card is still era 1'):
per the rulebook, era transitions happen during Phase 2 (Replace Purchased
Colony Upgrade Cards) — when Era I ends, its remaining Kicker cards (slots +
pile) are boxed and the slots refill from Era II. A mid-round VP change does
not advance the era until the next colony ship. The engine already did this;
the bug was the DISPLAY: the header computed the era live from current VP,
so it showed Era II mid-round while the effective era (die, kickers) was
still I.

The state now carries the effective era, fixed at round begin and recorded
on round entries for replay; the header and the supply-bar highlights show
it. refillKickers also handles a double era jump (I -> III) by boxing both
ended eras. Engine 0.9.7.
This commit is contained in:
coyotte508 2026-08-30 15:47:09 +00:00
commit 5401bb6b5a
8 changed files with 60 additions and 13 deletions

View file

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

View file

@ -66,6 +66,32 @@ test("kicker: the era follows the game era (leader VP), discarding the ended era
assert.equal(KICKER_SPECS[state.kickerMarket[0]!].era, 2);
});
test("kicker: a mid-round era advance takes effect at the next colony ship, not immediately", () => {
const state = kickerGame(4);
assert.equal(state.era, 1);
assert.equal(state.kickerEra, 1);
const slotCard = state.kickerMarket[0]!;
assert.equal(KICKER_SPECS[slotCard].era, 1);
// Mid-round, the leader crosses the Era II threshold (e.g. wins an auction).
const leader = state.players[0] as PlayerState;
leader.upgrades.orbitalLab = 4;
assert.ok(victoryPoints(leader) >= 10);
// Rule: era transitions happen during Phase 2 (colony ship arrival). Until
// then the effective era and the Kicker slots are unchanged — the era I
// Kicker can still be bought this round.
assert.equal(state.era, 1);
assert.equal(state.kickerEra, 1);
assert.deepEqual(state.kickerMarket, [slotCard]);
// The next round's colony ship applies the transition.
beginRound(state);
assert.equal(state.era, 2);
assert.equal(state.kickerEra, 2);
assert.equal(state.kickerPiles[1].length, 0);
assert.ok(state.kickerMarket.every((k) => KICKER_SPECS[k].era === 2));
const entry = state.log[state.log.length - 1];
assert.ok(entry?.type === "round" && entry.era === 2 && entry.kickerEra === 2);
});
test("kicker: an era advance replays identically from a stripped log", () => {
const state = kickerGame(4);
// Cross the Era II threshold and start a new round so the round entry

View file

@ -96,10 +96,12 @@ export function refillMarket(state: GameState): void {
}
/**
* Kicker expansion: refill the Kicker slots from the current era's pile. The
* Kicker era follows the game era (leader VP), not the piles: when the era
* advances, leftover Kicker cards of the ended era — in the slots and in that
* era's pile — are returned to the box and the slots refill from the new era.
* Kicker expansion: refill the Kicker slots from the current era's pile. Era
* transitions take effect here, during Phase 2 (colony ship arrival) — rule:
* "When Era I ends, return any Era I Kicker cards still in Kicker slots and
* in the Era I pile to the game box", repeated per ended era, then the slots
* refill from the new era's pile. A mid-round VP change does NOT advance the
* era until the next colony ship.
*/
export function refillKickers(state: GameState): void {
if (state.options.kicker !== true) {
@ -107,9 +109,10 @@ export function refillKickers(state: GameState): void {
}
const era = colonyEra(state);
if (era > state.kickerEra) {
const ended = state.kickerEra;
state.kickerMarket = state.kickerMarket.filter((k) => KICKER_SPECS[k].era !== ended);
state.kickerPiles[ended] = [];
state.kickerMarket = state.kickerMarket.filter((k) => KICKER_SPECS[k].era >= era);
for (let ended = 1; ended < era; ended++) {
state.kickerPiles[ended as 1 | 2 | 3] = [];
}
state.kickerEra = era;
}
const { slots } = kickerSetup(state.players.filter((p) => !p.dropped).length);

View file

@ -1,5 +1,5 @@
import { FACTORIES, KICKER_SPECS, MEGA_CARDS, ROBOT_COST, UPGRADE_SPECS, VICTORY_VP } from "./data.js";
import { refillKickers, refillMarket, updateEraStreaks } from "./market.js";
import { colonyEra, refillKickers, refillMarket, updateEraStreaks } from "./market.js";
import { producePlayer } from "./production.js";
import {
canBuyFactory,
@ -86,8 +86,11 @@ export function beginRound(state: GameState): void {
state.round += 1;
state.purchaseOrder = computePurchaseOrder(state);
// The "very rare" era fallback is evaluated as the round begins, before the
// refill draws down the supply.
// refill draws down the supply. The era in effect for this round is fixed
// here, at the colony ship's arrival — mid-round VP changes wait for the
// next ship.
updateEraStreaks(state);
state.era = colonyEra(state);
refillMarket(state);
refillKickers(state);
@ -110,6 +113,7 @@ export function beginRound(state: GameState): void {
kickerPiles: { 1: [...state.kickerPiles[1]], 2: [...state.kickerPiles[2]], 3: [...state.kickerPiles[3]] },
eraStreak4: state.eraStreak4,
eraStreak10: state.eraStreak10,
era: state.era,
produced,
megaGroups,
});

View file

@ -76,6 +76,9 @@ function applyRoundEntry(state: GameState, entry: LogEntry & { type: "round" }):
if (entry.eraStreak10 !== undefined) {
state.eraStreak10 = entry.eraStreak10;
}
if (entry.era !== undefined) {
state.era = entry.era;
}
for (const { player: seat, cards } of entry.produced) {
const player = state.players[seat];
if (player) {

View file

@ -187,6 +187,8 @@ export type LogEntry =
/** Era-fallback streaks as this round began (for exact replay). */
eraStreak4?: number;
eraStreak10?: number;
/** The game era in effect this round (evaluated at the colony ship's arrival). */
era?: 1 | 2 | 3;
produced: { player: number; cards: ProductionCard[] }[];
/** Mega-eligible groups per player this round (rule 12.1), for exact replay. */
megaGroups?: { player: number; groups: Partial<Record<Resource, number>> }[];
@ -253,6 +255,12 @@ export interface GameState {
*/
eraStreak4?: number;
eraStreak10?: number;
/**
* The game era in effect (1-3). Era transitions happen during Phase 2, when
* the colony ship arrives: a mid-round VP change does not advance the era
* until the next round begins. Optional for pre-0.9.7 saved states.
*/
era?: 1 | 2 | 3;
/** Kicker expansion: Kicker cards currently in the Kicker slots. */
kickerMarket: Kicker[];
/** Kicker expansion: remaining Kicker piles by era (shuffled, face-down). */

View file

@ -7,7 +7,7 @@
let { state }: Props = $props();
const era = $derived(state.ended ? null : colonyEra(state));
const era = $derived(state.ended ? null : (state.era ?? colonyEra(state)));
const phaseLabel = $derived(
state.ended
@ -36,7 +36,10 @@
</span>
<span class="item">Round <strong>{state.round}</strong></span>
{#if era !== null}
<span class="item era" title="Game era (leader VP): sets which colony upgrades and Kicker cards are available">
<span
class="item era"
title="Game era: sets which colony upgrades and Kicker cards are available. Evaluated from the leader's VP when the colony ship arrives — a mid-round VP change counts at the next round"
>
Era {["", "I", "II", "III"][era]}
</span>
{/if}

View file

@ -23,7 +23,7 @@
const pick = $derived(store.auctionPick);
const meIndex = $derived(store.playerIndex);
const gameEra = $derived(colonyEra(state));
const gameEra = $derived(state.era ?? colonyEra(state));
// Remaining colony upgrades, grouped by era so each era gets a delimiter chip
// and the current era a highlight — same presentation as the Kicker supply.
const supplyByEra = $derived(