Files
SirRoboGarage/ModularBot_garage/tests/test_battle_suite.nim
T
SirStone 254c7dc997 feat(ModularBot): pluggable bot with 4 guns, phantom meteor movement, radar harness
- Gun harness: virtual bullet tracker, rolling fitness, auto-selector
- Guns: head-on, linear (extrapolation), circular (integrated formula), tsetlin machine (learning)
- Movement: phantom meteor gravity engine (danger histograms, phantom bullets, fire detection)
- Radar: harness + radar_lock adapter
- Color-coded modules: turret/bullet color per gun, body per movement, scan per radar
- Beats Target, SpinBot, Crazy, TrackFire in 10-round battles
2026-09-20 00:37:10 +02:00

59 lines
2.4 KiB
Nim

import std/[os, unittest, strformat]
import test_framework/test_framework
const
modularBotDir = currentSourcePath().parentDir.parentDir
samplesDir = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
target = samplesDir / "Target"
spinBot = samplesDir / "SpinBot"
crazy = samplesDir / "Crazy"
trackFire = samplesDir / "TrackFire"
# Skip if JARs are missing
if not fileExists("/home/davide/Projects/tank-royale/server/build/libs/robocode-tankroyale-server-0.35.5-all.jar") or
not fileExists("/home/davide/Projects/tank-royale/runner/examples/lib/robocode-tankroyale-runner.jar"):
echo "Skipping: Tank Royale JARs not found"
quit(0)
proc extractFinalScores(r: BattleResult, enemyName: string): tuple[modularScore, enemyScore: int] =
var modularScore = 0
var enemyScore = 0
for b in r.results:
if b.name == "ModularBot": modularScore = b.totalScore
if b.name == enemyName: enemyScore = b.totalScore
(modularScore, enemyScore)
suite "ModularBot battle suite":
test "vs Target (stationary)":
echo "\n[1/4] ModularBot vs Target"
let r = runBattle(@[modularBotDir, target], rounds = 10, timeout = 180000)
let (mb, en) = extractFinalScores(r, "Target")
let winner = if mb > en: "ModularBot" else: "Target"
echo fmt" ModularBot: {mb}, Target: {en} → {winner} wins"
check mb > 0 or en > 0 # At least one score recorded
test "vs SpinBot (circular)":
echo "\n[2/4] ModularBot vs SpinBot"
let r = runBattle(@[modularBotDir, spinBot], rounds = 10, timeout = 180000)
let (mb, en) = extractFinalScores(r, "SpinBot")
let winner = if mb > en: "ModularBot" else: "SpinBot"
echo fmt" ModularBot: {mb}, SpinBot: {en} → {winner} wins"
check mb > 0 or en > 0
test "vs Crazy (unpredictable)":
echo "\n[3/4] ModularBot vs Crazy"
let r = runBattle(@[modularBotDir, crazy], rounds = 10, timeout = 180000)
let (mb, en) = extractFinalScores(r, "Crazy")
let winner = if mb > en: "ModularBot" else: "Crazy"
echo fmt" ModularBot: {mb}, Crazy: {en} → {winner} wins"
check mb > 0 or en > 0
test "vs TrackFire (fires back)":
echo "\n[4/4] ModularBot vs TrackFire"
let r = runBattle(@[modularBotDir, trackFire], rounds = 10, timeout = 180000)
let (mb, en) = extractFinalScores(r, "TrackFire")
let winner = if mb > en: "ModularBot" else: "TrackFire"
echo fmt" ModularBot: {mb}, TrackFire: {en} → {winner} wins"
check mb > 0 or en > 0