## G8.5 LIVE BENCH — virtual-gun tournament vs twin vs ELM vs inert. ## LIVE, Java required. FOUR binaries from the SAME tree: ## * inert — `-d:chimeraInert` (all CHIMERA command paths off == M1 copy) ## * elm — `-d:chimeraNoTwinGun` (probes+fusion+influence, ELM gun as now) ## * twin — `-d:chimeraNoVguns` (M7 influence-gated twin/ELM path) ## * vgun — default (M7.5 virtual-gun tournament: TWIN/ELM/HEAD-ON) ## 5 rounds per arm per opponent vs the 8 primary sample bots + the garage-local ## Dodger-v2 archetype. Reports win rate + score margin; the G7 no-regression read ## is vgun >= inert (win rate) on every opponent, stated plainly when it fails. ## ## The **discrimination test** is the Dodger-v2 row: M7 found the three arms ## ~equal there (~2660 each), i.e. the opponent was too weak to separate them. ## M7.5 reports the four Dodger margins and states plainly whether they now ## differ. ## ## Run: `nim c -r --hints:off -d:release tests/bench_g8_live.nim` import std/[os, osproc, strutils, sequtils, math, tables, algorithm, times] import bench_common const Rounds = 5 DodgerDir = currentSourcePath().parentDir / "archetypes" / "Dodger" type Outcome = object rounds, wins: int ourScore, oppScore: float64 ourSurv, oppSurv: int Arm = object tag, name: string defines: seq[string] const Arms = [ Arm(tag: "inert", name: "ChimeraInert", defines: @["-d:chimeraInert"]), Arm(tag: "elm", name: "ChimeraElm", defines: @["-d:chimeraNoTwinGun"]), Arm(tag: "twin", name: "ChimeraTwin", defines: @["-d:chimeraNoVguns"]), Arm(tag: "vgun", name: "ChimeraVgun", defines: @[]), ] proc parseOutcome(log, ourName: string): Outcome = for ln in log.splitLines(): if ln.len == 0 or ln.find("\"event\":\"round_ended\"") < 0: continue inc result.rounds let ri = ln.find("\"results\":[") if ri < 0: continue let oi = ln.find('[', ri) let ci = ln.find(']', ri) if oi < 0 or ci < 0 or ci <= oi: continue let seg = ln[oi + 1 ..< ci] var j = 0 var ourScoreV = -1.0 var theirScoreV = -1.0 var ourSurvF, theirSurvF = false while j < seg.len: let s = seg.find('{', j) if s < 0: break let e = seg.find('}', s) if e < 0: break let obj = seg[s + 1 ..< e] let (found, name) = extract(obj, "name") let (sf, score) = extract(obj, "score") let (vf, surv) = extract(obj, "survived") if found and sf and vf: if name == ourName: ourScoreV = score.parseFloat() ourSurvF = surv == "true" else: theirScoreV = score.parseFloat() theirSurvF = surv == "true" j = e + 1 if ourScoreV >= 0.0 and theirScoreV >= 0.0: result.ourScore += ourScoreV result.oppScore += theirScoreV if ourScoreV > theirScoreV: inc result.wins if ourSurvF: inc result.ourSurv if theirSurvF: inc result.oppSurv proc runBattle(url: string, botDirs: seq[string], rounds: int, ourName, tag: string): Outcome = putEnv("CHIMERA_TELEMETRY_DIR", getTempDir() / ("chimera_g8_tel_" & tag)) let (ok, logPath) = runBattleHardLog(url, botDirs, rounds, logName = "chimera_g8_" & tag) if not ok: return Outcome() parseOutcome(readFile(logPath), ourName) proc winRate(o: Outcome): float64 = if o.rounds == 0: 0.0 else: 100.0 * float(o.wins) / float(o.rounds) proc margin(o: Outcome): float64 = o.ourScore - o.oppScore proc main() = guardSkip() echo "[G8.5-live] staging 4 arms..." var bots = initTable[string, string]() for a in Arms: bots[a.tag] = stageBot("g85_" & a.tag, a.defines, a.name) let opps = sorted(toSeq(Expected.keys)) & @["Dodger"] var suite = initTable[string, Table[string, Outcome]]() # arm -> opp -> out for arm in Arms: var t = initTable[string, Outcome]() for opp in opps: let oppDir = if opp == "Dodger": DodgerDir else: SampleRoot / opp restartServer() putEnv("CHIMERA_OPPONENT", opp) let o = runBattle(serverUrl(), @[bots[arm.tag], oppDir], Rounds, arm.name, arm.tag & "_" & opp) t[opp] = o echo " [", alignLeft(arm.tag, 5), "] vs ", alignLeft(opp, 10), " rounds=", o.rounds, " winRate=", formatFloat(winRate(o), ffDecimal, 0), "%", " margin=", formatFloat(margin(o), ffDecimal, 1) suite[arm.tag] = t echo "\n=== G8.5 live suite (", Rounds, " rounds/arm/opponent) ===" echo "Opponent elmW% elmM twinW% twinM vgunW% vgunM inertW% inertM" var noRegress = true var regress: seq[string] var lines: seq[string] lines.add "# G8.5 live bench (M7.5 virtual-gun tournament)\n" lines.add "Four arms from the SAME tree: inert (`-d:chimeraInert`), elm " & "(`-d:chimeraNoTwinGun`), twin (`-d:chimeraNoVguns`), vgun (default). " & $Rounds & " rounds per arm per opponent. Generated by " & "`tests/bench_g8_live.nim`.\n" lines.add "| opponent | elm W% | elm margin | twin W% | twin margin | vgun W% | vgun margin | inert W% | inert margin |" lines.add "|---|---:|---:|---:|---:|---:|---:|---:|---:|" for opp in opps: let e = suite["elm"].getOrDefault(opp) let t = suite["twin"].getOrDefault(opp) let v = suite["vgun"].getOrDefault(opp) let i = suite["inert"].getOrDefault(opp) if v.rounds > 0 and i.rounds > 0 and v.wins < i.wins: noRegress = false; regress.add opp echo " ", alignLeft(opp, 10), align(formatFloat(winRate(e), ffDecimal, 0), 7), align(formatFloat(margin(e), ffDecimal, 1), 7), align(formatFloat(winRate(t), ffDecimal, 0), 7), align(formatFloat(margin(t), ffDecimal, 1), 6), align(formatFloat(winRate(v), ffDecimal, 0), 7), align(formatFloat(margin(v), ffDecimal, 1), 6), align(formatFloat(winRate(i), ffDecimal, 0), 8), align(formatFloat(margin(i), ffDecimal, 1), 7) lines.add "| " & opp & " | " & formatFloat(winRate(e), ffDecimal, 1) & " | " & formatFloat(margin(e), ffDecimal, 1) & " | " & formatFloat(winRate(t), ffDecimal, 1) & " | " & formatFloat(margin(t), ffDecimal, 1) & " | " & formatFloat(winRate(v), ffDecimal, 1) & " | " & formatFloat(margin(v), ffDecimal, 1) & " | " & formatFloat(winRate(i), ffDecimal, 1) & " | " & formatFloat(margin(i), ffDecimal, 1) & " |" # suite totals var totals = initTable[string, Outcome]() for opp in opps: for arm in Arms: let o = suite[arm.tag].getOrDefault(opp) totals.mgetOrPut(arm.tag, Outcome()).rounds += o.rounds totals[arm.tag].wins += o.wins totals[arm.tag].ourScore += o.ourScore totals[arm.tag].oppScore += o.oppScore var totLine = "Totals: " for arm in Arms: let t = totals[arm.tag] totLine.add arm.tag & " " & formatFloat(winRate(t), ffDecimal, 1) & "% (m " & formatFloat(margin(t), ffDecimal, 1) & ") " echo "\n", totLine lines.add "\n**" & totLine & "**" # Discrimination read on the Dodger-v2 row. var dm = "" var dmin = Inf var dmax = -Inf for arm in Arms: let o = suite[arm.tag].getOrDefault("Dodger") dm.add arm.tag & " " & formatFloat(margin(o), ffDecimal, 1) & " " dmin = min(dmin, margin(o)) dmax = max(dmax, margin(o)) let spread = dmax - dmin echo "Dodger-v2 margins: ", dm, " spread=", formatFloat(spread, ffDecimal, 1) lines.add "\n**Discrimination test (Dodger-v2 row).** Margins: " & dm & "spread " & formatFloat(spread, ffDecimal, 1) & ". " & (if spread >= 500.0: "The arms DIFFER materially against the upgraded Dodger." else: "The arms remain ~equal against the upgraded Dodger — stated plainly as a finding.") lines.add "\n**G7 no-regression (vgun >= inert win-rate on every opponent): " & (if noRegress: "PASS" else: "**FAIL** on " & regress.join(", ")) & ".**" let art = currentSourcePath().parentDir.parentDir / "benchmarks" / "m7_5_g8_live.md" createDir(art.parentDir) writeFile(art, lines.join("\n") & "\n") echo "\nArtifact: ", art when isMainModule: main()