forked from WikiDeck/wikideck
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: WikiDeck/wikideck#23
Co-authored-by: Claude <claude@eom.dev>
111 lines
6.9 KiB
TypeScript
111 lines
6.9 KiB
TypeScript
// Test-only deck builder for duel-core tests. NOT the real derivation (that is duel-cards'
|
|
// shared/duel/derive.ts): a crude, deterministic mapping from docs/game/card-sample.json
|
|
// so engine tests have 236 varied real cards. Zero network calls.
|
|
import { readFileSync } from 'node:fs';
|
|
import { Rng } from '../shared/game/rng.ts';
|
|
import type { CardType, DuelCard, EffectSpec, Keyword, Portal } from '../shared/duel/index.ts';
|
|
|
|
interface SampleCard {
|
|
pageId: number; title: string; description?: string; revisionId?: number; pageBytes: number; languageCount: number;
|
|
categories: string[]; stats: { attention: number; depth: number; reach: number }; faction: string;
|
|
instanceOf?: { id: string; label: string }[];
|
|
}
|
|
|
|
const sample = JSON.parse(readFileSync(new URL('../docs/game/card-sample.json', import.meta.url), 'utf8')) as { cards: SampleCard[] };
|
|
|
|
/** Effect templates shaped like DUEL_DESIGN §5 (k = magnitude). */
|
|
const EVENTS = (k: number): EffectSpec[][] => [
|
|
[{ trigger: 'onPlay', op: 'damage', target: 'figureOrLocation', amount: k + 1, template: 'T3' }],
|
|
[{ trigger: 'onPlay', op: 'damageEach', target: 'each', amount: Math.max(1, k - 1), template: 'T4' }],
|
|
[{ trigger: 'onPlay', op: 'createToken', amount: k, token: { name: 'Elected Member', power: 1, toughness: 1, portal: 'Society' }, template: 'T5' }],
|
|
[{ trigger: 'onPlay', op: 'pump', target: 'ownFigure', power: k, toughness: 0, template: 'T6' }, { trigger: 'onPlay', op: 'fight', target: 'opponentFigure', template: 'T6' }],
|
|
[{ trigger: 'onPlay', op: 'draw', amount: k, template: 'T7' }],
|
|
[{ trigger: 'onPlay', op: 'damage', target: 'anyTarget', amount: k, template: 'X1' }],
|
|
];
|
|
const INSTITUTIONS = (k: number, cost: number): EffectSpec[][] => [
|
|
cost >= 4
|
|
? [{ trigger: 'startOfTurn', op: 'createToken', token: { name: 'Staff Member', power: 1, toughness: 1, portal: 'Society' }, condition: { maxTokens: 3 }, template: 'T8' }]
|
|
: [{ trigger: 'onEnter', op: 'createToken', token: { name: 'Staff Member', power: 1, toughness: 1, portal: 'Society' }, template: 'T8' }],
|
|
[{ trigger: 'onEnter', op: 'draw', amount: 1, template: 'T9' }, { trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 1, condition: { connected: true }, template: 'T9' }],
|
|
[{ trigger: 'static', op: 'pump', target: 'ownFigures', power: 1, toughness: 0, condition: { maxPower: 2 }, template: 'T10' }],
|
|
];
|
|
const DOCTRINES = (k: number): EffectSpec[][] => [
|
|
[{ trigger: 'onPlay', op: 'attach', target: 'ownFigure', template: 'T11' }, { trigger: 'static', op: 'pump', target: 'attached', power: k, toughness: k, template: 'T11' }],
|
|
[{ trigger: 'onPlay', op: 'attach', target: 'ownFigure', template: 'T11' }, { trigger: 'static', op: 'pump', target: 'attached', power: k, toughness: k, grant: ['Well-sourced'], template: 'T11' }],
|
|
[{ trigger: 'onPlay', op: 'attach', target: 'ownFigure', template: 'T11' }, { trigger: 'static', op: 'pump', target: 'attached', power: k, toughness: k, template: 'T11' }, { trigger: 'onCombatDamageToPlayer', op: 'draw', amount: 1, template: 'T11' }],
|
|
[{ trigger: 'onPlay', op: 'attach', target: 'figure', template: 'T12' }, { trigger: 'static', op: 'pump', target: 'attached', power: -k, toughness: -k, template: 'T12' }],
|
|
];
|
|
|
|
const PORTAL: Record<string, Portal> = {
|
|
People: 'Society', Places: 'Earth', Nature: 'Earth', Structures: 'Arts', Works: 'Arts', Events: 'History', Organisations: 'Society',
|
|
'Ideas & Tech': 'Science', Sport: 'Society', Other: 'Neutral',
|
|
};
|
|
|
|
function typeOf(c: SampleCard, i: number): CardType {
|
|
if (c.instanceOf?.some(x => x.id === 'Q5') || c.faction === 'Nature') return 'Figure';
|
|
if (c.faction === 'Places' || c.faction === 'Structures') return i % 2 ? 'Location' : 'Figure';
|
|
if (c.faction === 'Events') return 'Event';
|
|
if (c.faction === 'Works' || c.faction === 'Organisations') return 'Institution';
|
|
return (['Event', 'Doctrine', 'Figure', 'Institution'] as CardType[])[i % 4];
|
|
}
|
|
|
|
const COUNTRIES = ['Q30', 'Q145', 'Q142', 'Q183', 'Q668', 'Q17', 'Q902', 'Q252'];
|
|
|
|
export function toDuelCard(c: SampleCard, i: number): DuelCard {
|
|
const type = typeOf(c, i);
|
|
const fame = Math.round((c.stats.attention + c.stats.depth + c.stats.reach) / 3);
|
|
const cost = 1 + [26, 39, 51, 63, 78].filter(t => fame >= t).length;
|
|
const k = Math.ceil(cost / 2);
|
|
const keywords: Keyword[] = [];
|
|
if (type === 'Figure') {
|
|
const add = (kw: Keyword, ok: boolean) => { if (ok && keywords.length < 2) keywords.push(kw); };
|
|
add('Protected', c.categories.includes('Living people'));
|
|
add('Featured', c.stats.attention >= 85);
|
|
add('Legacy', c.categories.some(x => /^\d+ deaths$/.test(x)));
|
|
add('Multilingual', c.stats.reach >= 90);
|
|
add('Translated', c.stats.reach >= 75 && c.stats.reach < 90);
|
|
add('Well-sourced', c.stats.depth >= 85);
|
|
add('Stub', c.pageBytes < 3000 || c.categories.some(x => /stubs$/.test(x)));
|
|
add('Local', c.stats.reach === 0);
|
|
}
|
|
const budget = [3, 4, 6, 8, 10, 12][cost - 1] - keywords.filter(x => x !== 'Stub' && x !== 'Translated' && x !== 'Local').length;
|
|
const a = c.stats.attention + 1, d = c.stats.depth + 1;
|
|
const power = type === 'Figure' ? Math.min(budget - 1, Math.max(1, Math.round(budget * a / (a + d)))) : 0;
|
|
const toughness = type === 'Figure' ? Math.max(1, budget - power) : type === 'Location' ? 1 + Math.floor(c.stats.depth / 25) : 0;
|
|
const effects: EffectSpec[] =
|
|
type === 'Event' ? EVENTS(k)[i % 6]
|
|
: type === 'Doctrine' ? DOCTRINES(k)[i % 4]
|
|
: type === 'Institution' ? INSTITUTIONS(k, cost)[i % 3]
|
|
: [];
|
|
return {
|
|
cardId: `sample-${c.pageId}`, pageId: c.pageId, revisionId: c.revisionId, title: c.title, description: c.description, type,
|
|
portal: PORTAL[c.faction] ?? 'Neutral', cost: type === 'Location' ? Math.ceil(cost / 2) : cost, power, toughness, keywords,
|
|
...(type === 'Location' ? { territory: 1 } : {}), effects, rulesText: '', flavor: '',
|
|
connect: {
|
|
countries: [COUNTRIES[c.pageId % COUNTRIES.length]].filter((_, j) => (c.pageId >> 3) % 3 !== 0 || j > 0),
|
|
centuries: [17 + (c.pageId % 5)],
|
|
links: [],
|
|
p31: (c.instanceOf ?? []).map(x => x.id),
|
|
},
|
|
};
|
|
}
|
|
|
|
export const POOL: DuelCard[] = sample.cards.map(toDuelCard);
|
|
|
|
// A few direct links so the Linked tier gets exercised.
|
|
for (let i = 0; i + 1 < POOL.length; i += 9) {
|
|
const b = POOL[i + 1];
|
|
if (b.pageId !== null) POOL[i].connect!.links.push(b.pageId);
|
|
}
|
|
|
|
/** `size` distinct pool cards; cardIds suffixed per seat so the two decks never share ids. */
|
|
export function randomDeck(seed: string, seat: 0 | 1, size = 40): DuelCard[] {
|
|
const rng = Rng.fromSeed(seed);
|
|
return rng.shuffle(POOL).slice(0, size).map(c => ({ ...structuredClone(c), cardId: `${c.cardId}#${seat}` }));
|
|
}
|
|
|
|
/** Minimal vanilla Figure for hand-built scenarios. */
|
|
export function fig(id: string, power: number, toughness: number, keywords: Keyword[] = [], extra: Partial<DuelCard> = {}): DuelCard {
|
|
return { cardId: id, pageId: null, title: id, type: 'Figure', portal: 'Society', cost: 1, power, toughness, keywords, effects: [], rulesText: '', flavor: '', ...extra };
|
|
}
|