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>
73 lines
4.2 KiB
TypeScript
73 lines
4.2 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import type { CardInstance, CardRef, DuelCard, LogEvent } from '../shared/duel/types.ts';
|
|
import { fromDuel } from '../shared/duel/story/fromDuel.ts';
|
|
import { recap, renderLog } from '../shared/duel/story/index.ts';
|
|
|
|
function duelCard(cardId: string, title: string, type: DuelCard['type'], cost: number, extra: Partial<DuelCard> = {}): DuelCard {
|
|
return {
|
|
cardId, pageId: 1, revisionId: 1000 + cost, title, description: `${title} description`, type, subtype: null,
|
|
portal: 'Society', cost, power: type === 'Figure' ? 2 : null, toughness: type === 'Figure' ? 2 : null,
|
|
keywords: [], effects: [], rulesText: '', flavor: '', ...extra,
|
|
};
|
|
}
|
|
const inst: CardInstance[] = [
|
|
{ uid: '0:0', owner: 0, card: duelCard('tokA', 'Pathrail Mosque', 'Location', 2) },
|
|
{ uid: '0:1', owner: 0, card: duelCard('tokB', 'Tom Ewell', 'Figure', 6) },
|
|
{ uid: '1:0', owner: 1, card: duelCard('tokC', '1954 Gold Coast general election', 'Event', 3) },
|
|
{ uid: '1:1', owner: 1, card: duelCard('tokD', "Pallas's cat", 'Figure', 6) },
|
|
];
|
|
const R = (i: CardInstance, p?: number, t?: number): CardRef =>
|
|
({ uid: i.uid, cardId: i.card.cardId, title: i.card.title, pageId: i.card.pageId, type: i.card.type, power: p, toughness: t });
|
|
const tok1: CardRef = { uid: 't:1', cardId: 'token:elected', title: 'Elected Member', pageId: null, type: 'Figure', power: 1, toughness: 1 };
|
|
const tok2: CardRef = { ...tok1, uid: 't:2' };
|
|
let seq = 0;
|
|
const E = (turn: number, e: Record<string, unknown>) => ({ seq: seq++, turn, ...e }) as LogEvent;
|
|
const log: LogEvent[] = [
|
|
E(0, { kind: 'start', firstSeat: 0 }),
|
|
E(1, { kind: 'turnStart', seat: 0, citations: 1, life: [20, 20] }),
|
|
E(1, { kind: 'deploy', seat: 0, card: R(inst[0], 0, 3) }),
|
|
E(2, { kind: 'turnStart', seat: 1, citations: 1, life: [20, 20] }),
|
|
E(2, { kind: 'draw', seat: 1 }),
|
|
E(2, { kind: 'cast', seat: 1, card: R(inst[2]), targets: [] }),
|
|
E(2, { kind: 'tokenCreated', seat: 1, card: tok1, source: R(inst[2]) }),
|
|
E(2, { kind: 'tokenCreated', seat: 1, card: tok2, source: R(inst[2]) }),
|
|
E(3, { kind: 'turnStart', seat: 0, citations: 2, life: [20, 20] }),
|
|
E(3, { kind: 'draw', seat: 0, card: R(inst[1]) }),
|
|
E(3, { kind: 'deploy', seat: 0, card: R(inst[1], 5, 5) }),
|
|
E(4, { kind: 'turnStart', seat: 1, citations: 2, life: [20, 20] }),
|
|
E(4, { kind: 'attack', seat: 1, attackers: [R(inst[3], 5, 5), tok1] }),
|
|
E(4, { kind: 'block', seat: 0, blocks: [{ blocker: R(inst[1], 5, 5), attacker: tok1 }] }),
|
|
E(4, { kind: 'combatDamage', source: tok1, target: R(inst[1]), amount: 1 }),
|
|
E(4, { kind: 'destroyed', card: tok1, owner: 1 }),
|
|
E(4, { kind: 'playerDamage', source: R(inst[3]), seat: 0, amount: 5, life: 15, combat: true }),
|
|
E(4, { kind: 'lifeGain', source: R(inst[3]), seat: 1, amount: 2, life: 22 }),
|
|
E(4, { kind: 'concede', seat: 0 }),
|
|
E(4, { kind: 'gameOver', winner: 1, reason: 'concede', life: [15, 22] }),
|
|
];
|
|
|
|
test('fromDuel maps duel-core LogEvents onto the story record', () => {
|
|
const rec = fromDuel({
|
|
matchId: 'm1', storySeed: 'story-seed', date: '2026-11-17',
|
|
players: [{ name: 'alice' }, { name: 'bob' }], instances: inst, log,
|
|
});
|
|
assert.deepEqual(rec.events.map(e => e.kind), [
|
|
'turnStart', 'deploy', 'turnStart', 'draw', 'cast', 'tokenCreated', 'turnStart', 'draw', 'deploy',
|
|
'turnStart', 'attack', 'attack', 'block', 'destroyed', 'playerDamage', 'lifeGain', 'gameOver',
|
|
]);
|
|
const tc = rec.events.find(e => e.kind === 'tokenCreated');
|
|
assert.deepEqual(tc, { kind: 'tokenCreated', seat: 1, source: '1:0', token: 'Elected Member', count: 2 });
|
|
assert.equal(rec.cards['t:1'].token, true);
|
|
assert.equal(rec.cards['0:1'].tokenId, 'tokB');
|
|
assert.equal(rec.seed, 'story-seed');
|
|
const over = rec.events[rec.events.length - 1];
|
|
assert.deepEqual(over, { kind: 'gameOver', winner: 1, reason: 'concede', turn: 4, life: [15, 22] });
|
|
|
|
const r = recap(rec);
|
|
assert.equal(r.title, 'Skirmish at Pathrail Mosque (2026)');
|
|
assert.equal(r.infobox.result, 'bob victory by withdrawal');
|
|
assert.ok(r.references.every(x => !x.title.includes('Elected Member')));
|
|
const forBob = renderLog(rec, 1).lines.map(l => l.text).join(' ');
|
|
assert.doesNotMatch(forBob, /Tom Ewell.*drawn|drew \*Tom Ewell/); // alice's draw is hidden from bob
|
|
});
|