Rich card descriptions + precise Kicker pile counts

- stripSecret now sorts the face-down Kicker piles into canonical order
  instead of placeholder-masking them. The draw order stays secret, but the
  per-type counts (public info: initial copies minus the public market and
  owned cards) are now visible. The Kicker supply bar shows each pending
  card with its count, like the colony-upgrade supply bar.
- New CardEffect component renders effect text with upgrade names as
  era-badged chips, resource names as resource-icon chips, and "N X
  factories" as manned-factory icons. Used in the market, the auction
  banner, and tooltips stay plain text.
- The market card era marker now sits inline after the title.
- Capitalized resource names in effect strings so they render as chips.

Engine 0.9.6.
This commit is contained in:
coyotte508 2026-08-29 20:26:07 +00:00
commit 415d245a3f
7 changed files with 244 additions and 45 deletions

View file

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

View file

@ -7,7 +7,7 @@ import { producePlayer } from "./production.js";
import { replay } from "./replay.js";
import { populationMax, robotMax, upgradeDiscount, victoryPoints } from "./state.js";
import { stripSecret } from "../wrapper.js";
import type { GameState, PlayerState, ProductionCard } from "./types.js";
import { KICKERS, type GameState, type PlayerState, type ProductionCard } from "./types.js";
function kickerGame(players = 4, seed = "kicker-spec"): GameState {
return initGame(players, { kicker: true }, seed);
@ -187,12 +187,21 @@ test("kicker: Smelter draws a bonus ore card per two ore factories", () => {
assert.equal(produced.filter((c) => c.t === "ore").length, 6);
});
test("kicker: the face-down piles are hidden by stripSecret, the slots stay public", () => {
test("kicker: the face-down piles are order-masked by stripSecret, the slots stay public", () => {
const state = kickerGame(4);
const stripped = stripSecret(state, 0);
// Pile contents are masked (same length, placeholder names).
assert.equal(stripped.kickerPiles[1].length, state.kickerPiles[1].length);
assert.deepEqual([...new Set(stripped.kickerPiles[1])], ["iceProspector"]);
// The pile's draw order is destroyed (sorted into canonical order) but its
// public multiset of contents is preserved.
for (const era of [1, 2, 3] as const) {
const sorted = [...state.kickerPiles[era]].sort();
assert.deepEqual([...stripped.kickerPiles[era]].sort(), sorted);
// Canonical (KICKERS-index) order, not the shuffled draw order.
const indexes = stripped.kickerPiles[era].map((k) => KICKERS.indexOf(k));
assert.deepEqual(
indexes,
[...indexes].sort((a, b) => a - b)
);
}
// The face-up slot card stays visible.
assert.deepEqual(stripped.kickerMarket, state.kickerMarket);
});

View file

@ -4,7 +4,17 @@ import { applyMove, dropPlayer as dropPlayerCore, initGame } from "./src/moves.j
import { rankings as computeRankings } from "./src/rankings.js";
import { replay as replayCore } from "./src/replay.js";
import { availableMoves, scores as computeScores } from "./src/state.js";
import type { GameState, LogEntry, Move, ProductionCard } from "./src/types.js";
import { KICKERS, type GameState, type Kicker, type LogEntry, type Move, type ProductionCard } from "./src/types.js";
/**
* The face-down Kicker piles' draw order is secret, but the multiset of their
* contents is public (initial copies minus the public market and owned cards).
* Sort each pile into canonical order so the counts are visible without
* leaking what comes next.
*/
function sortedPile(pile: Kicker[]): Kicker[] {
return [...pile].sort((a, b) => KICKERS.indexOf(a) - KICKERS.indexOf(b));
}
export async function init(
players: number,
@ -119,13 +129,13 @@ function hideProduced(
}
return {
...entry,
// The face-down Kicker piles' draw order is secret; only sizes are public.
// The face-down Kicker piles' draw order is secret; sort to show counts.
...(entry.kickerPiles
? {
kickerPiles: {
1: entry.kickerPiles[1].map(() => "iceProspector" as const),
2: entry.kickerPiles[2].map(() => "launchFacility" as const),
3: entry.kickerPiles[3].map(() => "biosphere" as const),
1: sortedPile(entry.kickerPiles[1]),
2: sortedPile(entry.kickerPiles[2]),
3: sortedPile(entry.kickerPiles[3]),
},
}
: {}),
@ -173,11 +183,12 @@ export function stripSecret(data: GameState, player?: number): GameState {
decks: Object.fromEntries(
Object.entries(data.decks).map(([resource, deck]) => [resource, deck.map(() => -1)])
) as GameState["decks"],
// The face-down Kicker piles' draw order is secret; only their sizes are public.
// The face-down Kicker piles' draw order is secret; their (public) counts
// are shown by sorting into canonical order.
kickerPiles: {
1: data.kickerPiles[1].map(() => "iceProspector" as const),
2: data.kickerPiles[2].map(() => "launchFacility" as const),
3: data.kickerPiles[3].map(() => "biosphere" as const),
1: sortedPile(data.kickerPiles[1]),
2: sortedPile(data.kickerPiles[2]),
3: sortedPile(data.kickerPiles[3]),
},
players: data.players.map((p, i) => {
if (i === viewer) {

View file

@ -1,6 +1,7 @@
<script lang="ts">
import { KICKER_SPECS, UPGRADE_SPECS, type GameState } from "outpost-engine";
import UpgradeBadges from "./UpgradeBadges.svelte";
import CardEffect from "./CardEffect.svelte";
import { KICKER_EFFECTS, UPGRADE_EFFECTS, type ViewerStore } from "./store.svelte";
interface Props {
@ -44,7 +45,7 @@
{#if auction.upgrade}
<UpgradeBadges upgrade={auction.upgrade} />
{/if}
<span class="ueffect">{effectText}</span>
<span class="ueffect"><CardEffect text={effectText} /></span>
</div>
<div class="status">
{#if fast && state.phase === "auction"}

View file

@ -0,0 +1,163 @@
<script lang="ts">
import { UPGRADE_SPECS, upgradeEra, type Resource, type Upgrade } from "outpost-engine";
import ResourceIcon from "./ResourceIcon.svelte";
import { RESOURCE_LABELS } from "./store.svelte";
interface Props {
text: string;
}
let { text }: Props = $props();
type Token =
| { kind: "text"; value: string }
| { kind: "upgrade"; upgrade: Upgrade }
| { kind: "resource"; resource: Resource }
| { kind: "factory"; resource: Resource; count: number; label: string };
const UPGRADE_NAMES = new Map<Upgrade, string>(
(Object.keys(UPGRADE_SPECS) as Upgrade[]).map((u) => [u, UPGRADE_SPECS[u].name])
);
const RESOURCE_NAMES = new Map<Resource, string>(
(Object.entries(RESOURCE_LABELS) as [Resource, string][]).map(([r, label]) => [r, label])
);
// Longest-first so "New Chemicals" / "Orbital Medicine" / "Ring Ore" / "Moon Ore"
// match before their single-word prefixes ("New", "Ring", "Moon", "Ore").
const NAMES: { label: string; token: Token }[] = [
...[...UPGRADE_NAMES.entries()].map(([upgrade, label]) => ({
label,
token: { kind: "upgrade", upgrade } as Token,
})),
...[...RESOURCE_NAMES.entries()].map(([resource, label]) => ({
label,
token: { kind: "resource", resource } as Token,
})),
].sort((a, b) => b.label.length - a.label.length);
// "2 ore factories" / "two Ore factories" → a factory token (manned-factory icons).
const RESOURCE_WORD = [...RESOURCE_NAMES.values()].join("|");
const FACTORY_RE = new RegExp(`^(\\d+)\\s+(${RESOURCE_WORD})\\s+factories`, "i");
function tokenize(value: string): Token[] {
const tokens: Token[] = [];
let rest = value;
while (rest.length > 0) {
const factory = FACTORY_RE.exec(rest);
if (factory) {
const word = (factory[2] as string).toLowerCase();
const resource = [...RESOURCE_NAMES.entries()].find(([, label]) => label.toLowerCase() === word)?.[0];
if (resource) {
tokens.push({ kind: "factory", resource, count: Number(factory[1]), label: factory[0] as string });
rest = rest.slice((factory[0] as string).length);
continue;
}
}
let matched = false;
for (const { label, token } of NAMES) {
if (rest.startsWith(label)) {
// Word boundary: the next character must not be a letter (so "Ore"
// doesn't match inside "Oreload"-like words, and "Robots" the upgrade
// isn't matched by a "Robot" prefix).
const next = rest[label.length];
if (next === undefined || !/[a-zA-Z]/.test(next)) {
tokens.push(token);
rest = rest.slice(label.length);
matched = true;
break;
}
}
}
if (!matched) {
// Accumulate plain text up to the next potential name start.
const last = tokens[tokens.length - 1];
if (last?.kind === "text") {
last.value += rest[0];
} else {
tokens.push({ kind: "text", value: rest[0] as string });
}
rest = rest.slice(1);
}
}
return tokens;
}
const tokens = $derived(tokenize(text));
</script>
{#each tokens as token, i (i)}
{#if token.kind === "upgrade"}
<span class="chip uchip era-{upgradeEra(token.upgrade)}">
<span class="chip-era">{["", "I", "II", "III"][upgradeEra(token.upgrade)]}</span>{UPGRADE_SPECS[token.upgrade]
.name}
</span>
{:else if token.kind === "resource"}
<span class="chip rchip res-{token.resource}">
<ResourceIcon resource={token.resource} size={11} />
{RESOURCE_LABELS[token.resource]}
</span>
{:else if token.kind === "factory"}
<span class="chip fchip res-{token.resource}" title={token.label}>
{token.count}
<span class="fdots">
{#each Array.from({ length: token.count }) as _, i (i)}
<span class="fdot"><ResourceIcon resource={token.resource} size={10} /></span>
{/each}
</span>
{RESOURCE_LABELS[token.resource]} factories
</span>
{:else}
{token.value}
{/if}
{/each}
<style>
.chip {
display: inline-flex;
align-items: center;
gap: 3px;
font-size: 0.92em;
font-weight: 700;
border-radius: 4px;
padding: 0 4px;
white-space: nowrap;
}
.chip-era {
font-size: 0.82em;
font-weight: 800;
}
.uchip.era-1 {
color: #5aa5e0;
background: color-mix(in srgb, #5aa5e0 14%, transparent);
}
.uchip.era-2 {
color: #f08c48;
background: color-mix(in srgb, #f08c48 14%, transparent);
}
.uchip.era-3 {
color: #b48ce8;
background: color-mix(in srgb, #b48ce8 14%, transparent);
}
.rchip {
color: var(--res);
background: color-mix(in srgb, var(--res) 14%, transparent);
}
.fchip {
color: var(--res);
background: color-mix(in srgb, var(--res) 14%, transparent);
}
.fdots {
display: inline-flex;
gap: 1px;
}
.fdot {
display: inline-flex;
align-items: center;
justify-content: center;
width: 14px;
height: 14px;
border-radius: 3px;
background: var(--res);
color: var(--res-text, #fff);
}
</style>

View file

@ -10,6 +10,7 @@
type Kicker,
} from "outpost-engine";
import UpgradeBadges from "./UpgradeBadges.svelte";
import CardEffect from "./CardEffect.svelte";
import { KICKER_EFFECTS, UPGRADE_EFFECTS, type ViewerStore } from "./store.svelte";
interface Props {
@ -22,12 +23,17 @@
const supplyLeft = $derived(UPGRADES.map((u) => ({ u, n: state.supply[u] })).filter((x) => x.n > 0));
const pick = $derived(store.auctionPick);
const meIndex = $derived(store.playerIndex);
// Remaining Kicker cards per era: the era's types (fixed, public) plus the
// face-down pile's size (the draw order is hidden, so only the total shows).
// Remaining Kicker cards per era: the pile is sorted (draw order hidden but
// the public counts preserved), so count copies of each type still in it.
const kickerSupply = $derived(
([1, 2, 3] as const)
.map((era) => ({ era, types: KICKERS_BY_ERA[era], left: state.kickerPiles[era].length }))
.filter((x) => x.left > 0 || x.era === state.kickerEra)
.map((era) => ({
era,
counts: KICKERS_BY_ERA[era]
.map((k) => ({ k, n: state.kickerPiles[era].filter((c) => c === k).length }))
.filter((x) => x.n > 0),
}))
.filter((x) => x.counts.length > 0 || x.era === state.kickerEra)
);
function myDue(upgrade: (typeof UPGRADES)[number]): number {
@ -62,20 +68,22 @@
: spec.name}
onclick={() => (open ? store.cancel() : store.openAuction(i))}
>
<span class="uname">{spec.name}</span>
<span class="uname">
{spec.name}
<span
class="uera era-{upgradeEra(upgrade)}"
title="Era {['', 'I', 'II', 'III'][upgradeEra(upgrade)]} upgrade (card #{upgradeNumber(upgrade)})"
>
{["", "I", "II", "III"][upgradeEra(upgrade)]}
</span>
</span>
<span class="uvp">{spec.vp} VP</span>
<span class="uprice">
min ◈ {spec.price}{#if due < spec.price}
· you pay ◈ {due}{/if}
</span>
<span
class="uera era-{upgradeEra(upgrade)}"
title="Era {['', 'I', 'II', 'III'][upgradeEra(upgrade)]} upgrade (card #{upgradeNumber(upgrade)})"
>
{["", "I", "II", "III"][upgradeEra(upgrade)]}
</span>
<UpgradeBadges {upgrade} />
<span class="ueffect">{UPGRADE_EFFECTS[upgrade]}</span>
<span class="ueffect"><CardEffect text={UPGRADE_EFFECTS[upgrade]} /></span>
</button>
{#if open && pick}
<div class="bidbox">
@ -129,7 +137,7 @@
<span class="uname">{spec.name}</span>
<span class="uvp">{spec.vp} VP</span>
<span class="uprice">min ◈ {spec.price}</span>
<span class="ueffect">{KICKER_EFFECTS[kicker]}</span>
<span class="ueffect"><CardEffect text={KICKER_EFFECTS[kicker]} /></span>
</button>
{#if open && pick}
<div class="bidbox">
@ -161,18 +169,24 @@
</div>
<div class="supply ksupply">
{#each kickerSupply as x (x.era)}
<span
class="stag era-{x.era}"
class:current={x.era === state.kickerEra}
title="Era {['', 'I', 'II', 'III'][x.era]} Kicker cards ({x.types
.map((k) => KICKER_SPECS[k].name)
.join(', ')}): {x.left} left in the face-down pile{x.era === state.kickerEra ? ' — current era' : ''}"
>
<span class="stag-era">{["", "I", "II", "III"][x.era]}</span>{x.types
.map((k) => KICKER_SPECS[k].name)
.join(", ")}
<span class="kcount">×{x.left}</span>
<span class="stag era-{x.era} ks-era" class:current={x.era === state.kickerEra}>
<span class="stag-era">{["", "I", "II", "III"][x.era]}</span>
</span>
{#each x.counts as c (c.k)}
{@const spec = KICKER_SPECS[c.k]}
<span
class="stag era-{x.era}"
class:current={x.era === state.kickerEra}
title="{spec.name} ({spec.vp} VP, list ◈ {spec.price}): {KICKER_EFFECTS[c.k]} ×{c.n} left in the Era {[
'',
'I',
'II',
'III',
][x.era]} pile{x.era === state.kickerEra ? ' (current era)' : ''}"
>
{spec.name}&nbsp;<span class="kcount">×{c.n}</span>
</span>
{/each}
{/each}
</div>
{/if}
@ -269,7 +283,8 @@
letter-spacing: 0.06em;
border-radius: 4px;
padding: 1px 5px;
align-self: flex-start;
margin-left: 5px;
vertical-align: 1px;
}
.uera.era-1 {
color: #5aa5e0;

View file

@ -83,12 +83,12 @@ function cardRange(resource: keyof typeof MIN_CARD_VALUE): string {
export const UPGRADE_EFFECTS: Record<Upgrade, string> = {
dataLibrary: "−10 on Scientists and Laboratory bids (per copy).",
warehouse: "+3 hand capacity (per copy).",
heavyEquipment: `Allows titanium factories (${cardRange("titanium")} cards). −5 on Warehouse/Nodule, −15 on Outpost (per copy).`,
heavyEquipment: `Allows Titanium factories (${cardRange("titanium")} cards). −5 on Warehouse/Nodule, −15 on Outpost (per copy).`,
nodule: "+3 population limit (per copy).",
scientists: `Produces a Research card (${cardRange("research")}) each round (per copy).`,
orbitalLab: `Produces a Microbiotics card (${cardRange("microbiotics")}) each round (per copy).`,
robots: "Allows buying robots, operators that ignore the population limit (per copy: up to population).",
laboratory: `Allows research factories (${cardRange("research")} cards); comes with a free one.`,
laboratory: `Allows Research factories (${cardRange("research")} cards); comes with a free one.`,
ecoplants: "Colonists cost 5 instead of 10. −10 on Outpost bids (per copy).",
outpost: "Free titanium factory, +5 hand capacity, +5 population limit.",
spaceStation: `Produces an Orbital Medicine card (${cardRange("orbitalMedicine")}) each round.`,
@ -101,12 +101,12 @@ export const KICKER_EFFECTS: Record<Kicker, string> = {
"When you draw Water cards in production, draw 1 extra Water card, then discard 1 of the Water cards just drawn.",
robotPrototype:
"Comes with a free robot you can operate even without a Robots upgrade (counts against your robot limit once you own one).",
smelter: "−5 on Robots upgrade bids. Draw 1 extra Ore card per 2 ore factories you operate.",
smelter: "−5 on Robots upgrade bids. Draw 1 extra Ore card per 2 Ore factories you operate.",
wilyTrader:
"Once per round, trade an Ore/Water/Titanium card to another player for their higher-valued card of the same type.",
launchFacility: "−30 on Space Station, Planetary Cruiser, and Moon Base bids.",
merchantHouse: "Like Wily Trader, but for Research, Microbiotics, and New Chemicals cards.",
ncfPrototype: "Comes with a free New Chemicals factory (no research card needed).",
ncfPrototype: "Comes with a free New Chemicals factory (no Research card needed).",
refinery:
"When you draw Titanium cards in production, draw 1 extra Titanium card, then discard 1 of the Titanium cards just drawn.",
biosphere: "+5 colony support (population) limit.",