## G8 LIVE BENCH — twin gun vs ELM gun vs inert, suite + G7 no-regression. ## LIVE, Java required. Three 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 — default (ELM gun REPLACED by the M7 twin gun) ## 5 rounds per arm per opponent vs the 8 primary sample bots + the garage-local ## Dodger archetype. Reports win rate + score margin; the G7 no-regression read ## is twin >= inert (win rate) on every opponent, stated plainly when it fails. ## ## 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: @[]), ] 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-live] staging 3 arms..." var bots = initTable[string, string]() for a in Arms: bots[a.tag] = stageBot("g8_" & 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 live suite (", Rounds, " rounds/arm/opponent) ===" echo "Opponent elmW% elmM twinW% twinM inertW% inertM" var noRegress = true var regress: seq[string] var lines: seq[string] lines.add "# G8 live bench (M7 twin gun)\n" lines.add "Three arms from the SAME tree: inert (`-d:chimeraInert`), elm " & "(`-d:chimeraNoTwinGun`), twin (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 | inert W% | inert margin |" lines.add "|---|---:|---:|---:|---:|---:|---:|" for opp in opps: let e = suite["elm"].getOrDefault(opp) let t = suite["twin"].getOrDefault(opp) let i = suite["inert"].getOrDefault(opp) if t.rounds > 0 and i.rounds > 0 and t.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(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(i), ffDecimal, 1) & " | " & formatFloat(margin(i), ffDecimal, 1) & " |" # suite totals var te, tt, ti: Outcome for opp in opps: for (dst, arm) in [(addr te, "elm"), (addr tt, "twin"), (addr ti, "inert")]: let o = suite[arm].getOrDefault(opp) dst.rounds += o.rounds; dst.wins += o.wins dst.ourScore += o.ourScore; dst.oppScore += o.oppScore echo "\nTotals: elm ", formatFloat(winRate(te), ffDecimal, 1), "% (m ", formatFloat(margin(te), ffDecimal, 1), ") twin ", formatFloat(winRate(tt), ffDecimal, 1), "% (m ", formatFloat(margin(tt), ffDecimal, 1), ") inert ", formatFloat(winRate(ti), ffDecimal, 1), "% (m ", formatFloat(margin(ti), ffDecimal, 1), ")" lines.add "\n**Totals:** elm " & formatFloat(winRate(te), ffDecimal, 1) & "% (margin " & formatFloat(margin(te), ffDecimal, 1) & "), twin " & formatFloat(winRate(tt), ffDecimal, 1) & "% (margin " & formatFloat(margin(tt), ffDecimal, 1) & "), inert " & formatFloat(winRate(ti), ffDecimal, 1) & "% (margin " & formatFloat(margin(ti), ffDecimal, 1) & ")." lines.add "\n**G7 no-regression (twin >= inert win-rate on every opponent): " & (if noRegress: "PASS" else: "**FAIL** on " & regress.join(", ")) & ".**" let art = currentSourcePath().parentDir.parentDir / "benchmarks" / "m7_g8_live.md" createDir(art.parentDir) writeFile(art, lines.join("\n") & "\n") echo "\nArtifact: ", art when isMainModule: main()