1ed7797cb6
- New guns: guess-factor (GF histogram), pattern-matcher (movement tape replay) - New modules: minimum-risk melee movement, spinning melee radar - New test bots: PatternMover, RandomMover, WaveSurfer - Fixed: FeedbackEvent now carries actualX/actualY for proper GF learning - Fixed: TM gun warmup gating + directional residuals - Fixed: circular gun integrated formula + multi-bin omega cache - Fixed: oscillator wall-bounce lockout - Fixed: phantom meteor perpendicular body orientation - 6/6 battle wins across all enemy types
82 lines
2.7 KiB
Nim
82 lines
2.7 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/PatternMover_garage"),
|
|
("RandomMover", "/home/davide/Projects/SirRoboGarage/RandomMover_garage"),
|
|
]
|
|
|
|
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 ""
|