c034eb9d25
- fix(ModularBot): onBulletHitBot → onBulletHit (real hits were never tracked) - feat(ModularBot): per-round gun stats dump to /tmp/gun_stats.jsonl - feat(ModularBot): gun selection counter per round - fix(tests): adversary paths _garage suffix removed from 7 test files - feat(tests): test_gauntlet_5bots.nim — 10-round gauntlet vs all 5 adversaries - feat(tests): analyze_gun_stats.nim — JSONL parser for gun performance tables - docs: gun_rack_analysis.md — full per-gun performance report - docs: gun_rack_summary.md — TL;DR verdict table (keep/drop/tune) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.8 KiB
Nim
82 lines
2.8 KiB
Nim
## Gun switching battle test: runs 10 rounds vs each enemy, captures [gun] lines
|
|
## from /tmp/modularbot_stdout.log (written by ModularBot.sh), reports scores
|
|
## and gun usage per battle.
|
|
|
|
import std/[os, strutils, tables, sequtils]
|
|
import test_framework/test_framework
|
|
|
|
if not existsEnv("TR_SERVER_JAR") or not existsEnv("TR_BATTLE_RUNNER"):
|
|
echo "Skipping: TR_SERVER_JAR / TR_BATTLE_RUNNER not set"
|
|
quit(0)
|
|
|
|
const
|
|
modularBotDir = "/home/davide/Projects/SirRoboGarage/ModularBot_garage"
|
|
sampleBots = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
|
|
|
|
let enemies = @[
|
|
("Target", sampleBots / "Target"),
|
|
("SpinBot", sampleBots / "SpinBot"),
|
|
("Crazy", sampleBots / "Crazy"),
|
|
("PatternMover", "/home/davide/Projects/SirRoboGarage/common_libs/test_framework/adversaries/PatternMover"),
|
|
("RandomMover", "/home/davide/Projects/SirRoboGarage/common_libs/test_framework/adversaries/RandomMover"),
|
|
]
|
|
|
|
const logFile = "/tmp/modularbot_stdout.log"
|
|
|
|
proc readGunLines(since: int64): seq[string] =
|
|
## Returns all [gun] lines appended after `since` bytes.
|
|
if not fileExists(logFile): return @[]
|
|
let content = readFile(logFile)
|
|
let tail = if since < content.len.int64: content[since.int ..< content.len] else: ""
|
|
for line in tail.splitLines():
|
|
if "[gun]" in line:
|
|
result.add line.strip()
|
|
|
|
proc gunCounts(lines: seq[string]): Table[string, int] =
|
|
for line in lines:
|
|
# "[gun] switched: GunName" or "[gun] starting: GunName"
|
|
let parts = line.split(' ')
|
|
if parts.len >= 3:
|
|
let name = parts[^1]
|
|
result[name] = result.getOrDefault(name, 0) + 1
|
|
|
|
echo ""
|
|
echo "=".repeat(70)
|
|
echo "ModularBot Gun Switching Battle Report"
|
|
echo "=".repeat(70)
|
|
echo ""
|
|
|
|
for (eName, eDir) in enemies:
|
|
# Snapshot log size before battle
|
|
let logSizeBefore: int64 =
|
|
if fileExists(logFile): getFileSize(logFile) else: 0
|
|
|
|
var r: BattleResult
|
|
try:
|
|
r = runBattle(@[modularBotDir, eDir], rounds = 10, timeout = 180_000)
|
|
except CatchableError as e:
|
|
echo "BATTLE vs " & eName & " FAILED: " & e.msg
|
|
continue
|
|
|
|
# Collect gun lines printed during this battle
|
|
let gunLines = readGunLines(logSizeBefore)
|
|
let counts = gunCounts(gunLines)
|
|
|
|
# Extract scores
|
|
var myScore, theirScore: int
|
|
for b in r.results:
|
|
if b.name == "ModularBot": myScore = b.totalScore
|
|
else: theirScore = b.totalScore
|
|
let outcome = if "ModularBot" in r.winners: "WIN" else: "LOSS"
|
|
|
|
echo "--- vs " & eName & " ---"
|
|
echo " Score: ModularBot=" & $myScore & " " & eName & "=" & $theirScore & " [" & outcome & "]"
|
|
echo " [gun] switches logged: " & $gunLines.len
|
|
if counts.len > 0:
|
|
echo " Gun usage:"
|
|
for gun, cnt in counts.pairs:
|
|
echo " " & gun & ": " & $cnt & " switch(es)"
|
|
else:
|
|
echo " (no [gun] lines captured)"
|
|
echo ""
|