Night 2 (2026-11-17), from the `claude/wikideck` fork's `night/2026-11-17` branch. It follows Night 1 (#22).
## What's in it
- **Duel engine** (fork #72, #80): 40-card decks of cards you own, Notability/Citations, keywords, effects T1–T12, Connected, a hidden-information-safe `viewFor`/`logFor`, and replay. Balance v1 tuning (#84) gives the first player about 51%.
- **Card profiles** (#70, #82): Figure, Location, Event, Institution or Doctrine, plus stats, keywords and rules text, all derived from real article data. Templates only.
- **Design and story** (#66, #69, #83): DUEL_DESIGN.md, plus the match log and the encyclopedic "Battle of X (2026)" recap.
- **PvP** (#74, #77, #81, #76, #85):
- The server checks ownership, and 40-card eligibility is enforced.
- Modes: Classic (ranked), Draft and Trending.
- Invites, quick match, Elo, a ladder and recap pages. Online matches render on the duel board.
- **Duel board UI** (#79): MTG-style card faces and combat declaration, built for 360 px first.
- **Polite Wikimedia client** (#73, #75): throttled, cached and identified requests, the mint-path fix, and a prefetch pool.
- **Android mining** (#78): native RandomX, as a sideload build. The emulator mined a testnet block.
- **Testnet ops** (#67, #68).
PR numbers refer to `claude/wikideck`.
## Status
- **Tests:** 423, of which 422 pass, 0 fail and 1 is skipped. The build is OK (`node:24-alpine`, `--network none`).
- **Testnet:** running this commit (036489c) on r350.
- **Untouched:** no changes to `server/testnet/consensus.ts`, `randomx.ts`, `native/` or the mainnet compose.
- **Review:** night-review reviewed fork #66–#79. #80–#85 came from the agents' unfinished branches and were not reviewed.
- **Known gaps:**
- The PvP end-to-end test hasn't been run (it needs two eom.dev accounts).
- Bot matches aren't reachable from Play.
- Card identity pre-bake hasn't been done.
- The RandomX verifier latch (`server/testnet/randomx.ts:140`) is still open.
This PR is for Eric to merge.
🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: #23
Co-authored-by: Claude <claude@eom.dev>
117 lines
6.3 KiB
TypeScript
117 lines
6.3 KiB
TypeScript
/**
|
||
* Effect templates by type and subtype (designer review §3.5; DUEL_DESIGN.md wins where they differ).
|
||
* Effects are plain data for duel-core's interpreter. k = ceil(cost / 2), 1–3, from the derived (fame) cost.
|
||
* Owner: duel-cards.
|
||
*/
|
||
import { definitionOf, type CardProfile, type CardType, type ChainHints } from './classify.ts';
|
||
import type { EffectSpec } from './types.ts';
|
||
|
||
export type { EffectOp, EffectSpec, EffectTrigger, TargetSpec as EffectTarget } from './types.ts';
|
||
|
||
type Subtypes = readonly (readonly [string, RegExp])[];
|
||
|
||
/**
|
||
* Subtype rules per type (DUEL_DESIGN §5), run over P31 labels, P279 labels, the description, then
|
||
* categories. First match in list order wins; no match is the type's default template.
|
||
* Additions beyond §5 (marked +): bands/associations count as organisations; 'flood' etc. as listed.
|
||
*/
|
||
export const SUBTYPE_RULES: Readonly<Record<CardType, Subtypes>> = {
|
||
Event: [
|
||
['conflict', /battle|war\b|siege|annexation|protest|riot|uprising|massacre|coup/],
|
||
['disaster', /storm|nor.easter|cyclone|hurricane|earthquake|flood|tornado|wildfire|eruption|famine|epidemic/],
|
||
['election', /election|referendum|straw poll/],
|
||
['sport', /match|final\b|season|tournament|championship|grand prix|\brace\b/],
|
||
],
|
||
Institution: [
|
||
['organisation', /company|organi[sz]ation|party|agency|studio|military|university|diocese|council|band\b|musical group|association|business|school|college|institute|manufacturer/],
|
||
['work', /film|album|song|\bbook|novel|series|video game|painting|software|typeface|newspaper|magazine/],
|
||
],
|
||
Doctrine: [
|
||
['pathology', /disease|clinical sign|pathogen|syndrome|disorder|toxin|poison/],
|
||
['language', /language|software|programming/],
|
||
['mathematics', /mathemat|theorem|algebra|geometr|polytope|polyhedron|equation|number theory|structure/],
|
||
['ideology', /ideology|religion|belief|doctrine|philosophy|theology/],
|
||
],
|
||
Figure: [],
|
||
Location: [],
|
||
};
|
||
|
||
/** Default template names, for the info panel (null subtype). */
|
||
export const DEFAULT_SUBTYPE: Readonly<Record<CardType, string | null>> = {
|
||
Figure: null, Location: null, Event: 'other', Institution: 'other', Doctrine: 'adopt',
|
||
};
|
||
|
||
export function subtypeFor(type: CardType, profile: Pick<CardProfile, 'instanceOf' | 'subclassOf' | 'description' | 'categories'>,
|
||
chain?: ChainHints): string | null {
|
||
const groups = [
|
||
[...profile.instanceOf.map(c => c.label), ...(profile.subclassOf ?? []).map(c => c.label)],
|
||
[profile.description ?? ''],
|
||
[...(profile.categories ?? []).filter(c => !/stubs$/i.test(c))],
|
||
// On-chain fallbacks, last: the extract's definitional phrase, then the title.
|
||
[definitionOf(chain?.extract), chain?.title ?? ''],
|
||
].map(g => g.map(t => t.toLowerCase()).filter(Boolean));
|
||
for (const texts of groups) for (const [name, rx] of SUBTYPE_RULES[type]) if (texts.some(t => rx.test(t))) return name;
|
||
return DEFAULT_SUBTYPE[type];
|
||
}
|
||
|
||
/** The effect list for a card (T1–T12). Figures and Locations have none beyond keywords and stats. */
|
||
/** DUEL_DESIGN §5 template id by type and subtype. */
|
||
export function templateFor(type: CardType, subtype: string | null): string | null {
|
||
switch (type) {
|
||
case 'Figure': return 'T1';
|
||
case 'Location': return 'T2';
|
||
case 'Event': return ({ conflict: 'T3', disaster: 'T4', election: 'T5', sport: 'T6' } as Record<string, string>)[subtype ?? ''] ?? 'T7';
|
||
case 'Institution': return subtype === 'organisation' ? 'T8' : subtype === 'work' ? 'T9' : 'T10';
|
||
case 'Doctrine': return subtype === 'pathology' ? 'T12' : 'T11';
|
||
}
|
||
}
|
||
|
||
export function effectsFor(type: CardType, subtype: string | null, cost: number): EffectSpec[] {
|
||
const template = templateFor(type, subtype);
|
||
return baseEffects(type, subtype, cost).map(e => (template ? { ...e, template } : e));
|
||
}
|
||
|
||
function baseEffects(type: CardType, subtype: string | null, cost: number): EffectSpec[] {
|
||
const k = Math.ceil(cost / 2);
|
||
switch (type) {
|
||
case 'Event':
|
||
switch (subtype) {
|
||
case 'conflict': return [{ trigger: 'onPlay', op: 'damage', target: 'figureOrLocation', amount: k + 1 }];
|
||
case 'disaster': return [{ trigger: 'onPlay', op: 'damageEach', target: 'each', amount: Math.max(1, k - 1) }];
|
||
case 'election': return [{ trigger: 'onPlay', op: 'createToken', amount: k,
|
||
token: { name: 'Elected Member', power: 1, toughness: 1, portal: 'Society' } }];
|
||
case 'sport': return [
|
||
{ trigger: 'onPlay', op: 'pump', target: 'ownFigure', power: k, toughness: 0, duration: 'turn' },
|
||
{ trigger: 'onPlay', op: 'fight', target: 'opponentFigure' },
|
||
];
|
||
default: return [{ trigger: 'onPlay', op: 'draw', amount: k }];
|
||
}
|
||
case 'Institution':
|
||
switch (subtype) {
|
||
case 'organisation': {
|
||
const token = { name: 'Staff Member', power: 1, toughness: 1, portal: 'Neutral' as const };
|
||
return cost >= 4
|
||
? [{ trigger: 'startOfTurn', op: 'createToken', amount: 1, token, condition: { maxTokens: 3 } }]
|
||
: [{ trigger: 'onEnter', op: 'createToken', amount: 1, token }];
|
||
}
|
||
case 'work': return [
|
||
{ trigger: 'onEnter', op: 'draw', amount: 1 },
|
||
{ trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 1, condition: { connected: true } },
|
||
];
|
||
default: return [{ trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 0, condition: { maxPower: 2 } }];
|
||
}
|
||
case 'Doctrine': {
|
||
// DUEL_API "Doctrine": `attach` picks the Figure; the buff is a static pump on `attached`.
|
||
const pathology = subtype === 'pathology';
|
||
const attach: EffectSpec = { trigger: 'onPlay', op: 'attach', target: pathology ? 'figure' : 'ownFigure' };
|
||
const buff: EffectSpec = { trigger: 'static', op: 'pump', target: 'attached', power: pathology ? -k : k, toughness: pathology ? -k : k };
|
||
if (pathology) return [attach, buff];
|
||
if (subtype === 'mathematics') return [attach, { ...buff, grant: ['Well-sourced'] }];
|
||
if (subtype === 'language') return [attach, buff, { trigger: 'onCombatDamageToPlayer', op: 'draw', amount: 1 }];
|
||
if (subtype === 'ideology') return [attach, buff, { trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 0, condition: { samePortal: true } }];
|
||
return [attach, buff];
|
||
}
|
||
default: return [];
|
||
}
|
||
}
|