From e0ac157ee1306324a79ce9601646fe2336337f57 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 23:14:51 -0500 Subject: [PATCH] Engine: trendDown -200 default; nullable loaner pageId counts copies per cardId (DESIGN #23/#24) Co-Authored-By: Claude Opus 5.5 --- docs/game/ENGINE_API.md | 2 +- shared/game/engine.ts | 13 ++++++++----- shared/game/ruleset.ts | 2 +- shared/game/types.ts | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/game/ENGINE_API.md b/docs/game/ENGINE_API.md index 55cb030..e4aedd7 100644 --- a/docs/game/ENGINE_API.md +++ b/docs/game/ENGINE_API.md @@ -89,7 +89,7 @@ type Action = ```ts interface GameCard { cardId: string; // unique within a deck: the NFT card hash, or `loaner::` - pageId: number; // at most ruleset.maxCopiesPerPage cards share a pageId + pageId: number | null; // at most maxCopiesPerPage cards share a pageId; null (unpinned loaners) → counted per cardId title: string; faction: 'Space' | 'Nature' | 'People' | 'Science' | 'History' | 'Culture'; rarity: 'Common' | 'Rare' | 'Epic' | 'Legendary'; // cosmetic in v1 diff --git a/shared/game/engine.ts b/shared/game/engine.ts index b5c7476..67d8616 100644 --- a/shared/game/engine.ts +++ b/shared/game/engine.ts @@ -29,14 +29,15 @@ export function validateDeck(rules: Ruleset, deck: readonly GameCard[]): string[ if (!Array.isArray(deck)) return ['Deck must be an array']; if (deck.length !== rules.deckSize) problems.push(`Deck must have exactly ${rules.deckSize} cards (has ${deck.length})`); const ids = new Set(); - const copies = new Map(); + const copies = new Map(); let loaners = 0; for (const card of deck) { if (typeof card?.cardId !== 'string' || !card.cardId || card.cardId.length > 128) { problems.push('cardId must be a non-empty string'); continue; } const label = card.cardId; if (ids.has(card.cardId)) problems.push(`Duplicate cardId ${label}`); ids.add(card.cardId); - if (!Number.isInteger(card.pageId)) problems.push(`${label}: bad pageId`); + if (card.pageId !== null && !Number.isInteger(card.pageId)) problems.push(`${label}: bad pageId`); + if (card.pageId === null && card.source !== 'loaner') problems.push(`${label}: owned cards need a pageId`); if (typeof card.title !== 'string' || card.title.length > 256) problems.push(`${label}: bad title`); if (!FACTION_SET.has(card.faction)) problems.push(`${label}: bad faction`); if (!RARITIES.has(card.rarity)) problems.push(`${label}: bad rarity`); @@ -49,9 +50,11 @@ export function validateDeck(rules: Ruleset, deck: readonly GameCard[]): string[ if (card.check !== undefined && !CHECKS.has(card.check)) problems.push(`${label}: bad check`); if (card.source === 'loaner') loaners++; if (card.source === 'owned' && !rules.ownedCards) problems.push(`${label}: owned cards are not allowed in this mode`); - const n = (copies.get(card.pageId) ?? 0) + 1; - copies.set(card.pageId, n); - if (n === rules.maxCopiesPerPage + 1) problems.push(`More than ${rules.maxCopiesPerPage} copies of page ${card.pageId}`); + // §2 / §2.1: owned and loaner copies count together by pageId; unpinned loaners (pageId null) by cardId. + const key = card.pageId !== null ? `page:${card.pageId}` : `card:${card.cardId}`; + const n = (copies.get(key) ?? 0) + 1; + copies.set(key, n); + if (n === rules.maxCopiesPerPage + 1) problems.push(`More than ${rules.maxCopiesPerPage} copies of ${card.pageId !== null ? `page ${card.pageId}` : card.cardId}`); } if (loaners > rules.maxLoaners) problems.push(`At most ${rules.maxLoaners} loaner cards`); return problems; diff --git a/shared/game/ruleset.ts b/shared/game/ruleset.ts index 4f5a57a..8297ead 100644 --- a/shared/game/ruleset.ts +++ b/shared/game/ruleset.ts @@ -119,7 +119,7 @@ export const DEFAULT_RULESET: Ruleset = { powerByCost: [0, 1, 2, 4, 6, 8, 10], onTopicBonus: [0, 1, 1, 2, 2, 3, 3], vanillaBonus: 1, keywordsEnabled: ['viral', 'rising', 'local', 'encyclopedic', 'nostalgic', 'translated'], ownedCards: true, - trendUp: 25, trendDown: -25, trendMinDaily: 20, uncheckedCostCap: 4, + trendUp: 25, trendDown: -200, trendMinDaily: 20, uncheckedCostCap: 4, factionSynergyCap: 3, verifyStats: true, percentiles: 'card-sample-2026-11-16', diff --git a/shared/game/types.ts b/shared/game/types.ts index 7096756..1fe5994 100644 --- a/shared/game/types.ts +++ b/shared/game/types.ts @@ -24,7 +24,8 @@ export type Rarity = 'Common' | 'Rare' | 'Epic' | 'Legendary'; export interface GameCard { /** Unique within one deck (the NFT card hash, or `loaner::`). */ cardId: string; - pageId: number; + /** null for unpinned loaners (DESIGN §2.1): copies then count per cardId. */ + pageId: number | null; title: string; faction: Faction; /** Cosmetic in v1 (§1.7). */