From 407a56e2fae154dc2cd6e99e425a45838e54369d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 23:37:27 -0500 Subject: [PATCH] game: v1.1 config hooks (default = v1): viral.base, encyclopedic.sides, cultureKeyword Co-Authored-By: Claude Opus 5.5 --- shared/game/derive.ts | 15 +++++++++++---- shared/game/keywords.ts | 6 ++++-- shared/game/ruleset.ts | 3 ++- shared/game/types.ts | 2 ++ tests/game-derive.test.ts | 18 ++++++++++++++++++ tests/game-keywords.test.ts | 22 ++++++++++++++++++++++ 6 files changed, 59 insertions(+), 7 deletions(-) diff --git a/shared/game/derive.ts b/shared/game/derive.ts index 6b5901b..19acc5d 100644 --- a/shared/game/derive.ts +++ b/shared/game/derive.ts @@ -35,6 +35,8 @@ export interface DerivationRules { powerByCost: readonly number[]; vanillaBonus: number; keywordsEnabled: readonly string[]; + /** v1.1 hook: 'home' gives Culture cards a home-stat keyword instead of viral (§10.1). Default 'faction' (v1). */ + cultureKeyword?: 'faction' | 'home'; keywordParams: Record>; trendUp: number; trendDown: number; @@ -106,11 +108,15 @@ export function trendFor(live: CardInput['live'], rules: Pick): +/** v1.1 option (critic, #3): Culture keyword by home stat when `cultureKeyword: 'home'`. */ +export const CULTURE_HOME_KEYWORD: Record = { attention: 'viral', depth: 'encyclopedic', reach: 'translated' }; + +export function keywordFor(faction: Faction, cost: number, hasCopyInDeck: boolean, + rules: Pick, home: Stat = 'attention'): { keyword: string | null; vanilla: boolean } { if (cost === 1) return { keyword: null, vanilla: true }; if (hasCopyInDeck && rules.keywordsEnabled.includes('edition')) return { keyword: 'edition', vanilla: false }; - const keyword = FACTION_KEYWORD[faction]; + const keyword = faction === 'Culture' && rules.cultureKeyword === 'home' ? CULTURE_HOME_KEYWORD[home] : FACTION_KEYWORD[faction]; return rules.keywordsEnabled.includes(keyword) ? { keyword, vanilla: false } : { keyword: null, vanilla: false }; } @@ -123,12 +129,13 @@ export function deriveCard(input: CardInput, table: PercentileTable, rules: Deri const faction = pinned ? pinned.faction : input.category; const base = rules.powerByCost[cost]; if (base === undefined) throw new RangeError(`powerByCost has no entry for cost ${cost}`); - const { keyword, vanilla } = keywordFor(faction, cost, hasCopyInDeck, rules); + const home = pinned ? pinned.home : homeStat(pct); + const { keyword, vanilla } = keywordFor(faction, cost, hasCopyInDeck, rules, home); const delta = keyword ? Math.max(-3, Math.min(0, rules.keywordParams[keyword]?.powerDelta ?? 0)) : 0; return { cardId: input.cardId, pageId: input.pageId, title: input.title, faction, rarity: pinned ? 'Common' : input.rarity, cost, power: Math.max(0, base + (vanilla ? rules.vanillaBonus : 0) + delta), - home: pinned ? pinned.home : homeStat(pct), trend: pinned ? 0 : trendFor(input.live, rules), keyword, + home, trend: pinned ? 0 : trendFor(input.live, rules), keyword, source: input.check === 'loaner' ? 'loaner' : 'owned', check: input.check, }; } diff --git a/shared/game/keywords.ts b/shared/game/keywords.ts index 4e3c1f6..3d5f732 100644 --- a/shared/game/keywords.ts +++ b/shared/game/keywords.ts @@ -115,7 +115,7 @@ export const KEYWORDS: Record = { let earlier = 0; for (const lane of ctx.state.lanes) for (const card of lane.cards[self.owner]) if (card !== self && card.turn === ctx.state.turn) earlier++; - const gain = Math.min(earlier * amount(ctx, 1), ctx.params.cap ?? 2); + const gain = Math.min((ctx.params.base ?? 0) + earlier * amount(ctx, 1), ctx.params.cap ?? 2); // base: v1.1 hook, 0 in v1 if (gain > 0) { self.bonus += gain; ctx.log(`${self.card.title}: Viral +${gain}`); } }, }, @@ -139,7 +139,9 @@ export const KEYWORDS: Record = { id: 'encyclopedic', name: 'Encyclopedic', text: '+{amount} power if there are no other cards here.', onReveal(ctx, self) { const [mine, theirs] = ctx.state.lanes[self.lane].cards; - if (mine.every(card => card === self) && theirs.length === 0) { + // sides: v1.1 hook. 2 (v1) = both sides must be empty; 1 = only your side. + const sides = ctx.params.sides ?? 2; + if (mine.every(card => card === self) && (sides === 1 || theirs.length === 0)) { self.bonus += amount(ctx, 2); ctx.log(`${self.card.title}: Encyclopedic +${amount(ctx, 2)}`); } diff --git a/shared/game/ruleset.ts b/shared/game/ruleset.ts index 8297ead..6975219 100644 --- a/shared/game/ruleset.ts +++ b/shared/game/ruleset.ts @@ -46,6 +46,7 @@ export const RulesetSchema = z.object({ vanillaBonus: int(0, 10), keywordsEnabled: z.array(z.enum(KEYWORD_IDS)).max(KEYWORD_IDS.length), ownedCards: z.boolean(), + cultureKeyword: z.enum(['faction', 'home']), trendUp: z.number().finite().min(-1000).max(1000), trendDown: z.number().finite().min(-1000).max(1000), trendMinDaily: z.number().finite().min(0).max(1e9), @@ -118,7 +119,7 @@ export const DEFAULT_RULESET: Ruleset = { costThresholds: [15, 35, 55, 75, 90], 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, + keywordsEnabled: ['viral', 'rising', 'local', 'encyclopedic', 'nostalgic', 'translated'], ownedCards: true, cultureKeyword: 'faction', trendUp: 25, trendDown: -200, trendMinDaily: 20, uncheckedCostCap: 4, factionSynergyCap: 3, verifyStats: true, diff --git a/shared/game/types.ts b/shared/game/types.ts index 1fe5994..97f4f6e 100644 --- a/shared/game/types.ts +++ b/shared/game/types.ts @@ -91,6 +91,8 @@ export interface Ruleset { /** Keyword ids whose hooks run. Cards with a disabled keyword are vanilla (derivation handles power). */ keywordsEnabled: string[]; ownedCards: boolean; + /** v1.1 hook (derive.ts): 'home' gives Culture cards a home-stat keyword. v1: 'faction'. */ + cultureKeyword: 'faction' | 'home'; trendUp: number; trendDown: number; trendMinDaily: number; diff --git a/tests/game-derive.test.ts b/tests/game-derive.test.ts index 8106149..5cd5be3 100644 --- a/tests/game-derive.test.ts +++ b/tests/game-derive.test.ts @@ -144,3 +144,21 @@ test('pinned values replace §1.1–1.5 for loaners only (§2.1)', () => { const cheap = deriveCard(input(stats, { check: 'loaner', pinned: { ...pinned, cost: 1 } }), TABLE); assert.deepEqual([cheap.power, cheap.keyword], [2, null], 'vanillaBonus still applies to pinned cost-1'); }); + +test('cultureKeyword (v1.1 hook): home gives Culture cards {attention: viral, depth: encyclopedic, reach: translated}', () => { + const home = { ...RULES, cultureKeyword: 'home' as const }; + const culture = (stats: CardInput['snapshot']['stats']) => input(stats, { category: 'Culture' }); + assert.equal(deriveCard(culture({ attention: 80, depth: 40, reach: 40 }), TABLE).keyword, 'viral', 'v1 default: faction'); + assert.equal(deriveCard(culture({ attention: 80, depth: 40, reach: 40 }), TABLE, home).keyword, 'viral'); + assert.equal(deriveCard(culture({ attention: 40, depth: 80, reach: 40 }), TABLE, home).keyword, 'encyclopedic'); + assert.equal(deriveCard(culture({ attention: 40, depth: 40, reach: 80 }), TABLE, home).keyword, 'translated'); + assert.equal(deriveCard(input({ attention: 40, depth: 40, reach: 80 }, { category: 'History' }), TABLE, home).keyword, 'nostalgic', 'other factions unchanged'); + assert.equal(deriveCard(culture({ attention: 5, depth: 5, reach: 5 }), TABLE, home).keyword, null, 'cost 1 still vanilla'); +}); + +test('a full Ruleset works as DerivationRules (hosts can derive with the mode rules)', async () => { + const { DEFAULT_RULESET } = await import('../shared/game/index.ts'); + const a = deriveCard(input({ attention: 81, depth: 71, reach: 61 }), TABLE, DEFAULT_RULESET); + const b = deriveCard(input({ attention: 81, depth: 71, reach: 61 }), TABLE); + assert.deepEqual(a, b); +}); diff --git a/tests/game-keywords.test.ts b/tests/game-keywords.test.ts index fcc28e0..b33259c 100644 --- a/tests/game-keywords.test.ts +++ b/tests/game-keywords.test.ts @@ -227,3 +227,25 @@ test('no keyword or Portal hook moves or removes cards (§10 v1 constraint)', () assert.deepEqual(count(), before, id); } }); + +// ---- v1.1 config hooks (default to v1) ---- +test('viral base (v1.1 hook): gain = min(base + earlier × amount, cap); base 0 by default', () => { + const s = board(); + assert.equal(reveal(s, 0, 1, card({ keyword: 'viral' })).bonus, 0, 'v1: nothing earlier, no gain'); + s.ruleset.keywordParams.viral = { amount: 1, cap: 3, base: 1 }; + const t = board(); t.ruleset.keywordParams.viral = { amount: 1, cap: 3, base: 1 }; + assert.equal(reveal(t, 0, 1, card({ keyword: 'viral' })).bonus, 1, 'base alone'); + place(t, 0, 0, card()); place(t, 0, 2, card()); place(t, 0, 2, card()); + assert.equal(reveal(t, 0, 0, card({ keyword: 'viral' })).bonus, 3, 'capped at 3'); +}); + +test('encyclopedic sides (v1.1 hook): 1 ignores the opponent side; default 2 is v1', () => { + const s = board(); + place(s, 1, 0, card()); + assert.equal(reveal(s, 0, 0, card({ keyword: 'encyclopedic' })).bonus, 0); + const t = board(); t.ruleset.keywordParams.encyclopedic = { amount: 2, sides: 1 }; + place(t, 1, 0, card()); + assert.equal(reveal(t, 0, 0, card({ keyword: 'encyclopedic' })).bonus, 2); + place(t, 0, 1, card()); + assert.equal(reveal(t, 0, 1, card({ keyword: 'encyclopedic' })).bonus, 0, 'own card still blocks'); +});