feat(test_framework): use TR_SAMPLE_BOTS env var for external bot directory

Adds TR_SAMPLE_BOTS env var support to point to external sample bots (Walls, Fire, SpinBot, etc). Updates test_bullet_economy.nim to use Walls from the sample-bots directory instead of custom WallsBot, removing the hardcoded path dependency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-16 08:43:46 +02:00
parent 67bba96da1
commit c671e0b0e3
2 changed files with 16 additions and 6 deletions
+12 -3
View File
@@ -1,6 +1,7 @@
## Bullet economy test: SNNBot vs WallsBot. ## Bullet economy test: SNNBot vs WallsBot.
## Prints per-round and summary stats for tuning. No hard pass/fail. ## Prints per-round and summary stats for tuning. No hard pass/fail.
## Requires TR server JARs (set TR_SERVER_JAR / TR_BATTLE_RUNNER env vars). ## Requires TR server JARs (set TR_SERVER_JAR / TR_BATTLE_RUNNER env vars).
## Set TR_SAMPLE_BOTS to point to sample-bots directory (e.g. sample-bots-nim-linux-1.0.7).
import std/[os, strformat] import std/[os, strformat]
import test_framework/battle_result import test_framework/battle_result
@@ -8,19 +9,27 @@ import test_framework/battle_result
const const
DefaultServerJar = "/home/davide/Projects/tank-royale/server/build/libs/robocode-tankroyale-server-0.35.5-all.jar" DefaultServerJar = "/home/davide/Projects/tank-royale/server/build/libs/robocode-tankroyale-server-0.35.5-all.jar"
DefaultRunnerJar = "/home/davide/Projects/tank-royale/runner/examples/lib/robocode-tankroyale-runner.jar" DefaultRunnerJar = "/home/davide/Projects/tank-royale/runner/examples/lib/robocode-tankroyale-runner.jar"
DefaultSampleBots = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
let serverJar = getEnv("TR_SERVER_JAR", DefaultServerJar) let serverJar = getEnv("TR_SERVER_JAR", DefaultServerJar)
let runnerJar = getEnv("TR_BATTLE_RUNNER", DefaultRunnerJar) let runnerJar = getEnv("TR_BATTLE_RUNNER", DefaultRunnerJar)
let sampleBotsDir = getEnv("TR_SAMPLE_BOTS", DefaultSampleBots)
if not fileExists(serverJar) or not fileExists(runnerJar): if not fileExists(serverJar) or not fileExists(runnerJar):
echo "Skipping: JAR files not found (set TR_SERVER_JAR / TR_BATTLE_RUNNER to override)" echo "Skipping: JAR files not found (set TR_SERVER_JAR / TR_BATTLE_RUNNER to override)"
quit(0) quit(0)
if not dirExists(sampleBotsDir):
echo "Skipping: sample bots directory not found at ", sampleBotsDir
echo "Set TR_SAMPLE_BOTS to override"
quit(0)
import test_framework/test_framework import test_framework/test_framework
const const
snnbotDir = currentSourcePath().parentDir.parentDir snnbotDir = currentSourcePath().parentDir.parentDir
wallsbotDir = currentSourcePath().parentDir.parentDir.parentDir /
"common_libs" / "test_framework" / "adversaries" / "WallsBot" let wallsbotDir = sampleBotsDir / "Walls"
let r = runBattle(@[snnbotDir, wallsbotDir], rounds = 10) let r = runBattle(@[snnbotDir, wallsbotDir], rounds = 10)
@@ -12,10 +12,10 @@ export battle_result.RoundResult
export battle_result.BotRoundResult export battle_result.BotRoundResult
proc runBattle*(botDirs: seq[string], rounds: int = 10, proc runBattle*(botDirs: seq[string], rounds: int = 10,
timeout: int = 120000): BattleResult = timeout: int = 120000, maxSpeed: bool = true): BattleResult =
ensureServer() ensureServer()
discard compileBots(botDirs) discard compileBots(botDirs)
let stdout = runBattleRunner(getServerUrl(), botDirs, rounds, timeout) let stdout = runBattleRunner(getServerUrl(), botDirs, rounds, timeout, maxSpeed)
result = parseServerOutput(stdout) result = parseServerOutput(stdout)
when isMainModule: when isMainModule:
@@ -26,7 +26,8 @@ when isMainModule:
echo " let r = runBattle(@[\"path/to/BotA\", \"path/to/BotB\"])" echo " let r = runBattle(@[\"path/to/BotA\", \"path/to/BotB\"])"
echo " echo r.winners" echo " echo r.winners"
echo "" echo ""
echo "Env vars forwarded to sub-modules:" echo "Env vars:"
echo " TR_SERVER_JAR TR server JAR path" echo " TR_SERVER_JAR TR server JAR path"
echo " TR_BATTLE_RUNNER BattleRunner JAR path" echo " TR_BATTLE_RUNNER BattleRunner JAR path"
echo " TR_BATTLE_RUNNER_DIR BattleRunner class dir" echo " TR_BATTLE_RUNNER_DIR BattleRunner class dir"
echo " TR_SAMPLE_BOTS Directory containing sample bots (e.g. Walls, Fire, SpinBot)"