Files
wownerogue/test/sim_ultra.test.js
T
jwinterm fd4327a54f feat(sim): headless balance-calibration harness (drives the REAL engine)
The instrument the design discussion said was missing. src/sim/ drives the actual
game engine (game.js — same dungeon gen, monster AI, movement as prod) with
headless bots to terminal outcomes, then measures what was only ever DECLARED:

- Per preset: escape/treasure/caught/stuck rates + completion-move/-time pctiles.
- MEASURED house-win-rate per network, integrating out the random block deadline
  analytically: for D~Exp(mean=blockTime), P(house wins an escape at T)=1-exp(-T/BT),
  so no Monte-Carlo over deadlines.
- Two bot skill models (omniscient beeline / explorer fog-of-war) as an upper band;
  neither evades the monster, so true house-win is likely below both.

First findings (explorer, 200 runs, 320ms/move): presets UNDERSHOOT their declared
targets (casino 57% vs 70%, normal 47% vs 55% on WOW) and the edge swings ~15pts
across chains from IDENTICAL dungeons (casino 48% BTC .. 65% GRIN) — because
cryptoType never actually sizes the dungeon. Exactly the two gaps we predicted.

Files: src/sim/{pathfind,simBots,simulate}.js + test/sim_ultra.test.js (structural
guard, not a balance assertion). Run: node src/sim/simulate.js --help-ish flags.
Suite 59/422 green.
2026-07-11 19:43:12 -04:00

47 lines
2.2 KiB
JavaScript

// Guards the balance-sim harness: it must keep driving the REAL engine to terminal outcomes and
// producing well-formed, in-range statistics. Not a balance assertion (those numbers are meant to
// move) — a structural regression guard so the instrument can't silently rot.
const { runOneGame, simulatePreset } = require('../src/sim/simulate');
const { BOTS } = require('../src/sim/simBots');
const { bfsField, stepDownField } = require('../src/sim/pathfind');
describe('balance sim harness', () => {
test('BFS field + downhill step navigate a trivial grid', () => {
const passable = () => true;
const dist = bfsField(3, 3, passable, [[2, 2]]);
expect(dist[2][2]).toBe(0);
expect(dist[0][0]).toBe(4); // Manhattan distance, 4-connected
const step = stepDownField(dist, 0, 0, 3, 3);
expect(step).toEqual(expect.objectContaining({ dx: expect.any(Number), dy: expect.any(Number) }));
// Step must reduce distance to the target.
expect(dist[0 + step.dy][0 + step.dx]).toBeLessThan(dist[0][0]);
});
test('every bot policy drives a game to a real terminal outcome', () => {
for (const id of Object.keys(BOTS)) {
const r = runOneGame(BOTS[id], { vision: 8, moveCap: 6000 });
expect(['escaped', 'caught', 'stuck']).toContain(r.outcome);
expect(r.moves).toBeGreaterThanOrEqual(0);
expect(typeof r.treasure).toBe('boolean');
}
});
test('simulatePreset returns in-range rates and per-network house-win', () => {
const args = { runs: 15, bot: 'explorer-greedy', nets: ['WOW', 'BTC', 'GRIN'], cadence: 320, moveCap: 6000 };
const r = simulatePreset('normal', args);
expect(r.n).toBe(15);
for (const k of ['escapeRate', 'treasureRate', 'caughtRate', 'stuckRate']) {
expect(r[k]).toBeGreaterThanOrEqual(0);
expect(r[k]).toBeLessThanOrEqual(1);
}
// Outcomes partition the runs.
expect(r.escapeRate + r.caughtRate + r.stuckRate).toBeCloseTo(1, 5);
for (const net of args.nets) {
expect(r.houseWin[net]).toBeGreaterThanOrEqual(0);
expect(r.houseWin[net]).toBeLessThanOrEqual(1);
}
// Slower blocks (BTC 10min) give players more time → house wins no MORE than on fast GRIN.
expect(r.houseWin.BTC).toBeLessThanOrEqual(r.houseWin.GRIN + 1e-9);
});
});