diff --git a/docs/game/ENGINE_API.md b/docs/game/ENGINE_API.md index fae7253..c93dc90 100644 --- a/docs/game/ENGINE_API.md +++ b/docs/game/ENGINE_API.md @@ -47,10 +47,10 @@ const r = result(state); // { winner: 0 | 1 | null, reason, topicsLed, lanePow | `scoringPower(state, lane)` | Lane power plus revealed "at scoring" Portals (§7). `result().lanePower` uses this. | | `laneCapacity(state, lane)` | Per-seat capacity of a lane. A Portal such as Stub may override it. | | `isOnTopic(state, cardInPlay)` | §1.4/§6 on-topic test, including Disambiguation. | -| `starterDeck(seed): GameCard[]` | A random 12-card **placeholder** loaner deck (2 per cost from `STARTER_POOL`). Kept for tests and tools; it is not a §2.1 starter deck. | -| `STARTER_DECKS`, `starterDeckById(id, rules?): GameCard[]` | The 4 DESIGN §2.1 starter decks (`stargazers`, `field-guide`, `headliners`, `pioneers`): pinned loaners derived through `deriveCard`. | -| `previewPool(rules?): GameCard[]` | The 19 frozen `docs/game/starter-cards.json` loaners, derived via §1 against the card-sample percentile table. For loaner slots and draft modes. | -| `deriveCard(input, table, rules?)`, `deriveDeck(inputs, table, rules?)` | DESIGN §1 + §10.1 derivation (`shared/game/derive.ts`). | +| `STARTER_DECKS`, `starterDeckById(id, rules?)` | The 4 DESIGN §2.1 starter decks (`stargazers`, `field-guide`, `headliners`, `pioneers`), derived through `deriveCard` with the given rules (a `Ruleset` works). **Use these for new players.** | +| `starterDeck(seed)` | Older placeholder loaner deck (seeded, 2 per cost from `STARTER_POOL`). Kept for tests and tools; not a §2.1 starter deck. | +| `previewPool(rules?)` | The 20 frozen `docs/game/starter-cards.json` loaners (council-data), derived via §1 against the `card-sample-2026-11-16` percentile table. For loaner slots and draft modes. | +| `deriveCard(input, table, rules?)`, `deriveDeck(inputs, table, rules?)` | DESIGN §1 + §10.1: `CardInput` → `GameCard`. **Hosts only**: run on host-frozen, plausibility-checked inputs, never on client JSON. A `Ruleset` can be passed as `rules`. | | `placeCard(state, seat, lane, card)`, `revealPortal(state, lane)` | Test helpers for building boards by hand. | ## 2. Actions @@ -107,11 +107,13 @@ interface GameCard { - **The engine takes already-derived cards and never reads raw stats.** The council asked for this, because snapshot stats are self-reported (#1, critic brief A.1). - Derivation (DESIGN §1 and §10.1: percentile → fame → cost → power, home, trend, keyword and vanillaBonus) lives in `shared/game/derive.ts`, which engine-b owns. Hosts run it on host-frozen, plausibility-checked inputs before calling `createMatch`. +- `CardInput = { cardId, pageId | null, title, category, rarity, snapshot: { stats }, live: { trendPercent, dailyAverage }, check, pinned? }`. `pinned: { cost, home, faction }` replaces §1.1–1.5 **only** when `check === 'loaner'`. `check === 'unchecked'` caps cost at `uncheckedCostCap` (home and fame are kept). +- **Never build `GameCard`s from client JSON.** `validateDeck` only checks shapes and ranges; a client could send cost 1 / power 30. Constructed modes must re-derive on the host. +- Both seats can hold the same loaner `cardId`. The engine keys per seat, so UIs should key cards by `owner + cardId`. - Modes may adjust `GameCard` fields such as `power` before `createMatch`. The engine does not re-derive them. -- **Trust boundary for `CardInput`.** `check` and `pinned` are host decisions, not player input. `deriveCard` trusts them: - `check: 'loaner'` with `pinned` replaces §1.1–1.5, and `check: 'unchecked'` only caps cost. A host must build loaner inputs - **only** from shipped data (`STARTER_DECKS`, `previewPool()`, `LOANER_SNAPSHOTS`), never from client JSON, and must set - `check` for owned cards from its own §1.10 plausibility check. Otherwise a client could send `check: 'loaner', pinned: {cost: 1, …}` for any card. +- **`check` and `pinned` are host decisions, not player input.** Build loaner inputs only from shipped data (`STARTER_DECKS`, + `previewPool()`, `LOANER_SNAPSHOTS`), and set `check` for owned cards from the host's own §1.10 check. Otherwise a client could + send `check: 'loaner', pinned: {cost: 1, …}` for any card. - **`obscure` leaks in v1.** `viewFor` does not mask Obscure cards yet. Modes must not put `obscure` in `keywordsEnabled` until it does. - A keyword that isn't in `ruleset.keywordsEnabled` never runs. Derivation is responsible for not giving that card `vanillaBonus`. - Lane power = `power` + `bonus` + `trend` + `onTopicBonus[cost]` if on-topic + ongoing keyword and Portal effects, floored at 0. @@ -198,7 +200,7 @@ Scoring runs after the last turn's End phase. Lane powers include revealed "at s ## 8. Keywords and Portals (extension contract) -`KEYWORDS` and `PORTALS` in `shared/game/keywords.ts` (engine-b) are registries of hook objects. The header of that file is normative. Every hook gets `ctx = { state, rng, params, lane, log, power(card) }`. +`KEYWORDS` and `PORTALS` in `shared/game/keywords.ts` (engine-b) are registries of hook objects. v1 keywords (`V1_KEYWORDS`, one per faction via `FACTION_KEYWORD`): viral, rising, local, encyclopedic, nostalgic, translated; optional (`OPTIONAL_KEYWORDS`, off by default): edition, obscure, wildcard. Portals: the 6 kinds of §10.3. The header of that file is normative. Every hook gets `ctx = { state, rng, params, lane, log, power(card) }`. **Keywords** - `onReveal(ctx, self)` and `endOfTurn(ctx, self)` may change `bonus` on cards in `ctx.state`. @@ -227,4 +229,4 @@ Portal hooks act only once the Portal is revealed. - on-topic power, the consensus tie-break, and Portal capacity, fizzle and at-scoring hooks - disabled keywords, AFK and concede, and draws - the random-play property: matches terminate, replay exactly, and serialise after every action -- `tests/game-*.test.ts` (engine-b): keywords, card derivation, property tests and the DESIGN §12 golden match. +- `tests/game-keywords`, `game-derive`, `game-starter`, `game-property`, `game-golden` (engine-b): every keyword and Portal, derivation, starter decks, properties (termination, determinism, round-trip, no input mutation, legality, power ≥ 0, capacity, no hand leak) and the DESIGN §12 golden match (19–15 / 15–19 / 13–10, p0 wins).