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>
50 lines
2.7 KiB
TypeScript
50 lines
2.7 KiB
TypeScript
// 40-card sim decks drawn from a card pool (the 236 real sample cards). Every card is unique (one NFT each),
|
||
// so decks sample without replacement. Archetypes skew the type or cost mix. Pure, seeded.
|
||
import { mulberry32 } from '../../shared/bots/index.ts';
|
||
|
||
export interface PoolCard { id: string; type: string; portal: string; cost: number; keywords: string[]; fame?: number }
|
||
export interface SimDeck<C extends PoolCard = PoolCard> { id: string; tags: string[]; cards: C[] }
|
||
|
||
export const ARCHETYPES = ['random', 'figure-heavy', 'doctrine-heavy', 'event-heavy', 'location-heavy', 'institution-heavy', 'low-curve', 'high-curve'] as const;
|
||
export type Archetype = typeof ARCHETYPES[number];
|
||
|
||
function weight(c: PoolCard, arch: Archetype): number {
|
||
switch (arch) {
|
||
case 'figure-heavy': return c.type === 'Figure' ? 8 : 1;
|
||
case 'doctrine-heavy': return c.type === 'Doctrine' ? 8 : 1;
|
||
case 'event-heavy': return c.type === 'Event' ? 12 : 1;
|
||
case 'location-heavy': return c.type === 'Location' ? 8 : 1;
|
||
case 'institution-heavy': return c.type === 'Institution' ? 10 : 1;
|
||
case 'low-curve': return c.cost <= 2 ? 8 : c.cost === 3 ? 3 : 0.3;
|
||
case 'high-curve': return c.cost >= 5 ? 8 : c.cost === 4 ? 3 : 0.5;
|
||
default: return 1;
|
||
}
|
||
}
|
||
|
||
/** Weighted sampling without replacement (Efraimidis–Spirakis keys). */
|
||
export function buildDeck<C extends PoolCard>(pool: C[], arch: Archetype, seed: number, size = 40): SimDeck<C> {
|
||
const rng = mulberry32(seed);
|
||
const keyed = pool.map(c => ({ c, k: Math.pow(rng(), 1 / Math.max(1e-6, weight(c, arch))) }));
|
||
keyed.sort((a, b) => b.k - a.k);
|
||
const cards = keyed.slice(0, Math.min(size, pool.length)).map(x => x.c);
|
||
return { id: `${arch}#${seed}`, tags: deckTags(cards, arch), cards };
|
||
}
|
||
|
||
export function deckTags(cards: PoolCard[], arch: string): string[] {
|
||
const count = (f: (c: PoolCard) => string) => { const m: Record<string, number> = {}; for (const c of cards) m[f(c)] = (m[f(c)] ?? 0) + 1; return m; };
|
||
const top = (m: Record<string, number>) => Object.entries(m).sort((a, b) => b[1] - a[1])[0]?.[0] ?? '?';
|
||
const avg = cards.reduce((t, c) => t + c.cost, 0) / (cards.length || 1);
|
||
const curve = avg < 2.6 ? 'low' : avg < 3.4 ? 'mid' : 'high';
|
||
return [`arch:${arch}`, `portal:${top(count(c => c.portal))}`, `curve:${curve}`, `mainType:${top(count(c => c.type))}`];
|
||
}
|
||
|
||
/** n decks: half random, the rest cycling through the skewed archetypes. */
|
||
export function deckSet<C extends PoolCard>(pool: C[], n: number, seed: number, size = 40): SimDeck<C>[] {
|
||
const out: SimDeck<C>[] = [];
|
||
for (let i = 0; i < n; i++) {
|
||
const arch: Archetype = i % 2 === 0 ? 'random' : ARCHETYPES[1 + ((i >> 1) % (ARCHETYPES.length - 1))];
|
||
out.push(buildDeck(pool, arch, (seed * 7919 + i * 104729) >>> 0, size));
|
||
}
|
||
return out;
|
||
}
|