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>
71 lines
3.8 KiB
TypeScript
71 lines
3.8 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { mulberry32 } from '../shared/bots/index.ts';
|
|
import { makeDuelBot, DUEL_BOT_NAMES } from '../shared/bots/duel-bots.ts';
|
|
import { makeStandinSim } from '../scripts/sim/duel-standin-adapter.ts';
|
|
import { buildDeck, deckSet, ARCHETYPES } from '../scripts/sim/duel-decks.ts';
|
|
import { playDuel, schedule, DUEL_MIXES, MAX_WORKERS } from '../scripts/sim/duel-run.ts';
|
|
import { aggregateDuel, duelMarkdown } from '../scripts/sim/duel-stats.ts';
|
|
|
|
const SAMPLE = fileURLToPath(new URL('../docs/game/card-sample.json', import.meta.url));
|
|
const sim = makeStandinSim(SAMPLE);
|
|
|
|
test('decks: 40 unique cards from the 236-card sample, archetypes skew types', () => {
|
|
assert.equal(sim.pool.length, 236);
|
|
for (const arch of ARCHETYPES) {
|
|
const d = buildDeck(sim.pool, arch, 3);
|
|
assert.equal(d.cards.length, 40);
|
|
assert.equal(new Set(d.cards.map(c => c.id)).size, 40, 'each NFT appears once');
|
|
assert.ok(d.tags.includes(`arch:${arch}`));
|
|
}
|
|
const figs = (arch: (typeof ARCHETYPES)[number]) => buildDeck(sim.pool, arch, 9).cards.filter(c => c.type === 'Figure').length;
|
|
assert.ok(figs('figure-heavy') > figs('doctrine-heavy'));
|
|
assert.deepEqual(deckSet(sim.pool, 6, 1).map(d => d.id), deckSet(sim.pool, 6, 1).map(d => d.id));
|
|
});
|
|
|
|
test('duel matches terminate, are deterministic and bots only play legal actions', () => {
|
|
const decks = deckSet(sim.pool, 4, 2);
|
|
for (const bots of [['random', 'random'], ['heuristic', 'greedy'], ['mc-lite', 'heuristic']] as [string, string][]) {
|
|
const a = playDuel(sim, [decks[0], decks[1]], bots, 11);
|
|
const b = playDuel(sim, [decks[0], decks[1]], bots, 11);
|
|
assert.equal(a.truncated, false, `${bots} truncated`);
|
|
assert.deepEqual({ ...a, ms: 0 }, { ...b, ms: 0 });
|
|
}
|
|
const { engine, lens } = sim;
|
|
for (const name of DUEL_BOT_NAMES) {
|
|
const bot = makeDuelBot(name, engine, lens);
|
|
let s = engine.createMatch('duel', [{ id: 'a', tags: [], payload: decks[2].cards }, { id: 'b', tags: [], payload: decks[3].cards }], 5);
|
|
const rng = mulberry32(3);
|
|
for (let i = 0; i < 400 && !engine.isOver(s); i++) {
|
|
const seat = engine.toAct(s);
|
|
const a = bot(engine.observe!(s, seat), seat, rng);
|
|
assert.ok(engine.legalActions(s, seat).some(x => JSON.stringify(x) === JSON.stringify(a)), `${name} chose an illegal action`);
|
|
s = engine.applyAction(s, a);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('observation hides the opponent hand and libraries', () => {
|
|
const decks = deckSet(sim.pool, 2, 4);
|
|
const s = sim.engine.createMatch('duel', [{ id: 'a', tags: [], payload: decks[0].cards }, { id: 'b', tags: [], payload: decks[1].cards }], 1);
|
|
const v = sim.engine.observe!(s, 0) as any;
|
|
assert.equal(v.players[1].hand.length, 0);
|
|
assert.equal(v.players[1].library.length, 0);
|
|
assert.equal(v.players[0].library.length, 0);
|
|
assert.equal(v.view.oppHand, s.players[1].hand.length);
|
|
});
|
|
|
|
test('heuristic beats random; stats and markdown cover the report metrics', () => {
|
|
const decks = deckSet(sim.pool, 10, 5);
|
|
const jobs = schedule(40, decks.length, 9, [['random', 'heuristic', 1]]);
|
|
const recs = jobs.map(j => playDuel(sim, [decks[j.decks[0]], decks[j.decks[1]]], j.bots, j.seed));
|
|
const stats = aggregateDuel(recs, sim, decks, 0, { label: 't', engine: 'standin', rules: {} });
|
|
assert.ok(stats.skill['heuristic>random'].rate > 0.8, JSON.stringify(stats.skill));
|
|
const md = duelMarkdown(stats);
|
|
for (const k of ['First-player win rate', 'Turns each', 'Stalls', 'Connected', 'Fame vs card win rate', 'Card type', 'Portal', 'Keyword', 'Cost']) assert.match(md, new RegExp(k));
|
|
assert.ok(stats.connected.pairRate > 0 && stats.connected.pairRate < 1);
|
|
assert.equal(MAX_WORKERS, 4);
|
|
assert.ok(Object.keys(DUEL_MIXES).includes('default'));
|
|
});
|