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>
77 lines
4.3 KiB
TypeScript
77 lines
4.3 KiB
TypeScript
// EngineAdapter + DuelLens over the sim stand-in duel engine (scripts/sim/duel-standin.ts).
|
|
import type { DeckSpec, EngineAdapter, Seat } from '../../shared/bots/types.ts';
|
|
import { duelEvaluate, type DuelLens, type LensAction } from '../../shared/bots/duel-bots.ts';
|
|
import { existsSync } from 'node:fs';
|
|
import { applyAction, createDuel, fromDuelCards, isCreature, legalActions, pow, tough, viewFor, deriveSample, STANDIN_RULES, type SAction, type SCard, type SRules, type SState } from './duel-standin.ts';
|
|
import { mulberry32 } from '../../shared/bots/index.ts';
|
|
import type { DuelSim } from './duel-sim-types.ts';
|
|
|
|
export const standinLens: DuelLens<SState, SAction> = {
|
|
phase: s => s.phase,
|
|
life: (s, p) => s.players[p].life,
|
|
handSize: (s, p) => (s as any).view && (s as any).view.seat !== p ? (s as any).view.oppHand : s.players[p].hand.length,
|
|
creatures: (s, p) => s.players[p].board.filter(isCreature).map(b => ({
|
|
uid: String(b.uid), power: pow(b), toughness: Math.max(0, tough(b) - b.damage), tapped: b.tapped,
|
|
canAttack: b.card.type === 'Figure' && !b.tapped && !b.sick, canBlock: !b.tapped,
|
|
value: pow(b) + tough(b) * 0.8 + (b.card.type === 'Figure' ? 0.5 : 0),
|
|
})),
|
|
attackers: s => s.attackers.map(String),
|
|
blocks: s => s.blocks.map(([b, a]) => [String(b), String(a)]),
|
|
decode: (s, a): LensAction => {
|
|
switch (a.type) {
|
|
case 'play': { const c = s.players[a.seat].hand.find(h => h.id === a.card); return { kind: 'play', cost: c?.cost ?? 0, cardType: c?.type ?? '?' }; }
|
|
case 'toggleAttacker': return { kind: 'attack', uid: String(a.uid), on: !s.attackers.includes(a.uid) };
|
|
case 'confirmAttack': return { kind: 'confirmAttack' };
|
|
case 'block': return { kind: 'block', blocker: String(a.blocker), attacker: String(a.attacker) };
|
|
case 'confirmBlocks': return { kind: 'confirmBlocks' };
|
|
case 'endPhase': return { kind: 'endMain' };
|
|
}
|
|
},
|
|
};
|
|
|
|
export function makeStandinSim(poolFile: string, rules: Partial<SRules> = {}): DuelSim<SState, SAction, SCard> {
|
|
const fixture = poolFile.replace(/card-sample\.json$/, 'duel-card-sample.json');
|
|
const pool = process.env.SIM_STANDIN_POOL !== 'own' && existsSync(fixture) ? fromDuelCards(fixture) : deriveSample(poolFile);
|
|
const R = { ...STANDIN_RULES, ...rules };
|
|
const engine: EngineAdapter<SState, SAction> = {
|
|
name: 'duel-standin',
|
|
rulesets: () => ['standin'],
|
|
decks: () => [],
|
|
createMatch: (_r, decks, seed) => createDuel([decks[0].payload as SCard[], decks[1].payload as SCard[]], seed, R),
|
|
toAct: s => (s.phase === 'block' ? (1 - s.active) : s.active) as Seat,
|
|
legalActions: (s, seat) => legalActions(s, seat),
|
|
applyAction: (s, a) => applyAction(s, a),
|
|
isOver: s => s.over,
|
|
result: s => ({ winner: s.winner, reason: s.reason }),
|
|
turn: s => s.turn,
|
|
evaluate: (s, seat) => duelEvaluate(standinLens, s, seat),
|
|
cardsOf: (s, a) => (a.type === 'play' ? [a.card] : []),
|
|
actionKind: a => a.type,
|
|
firstSeat: s => s.first,
|
|
observe: (s, seat) => viewFor(s, seat),
|
|
assume: (obs, seat, rng) => {
|
|
// Refill hidden zones from the unseen part of the pool (a determinization).
|
|
const v = structuredClone(obs) as SState & { view: { oppHand: number; oppLib: number; myLib: number } };
|
|
const seen = new Set<string>();
|
|
for (const p of v.players) for (const z of [p.hand, p.grave, p.board.map(b => b.card)]) for (const c of z) seen.add(c.id);
|
|
const unseen = pool.filter(c => !seen.has(c.id));
|
|
const r = mulberry32(Math.floor(rng() * 2 ** 31));
|
|
for (let i = unseen.length - 1; i > 0; i--) { const j = Math.floor(r() * (i + 1)); [unseen[i], unseen[j]] = [unseen[j], unseen[i]]; }
|
|
let k = 0;
|
|
const take = (n: number) => { const out: SCard[] = []; for (let i = 0; i < n; i++) out.push(unseen[k++ % Math.max(1, unseen.length)]); return out; };
|
|
const o = 1 - seat;
|
|
v.players[o].hand = take(v.view.oppHand);
|
|
v.players[o].library = take(v.view.oppLib);
|
|
v.players[seat].library = take(v.view.myLib);
|
|
delete (v as any).view;
|
|
return v;
|
|
},
|
|
};
|
|
return {
|
|
name: 'standin', engine, lens: standinLens, pool,
|
|
deckPayload: cards => cards,
|
|
metrics: s => ({ connectedFires: s.stats.connectedFires, plays: s.stats.plays, lifeLeft: s.winner === null ? 0 : s.players[s.winner].life }),
|
|
connected: (a, b) => a.connect.some((k: string) => b.connect.includes(k)),
|
|
};
|
|
}
|