## Task 4: offline gun-range runner. Replays one or more fixtures through the ## 13 ModularBot guns and prints a deterministic per-gun table (overall hit rate ## plus per-power-bin hits/shots) for each fixture. ## ## Usage: ## nim c -r common_libs/tests/run_range.nim # all tools/fixtures/*.jsonl ## nim c -r common_libs/tests/run_range.nim path/a.jsonl path/b.jsonl ## nim c -r common_libs/tests/run_range.nim --timing # add per-fixture wall time ## ## Tsetlin is stochastic; it is seeded (seed=1) here so this tool's output is ## reproducible run-to-run. Its numbers are NOT expected to match a live battle. import std/[os, algorithm, strformat, times] import gun_harness/offline_range import range_guns const fixturesDir = currentSourcePath().parentDir.parentDir.parentDir / "tools" / "fixtures" proc fixtureFiles(args: seq[string]): seq[string] = for a in args: if a == "--timing": continue if dirExists(a): for f in walkFiles(a / "*.jsonl"): result.add f elif fileExists(a): result.add a else: echo "warning: not found: ", a if result.len == 0: for f in walkFiles(fixturesDir / "*.jsonl"): result.add f result.sort() proc main() = var args: seq[string] for i in 1..paramCount(): args.add paramStr(i) let showTiming = "--timing" in args let files = fixtureFiles(args) if files.len == 0: echo "no fixtures found under ", fixturesDir echo "run: nim c -r common_libs/tests/gen_synthetic_fixtures.nim" quit(1) var grandShots, grandHits = 0 for path in files: let fx = loadFixture(path) var t0 = 0.0 if showTiming: t0 = epochTime() let reports = replayFixture(fx, buildAllGunDrivers(seed = 1), liveActual = (fx.meta.source == "live")) let elapsed = if showTiming: epochTime() - t0 else: 0.0 stdout.write formatReports(fx, reports) if showTiming: echo fmt" replay: {elapsed*1000.0:.1f} ms" var totShots, totHits = 0 for r in reports: totShots += r.shots totHits += r.hits grandShots += totShots grandHits += totHits echo "" if files.len > 1: echo fmt"TOTAL across {files.len} fixtures: {grandHits}/{grandShots} ({grandHits.float/grandShots.float*100.0:.1f}%)" echo fmt"(replayed {files.len} fixture(s))" when isMainModule: main()