forked from WikiDeck/wikideck
Engine-agnostic duel bots over a DuelLens, a 40-card deck builder from the 236 sample cards with type/curve-skewed archetypes, a <=4-worker sim runner and DUEL_BALANCE metrics. Runs on a small stand-in duel engine until duel-core's shared/duel alpha lands; then shared/bots/duel-adapter.ts binds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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;
|
||
}
|