game: v1.1 config hooks (default = v1): viral.base, encyclopedic.sides, cultureKeyword

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 23:37:27 -05:00
co-authored by Claude Opus 5.5
parent f8e13cec87
commit 407a56e2fa
6 changed files with 59 additions and 7 deletions
+11 -4
View File
@@ -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<string, Record<string, number>>;
trendUp: number;
trendDown: number;
@@ -106,11 +108,15 @@ export function trendFor(live: CardInput['live'], rules: Pick<DerivationRules, '
* §10.1: cost 1 → vanilla (+vanillaBonus); edition if enabled and the deck has another
* copy; else the faction keyword if enabled; else vanilla without the bonus.
*/
export function keywordFor(faction: Faction, cost: number, hasCopyInDeck: boolean, rules: Pick<DerivationRules, 'keywordsEnabled'>):
/** v1.1 option (critic, #3): Culture keyword by home stat when `cultureKeyword: 'home'`. */
export const CULTURE_HOME_KEYWORD: Record<Stat, string> = { attention: 'viral', depth: 'encyclopedic', reach: 'translated' };
export function keywordFor(faction: Faction, cost: number, hasCopyInDeck: boolean,
rules: Pick<DerivationRules, 'keywordsEnabled' | 'cultureKeyword'>, 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,
};
}
+4 -2
View File
@@ -115,7 +115,7 @@ export const KEYWORDS: Record<string, KeywordDef> = {
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<string, KeywordDef> = {
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)}`);
}
+2 -1
View File
@@ -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,
+2
View File
@@ -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;
+18
View File
@@ -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);
});
+22
View File
@@ -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');
});