Repository navigation
Add a fight simulator that plays fights through the engine's own turn loop - #91
Merged
Merged
Conversation
… loop fight MATCHUP.yml plays one matchup thousands of times on a throwaway in-memory arena, typing attack/go/drink/throw lines into Engine::submit (the told loop, no model) or Engine::play (the mechanics loop), and counts win, death and flight rates with 95% intervals, rounds, hit points left, and damage and blows. --replay SEED prints one fight line by line; --json prints the table as JSON. No rule is copied: the turn loop decides every blow, and a fight is read back off the records it left. tests/sim.rs holds it to the rules' exact odds, per-seed identity of the two loops on fights with no move, determinism, and the blows-to-tally check.
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 1 of the fight simulator: fights played through the engine's own turn loop, with no model and no copied rule.
What it does
fight MATCHUP.ymlplays one matchup thousands of times and counts the results. Each fight is a throwaway in-memory game. A policy types one line a turn (attack,go,drink,throw), and the line goes through:Engine::submitin a game the player narrates, slashed, with an emptymodel::Replay(the told loop the browser plays; the default), orEngine::play(the mechanics loop, a little faster, with a clock that does not move between lines).The turn loop decides every blow, riposte, death and fight close, and the fight is read back off the rows it left (
playthrough_blows,outcome::State). A rule that lands in the engine is therefore in the simulator straight away.src/sim/arena.rs: the arena. It is the sweep's one-room world with the matchup's player, carried things and foes, and both rooms written. It is built once and kept as a SQLite image; each fight opens a fresh copy (rusqliteserialize). The turn loop also updates world rows during a fight (for example, a dead foe's body), so a fresh copy is exact where deleting rows above a high-water mark would not be.src/sim/matchup.rs: the YAML matchup file. Its keys are a world file's;rolledtakes a number fromstat_block::rollfor each seed; any other key of a foe, a carried thing or the story is written into the row as given.src/sim/policy.rs:attack,flee_below,drink_below,throw_first(each throwable tried once),naive(drink below 30%) andcareful(drink at half; leave when HP ≤ the sum of the live foes' hit dice). The options combine.src/sim/mod.rs: the two drivers, seeds (playthrough id =SEED_BASE+ seed), and threads. Fights come back in seed order, the same on any thread count. A refused line, or a line that asks a model, is an error.src/sim/tally.rs: win, death and flight rates with Wilson 95% intervals; rounds and HP left (mean and histogram); damage and blows on each side;--json;--replay SEEDline by line.src/bin/fight.rs: the CLI (--seeds A..B,--driver,--threads,--json,--replay). It turns off SQLite's global allocation counter before the first connection opens. With the counter on, 8 threads ran about 300 fights/s; with it off, about 700–1,000/s on this shared machine.tests/sim.rs:playthrough_blowsrows say;sim/matchups/.No rule, migration, golden, prompt or server change. Fight goldens in CI, sweeps,
--database,--fight-tableand CSV are left to the later stages.Sample results
All runs use the told driver against the house body (L3 d8, 18 HP).
Exact P(win) from the rules: 1 × L3 d10 is 0.2338 and 3 × L1 d6 is 0.1914, both inside the intervals. On these two matchups the mechanics driver gives the same tallies to the last digit.
Checks
cargo fmt --checkandcargo clippy --workspace --all-targets --locked -- -D warningspass.cargo test --workspace --lockedpasses.tests/sim.rstakes 17–50 s in debug on a loaded 16-core machine.parity --check parityexits 0, unchanged.OPENROUTER_API_KEYandTYPESAFE_API_KEYunset. No model was called.