Merge pull request '[duel-cards] Align card profiles with the merged duel types (#61)' (#82) from night2/duel-cards/types-align-wip into night/2026-11-17

This commit is contained in:
2026-11-18 16:15:42 +00:00
5 changed files with 69 additions and 29 deletions
+3 -2
View File
@@ -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 }
+10 -6
View File
@@ -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<CoreDuelCard['rarity']>;
/** What derive() reads from the chain: a minted block's article and stats snapshot. */
export interface CardOnChain {
@@ -31,7 +31,8 @@ export interface CardOnChain {
statsSnapshot: Pick<MintStatsSnapshot, 'pageBytes' | 'languageCount' | 'stats'>;
}
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[];
@@ -44,7 +45,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;
@@ -236,6 +238,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]);
}
+2 -20
View File
@@ -4,27 +4,9 @@
* Owner: duel-cards.
*/
import { definitionOf, type CardProfile, type CardType, type ChainHints } 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])[];
+6 -1
View File
@@ -17,6 +17,7 @@ export const KEYWORD_REMINDER: Readonly<Record<Keyword, string>> = {
'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<Record<string, string>> = {
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'}`;
}
}
+48
View File
@@ -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}`);
});