diff --git a/scripts/sim/duel-decks.ts b/scripts/sim/duel-decks.ts new file mode 100644 index 0000000..388bd49 --- /dev/null +++ b/scripts/sim/duel-decks.ts @@ -0,0 +1,49 @@ +// 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 { 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(pool: C[], arch: Archetype, seed: number, size = 40): SimDeck { + 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 = {}; for (const c of cards) m[f(c)] = (m[f(c)] ?? 0) + 1; return m; }; + const top = (m: Record) => 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(pool: C[], n: number, seed: number, size = 40): SimDeck[] { + const out: SimDeck[] = []; + 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; +} diff --git a/scripts/sim/duel-run.ts b/scripts/sim/duel-run.ts new file mode 100644 index 0000000..74cfc33 --- /dev/null +++ b/scripts/sim/duel-run.ts @@ -0,0 +1,137 @@ +// Duel balance simulation. +// npx tsx scripts/sim/duel-run.ts --engine duel --matches 2000 --workers 4 --out sim-out/duel [--rules '{"startingLife":18}'] +// Writes /