From 85efb929be5e905357501b2e05e064f47442355c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:53:35 -0500 Subject: [PATCH 1/2] [duel-cards] Use duel-core's types.ts: DuelCard/ConnectKeys extend the contract, EffectSpec/Keyword/Portal/CardType re-exported; Trending reminder; text for drain/destroy/bounce/tap; 'adopted Figure' Co-Authored-By: Claude Opus 5.5 --- shared/duel/classify.ts | 5 +++-- shared/duel/derive.ts | 16 ++++++++++------ shared/duel/effects.ts | 22 ++-------------------- shared/duel/text.ts | 7 ++++++- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/shared/duel/classify.ts b/shared/duel/classify.ts index 2f59bb7..52fce1f 100644 --- a/shared/duel/classify.ts +++ b/shared/duel/classify.ts @@ -6,8 +6,9 @@ * Owner: duel-cards. */ -export type CardType = 'Figure' | 'Location' | 'Event' | 'Institution' | 'Doctrine'; -export const CARD_TYPES: readonly CardType[] = ['Figure', 'Location', 'Event', 'Institution', 'Doctrine']; +import type { CardType } from './types.ts'; +export type { CardType } from './types.ts'; +export { CARD_TYPES } from './types.ts'; export interface WikidataClass { id: string; label: string } diff --git a/shared/duel/derive.ts b/shared/duel/derive.ts index 85956f1..2044f63 100644 --- a/shared/duel/derive.ts +++ b/shared/duel/derive.ts @@ -18,10 +18,10 @@ export type { EffectSpec } from './effects.ts'; export const DERIVE_VERSION = 'duel-derive-1'; -export type Portal = 'Arts' | 'Earth' | 'History' | 'Science' | 'Society' | 'Neutral'; -export const PORTALS: readonly Portal[] = ['Arts', 'Earth', 'History', 'Science', 'Society', 'Neutral']; -export type Keyword = 'Protected' | 'Featured' | 'Translated' | 'Legacy' | 'Stub' | 'Well-sourced' | 'Multilingual' | 'Local'; -export type Rarity = 'Common' | 'Rare' | 'Epic' | 'Legendary'; +import type { ConnectKeys as CoreConnectKeys, DuelCard as CoreDuelCard, Keyword, Portal } from './types.ts'; +export type { Keyword, Portal } from './types.ts'; +export { PORTALS } from './types.ts'; +export type Rarity = NonNullable; /** What derive() reads from the chain: a minted block's article and stats snapshot. */ export interface CardOnChain { @@ -30,7 +30,8 @@ export interface CardOnChain { statsSnapshot: Pick; } -export interface ConnectKeys { +/** duel-core's ConnectKeys, with `cites` always present. */ +export interface ConnectKeys extends CoreConnectKeys { /** P17/P27 values, or normalised country names from text when Wikidata has none. */ countries: string[]; centuries: number[]; @@ -43,7 +44,8 @@ export interface ConnectKeys { cites: string[]; } -export interface DuelCard { +/** duel-core's DuelCard (types.ts), with every field derive() always sets made required, plus audit fields. */ +export interface DuelCard extends CoreDuelCard { cardId: string; pageId: number; revisionId: number; @@ -235,6 +237,8 @@ export function triggeredKeywords(chain: CardOnChain, profile: CardProfile, p: P Translated: p.reach >= rules.translatedPct && p.reach < rules.multilingualPct, Stub: cats.some(c => c.toLowerCase().includes('stubs')) || chain.statsSnapshot.pageBytes < rules.stubBytes, Local: chain.statsSnapshot.stats.reach === 0, + // Granted by Trending mode from frozen live data, never by derivation. + Trending: false, }; return rules.keywordOrder.filter(k => on[k]); } diff --git a/shared/duel/effects.ts b/shared/duel/effects.ts index c433f6d..4f4f5be 100644 --- a/shared/duel/effects.ts +++ b/shared/duel/effects.ts @@ -4,27 +4,9 @@ * Owner: duel-cards. */ import type { CardProfile, CardType } from './classify.ts'; -import type { Keyword, Portal } from './derive.ts'; +import type { EffectSpec } from './types.ts'; -export type EffectTrigger = 'onPlay' | 'onEnter' | 'startOfTurn' | 'onDestroyed' | 'static' | 'onCombatDamageToPlayer'; -export type EffectOp = 'damage' | 'damageEach' | 'createToken' | 'pump' | 'fight' | 'draw' | 'attach' | 'gainLife'; -export type EffectTarget = 'figure' | 'figureOrLocation' | 'ownFigure' | 'opponentFigure' | 'each' | 'self' | 'attached' | 'ownFigures'; - -export interface EffectSpec { - trigger: EffectTrigger; - op: EffectOp; - target?: EffectTarget; - amount?: number; - power?: number; - toughness?: number; - duration?: 'turn' | 'permanent'; - token?: { name: string; power: number; toughness: number; portal: Portal }; - /** maxTokens: createToken only if the controller controls fewer than this many tokens (duel-core types.ts). */ - condition?: { maxPower?: number; samePortal?: boolean; connected?: boolean; maxTokens?: number }; - grant?: Keyword[]; - /** Template id (DUEL_DESIGN §5, T3–T12) for rules text and log wording. */ - template?: string; -} +export type { EffectOp, EffectSpec, EffectTrigger, TargetSpec as EffectTarget } from './types.ts'; type Subtypes = readonly (readonly [string, RegExp])[]; diff --git a/shared/duel/text.ts b/shared/duel/text.ts index 49bc556..ce44397 100644 --- a/shared/duel/text.ts +++ b/shared/duel/text.ts @@ -17,6 +17,7 @@ export const KEYWORD_REMINDER: Readonly> = { 'Well-sourced': 'Prevent the first 1 damage that would be dealt to this each turn.', Stub: 'At the start of your turn, put a +1/+1 counter on this, to a maximum of 2.', Local: 'Gets +1/+1 while you control a Compatriot Location.', + Trending: 'Can attack the turn it enters. Gets +1/+0.', }; const NUMBER_WORDS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six']; @@ -27,7 +28,7 @@ const pt = (p = 0, t = 0) => `${signed(p)}/${signed(t)}`; const TARGET_NOUN: Readonly> = { figure: 'target Figure', figureOrLocation: 'target Figure or Location', ownFigure: 'target Figure you control', opponentFigure: 'target Figure you don\'t control', each: 'each Figure and each Location', self: 'this', - attached: 'enchanted Figure', ownFigures: 'Figures you control', + attached: 'adopted Figure', ownFigures: 'Figures you control', }; function keywordsAsText(keywords: readonly Keyword[]): string { @@ -64,6 +65,10 @@ function actionText(e: EffectSpec): string { case 'draw': return e.amount === 1 ? 'draw a card' : `draw ${word(e.amount ?? 1)} cards`; case 'gainLife': return `you gain ${e.amount} Notability`; case 'attach': return ''; + case 'drain': return `each opponent loses ${e.amount} Notability and you gain ${e.amount} Notability`; + case 'destroy': return `destroy ${TARGET_NOUN[e.target ?? 'figure'] ?? 'target permanent'}`; + case 'bounce': return `return ${TARGET_NOUN[e.target ?? 'figure'] ?? 'target permanent'} to its owner's hand`; + case 'tap': return `tap ${TARGET_NOUN[e.target ?? 'figure'] ?? 'target permanent'}`; } } From 12d076b11e8b53213719a76459a1d94418bf886b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 23:23:03 -0500 Subject: [PATCH 2/2] [duel-cards] engine integration test (local, for after the engine merges) Co-Authored-By: Claude Opus 5.5 --- tests/duel-cards-engine.test.ts | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/duel-cards-engine.test.ts diff --git a/tests/duel-cards-engine.test.ts b/tests/duel-cards-engine.test.ts new file mode 100644 index 0000000..b1881db --- /dev/null +++ b/tests/duel-cards-engine.test.ts @@ -0,0 +1,48 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { createDuel, legalActions, applyAction, toAct, isOver, statsOf, DEFAULT_DUEL_RULESET } from '../shared/duel/index.ts'; +import { deriveSample, type SampleCard } from '../shared/duel/sample.ts'; +import { Rng } from '../shared/game/rng.ts'; +import type { DuelCard } from '../shared/duel/derive.ts'; + +const SAMPLE = (JSON.parse(readFileSync(new URL('../docs/game/card-sample.json', import.meta.url), 'utf8')) as { cards: SampleCard[] }).cards; +const CARDS = deriveSample(SAMPLE); + +function deck(rng: Rng, prefix: string): DuelCard[] { + const pool = [...CARDS]; + const out: DuelCard[] = []; + while (out.length < 40) out.push(pool.splice(rng.int(pool.length), 1)[0]); + return out.map(c => ({ ...c, cardId: `${prefix}:${c.cardId}` })); +} + +test('derived decks play to completion in the duel engine, and Doctrines change the adopted Figure', () => { + let adoptions = 0, checked = 0; + for (let g = 0; g < 40; g++) { + const rng = Rng.fromSeed(`duel-cards-engine-${g}`); + let state = createDuel(DEFAULT_DUEL_RULESET, [deck(rng, 'a'), deck(rng, 'b')], `seed-${g}`); + for (let steps = 0; !isOver(state) && steps < 3000; steps++) { + const seat = toAct(state)!; + const actions = legalActions(state, seat); + assert.ok(actions.length > 0); + const action = actions[rng.int(actions.length)]; + const prev = state; + state = applyAction(state, seat, action); + for (const ev of state.log.slice(prev.log.length)) { + if (ev.kind !== 'adopt') continue; + adoptions++; + const doctrine = state.battlefield.find(p => p.uid === ev.card.uid); + const figure = state.battlefield.find(p => p.uid === ev.to.uid); + if (!doctrine || !figure || !prev.battlefield.some(p => p.uid === figure.uid)) continue; + const buff = doctrine.card.effects.find(e => e.trigger === 'static' && e.target === 'attached')!; + const was = statsOf(prev, figure.uid), now = statsOf(state, figure.uid); + // Exactly the Doctrine's ±k, plus at most a Connected bonus (+1 or +2) between the two cards. + const dp = now.power - was.power - buff.power!, dt = now.toughness - was.toughness - buff.toughness!; + assert.ok(dp >= 0 && dp <= 2 && dt >= 0 && dt <= 2, `${doctrine.card.title} on ${figure.card.title}: ${JSON.stringify({ was, now, buff })}`); + checked++; + } + } + assert.ok(isOver(state), `game ${g} did not finish`); + } + assert.ok(adoptions > 0 && checked > 0, `adoptions ${adoptions}`); +});