From c671e0b0e32bcdb96079b3bea917c40576e49ae9 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Wed, 16 Sep 2026 08:43:46 +0200 Subject: [PATCH] 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 --- SNNBot_garage/tests/test_bullet_economy.nim | 15 ++++++++++++--- common_libs/test_framework/test_framework.nim | 7 ++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/SNNBot_garage/tests/test_bullet_economy.nim b/SNNBot_garage/tests/test_bullet_economy.nim index 766ed15..9e1fa3b 100644 --- a/SNNBot_garage/tests/test_bullet_economy.nim +++ b/SNNBot_garage/tests/test_bullet_economy.nim @@ -1,6 +1,7 @@ ## Bullet economy test: SNNBot vs WallsBot. ## 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). +## Set TR_SAMPLE_BOTS to point to sample-bots directory (e.g. sample-bots-nim-linux-1.0.7). import std/[os, strformat] import test_framework/battle_result @@ -8,19 +9,27 @@ import test_framework/battle_result const 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" + DefaultSampleBots = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7" let serverJar = getEnv("TR_SERVER_JAR", DefaultServerJar) let runnerJar = getEnv("TR_BATTLE_RUNNER", DefaultRunnerJar) +let sampleBotsDir = getEnv("TR_SAMPLE_BOTS", DefaultSampleBots) + if not fileExists(serverJar) or not fileExists(runnerJar): echo "Skipping: JAR files not found (set TR_SERVER_JAR / TR_BATTLE_RUNNER to override)" 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 const - snnbotDir = currentSourcePath().parentDir.parentDir - wallsbotDir = currentSourcePath().parentDir.parentDir.parentDir / - "common_libs" / "test_framework" / "adversaries" / "WallsBot" + snnbotDir = currentSourcePath().parentDir.parentDir + +let wallsbotDir = sampleBotsDir / "Walls" let r = runBattle(@[snnbotDir, wallsbotDir], rounds = 10) diff --git a/common_libs/test_framework/test_framework.nim b/common_libs/test_framework/test_framework.nim index 341a3a6..ac732dd 100644 --- a/common_libs/test_framework/test_framework.nim +++ b/common_libs/test_framework/test_framework.nim @@ -12,10 +12,10 @@ export battle_result.RoundResult export battle_result.BotRoundResult proc runBattle*(botDirs: seq[string], rounds: int = 10, - timeout: int = 120000): BattleResult = + timeout: int = 120000, maxSpeed: bool = true): BattleResult = ensureServer() discard compileBots(botDirs) - let stdout = runBattleRunner(getServerUrl(), botDirs, rounds, timeout) + let stdout = runBattleRunner(getServerUrl(), botDirs, rounds, timeout, maxSpeed) result = parseServerOutput(stdout) when isMainModule: @@ -26,7 +26,8 @@ when isMainModule: echo " let r = runBattle(@[\"path/to/BotA\", \"path/to/BotB\"])" echo " echo r.winners" echo "" - echo "Env vars forwarded to sub-modules:" + echo "Env vars:" echo " TR_SERVER_JAR TR server JAR path" echo " TR_BATTLE_RUNNER BattleRunner JAR path" echo " TR_BATTLE_RUNNER_DIR BattleRunner class dir" + echo " TR_SAMPLE_BOTS Directory containing sample bots (e.g. Walls, Fire, SpinBot)"