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
This commit is contained in:
@@ -0,0 +1 @@
|
||||
--path:"../../common_libs"
|
||||
@@ -0,0 +1,32 @@
|
||||
import std/[os, strutils]
|
||||
import test_framework/test_framework
|
||||
import test_framework/battle_result
|
||||
import test_framework/server_manager
|
||||
import test_framework/bot_compiler
|
||||
import test_framework/runner_process
|
||||
|
||||
const
|
||||
modularBotDir = currentSourcePath().parentDir.parentDir
|
||||
tfAdversaries = currentSourcePath().parentDir.parentDir.parentDir /
|
||||
"common_libs" / "test_framework" / "adversaries"
|
||||
sittingDuck = tfAdversaries / "SittingDuck"
|
||||
|
||||
# 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)
|
||||
|
||||
# Compile bots
|
||||
let compiledBots = compileBots(@[modularBotDir, sittingDuck])
|
||||
echo "Compiled bots: ", compiledBots
|
||||
|
||||
# Run battle
|
||||
ensureServer()
|
||||
let stdout = runBattleRunner(getServerUrl(), @[modularBotDir, sittingDuck], 3, 300000, true)
|
||||
echo ""
|
||||
echo "Raw battle runner output (last 50 lines):"
|
||||
let lines = stdout.split('\n')
|
||||
let start = max(0, lines.len - 50)
|
||||
for i in start..<lines.len:
|
||||
echo lines[i]
|
||||
@@ -0,0 +1,58 @@
|
||||
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
|
||||
@@ -0,0 +1,24 @@
|
||||
import std/os
|
||||
import std/strutils
|
||||
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)
|
||||
|
||||
let modularBotDir = "/home/davide/Projects/SirRoboGarage/ModularBot_garage"
|
||||
let sampleBotsDir = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
|
||||
|
||||
echo "\n=== BATTLE 1: ModularBot vs SpinBot (Circular Movement) ==="
|
||||
let r1 = runBattle(@[modularBotDir, sampleBotsDir / "SpinBot"], rounds = 10)
|
||||
echo "\nBattle 1 Results:"
|
||||
for bot in r1.results:
|
||||
echo " " & bot.name & ": score=" & $bot.totalScore & " rank=" & $bot.rank
|
||||
echo "Winners: " & r1.winners.join(", ")
|
||||
|
||||
echo "\n=== BATTLE 2: ModularBot vs Crazy (Unpredictable Movement) ==="
|
||||
let r2 = runBattle(@[modularBotDir, sampleBotsDir / "Crazy"], rounds = 10)
|
||||
echo "\nBattle 2 Results:"
|
||||
for bot in r2.results:
|
||||
echo " " & bot.name & ": score=" & $bot.totalScore & " rank=" & $bot.rank
|
||||
echo "Winners: " & r2.winners.join(", ")
|
||||
@@ -0,0 +1,36 @@
|
||||
import std/os
|
||||
import std/strutils
|
||||
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)
|
||||
|
||||
let modularBotDir = "/home/davide/Projects/SirRoboGarage/ModularBot_garage"
|
||||
let sampleBotsDir = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
|
||||
|
||||
echo "\n" & "=".repeat(60)
|
||||
echo "BATTLE 1: ModularBot vs SpinBot (Circular Movement)"
|
||||
echo "=".repeat(60)
|
||||
let r1 = runBattle(@[modularBotDir, sampleBotsDir / "SpinBot"], rounds = 10)
|
||||
echo "\nRound Details:"
|
||||
for i, round in r1.rounds:
|
||||
echo " Round " & $i & ":"
|
||||
for bot in round.results:
|
||||
echo " " & bot.name & ": score=" & $bot.score & " rank=" & $bot.rank & " survived=" & $bot.survived
|
||||
echo "\nFinal Scores:"
|
||||
for bot in r1.results:
|
||||
echo " " & bot.name & ": score=" & $bot.totalScore & " rank=" & $bot.rank & " firstPlaces=" & $bot.firstPlaces & " survived=" & $bot.survivalCount
|
||||
|
||||
echo "\n" & "=".repeat(60)
|
||||
echo "BATTLE 2: ModularBot vs Crazy (Unpredictable Movement)"
|
||||
echo "=".repeat(60)
|
||||
let r2 = runBattle(@[modularBotDir, sampleBotsDir / "Crazy"], rounds = 10)
|
||||
echo "\nRound Details:"
|
||||
for i, round in r2.rounds:
|
||||
echo " Round " & $i & ":"
|
||||
for bot in round.results:
|
||||
echo " " & bot.name & ": score=" & $bot.score & " rank=" & $bot.rank & " survived=" & $bot.survived
|
||||
echo "\nFinal Scores:"
|
||||
for bot in r2.results:
|
||||
echo " " & bot.name & ": score=" & $bot.totalScore & " rank=" & $bot.rank & " firstPlaces=" & $bot.firstPlaces & " survived=" & $bot.survivalCount
|
||||
@@ -0,0 +1,34 @@
|
||||
import std/os
|
||||
import std/strutils
|
||||
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)
|
||||
|
||||
let modularBotDir = "/home/davide/Projects/SirRoboGarage/ModularBot_garage"
|
||||
let sampleBotsDir = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
|
||||
|
||||
echo "\n" & "=".repeat(60)
|
||||
echo "BATTLE 1: ModularBot vs SpinBot (Circular Movement)"
|
||||
echo "=".repeat(60)
|
||||
let r1 = runBattle(@[modularBotDir, sampleBotsDir / "SpinBot"], rounds = 10)
|
||||
echo "\nFinal Scores:"
|
||||
for bot in r1.results:
|
||||
echo " " & bot.name & ": score=" & $bot.totalScore & " rank=" & $bot.rank & " firstPlaces=" & $bot.firstPlaces & " survived=" & $bot.survivalCount
|
||||
echo "Winner: " & r1.winners[0]
|
||||
|
||||
echo "\n" & "=".repeat(60)
|
||||
echo "BATTLE 2: ModularBot vs Crazy (Unpredictable Movement)"
|
||||
echo "=".repeat(60)
|
||||
let r2 = runBattle(@[modularBotDir, sampleBotsDir / "Crazy"], rounds = 10)
|
||||
echo "\nFinal Scores:"
|
||||
for bot in r2.results:
|
||||
echo " " & bot.name & ": score=" & $bot.totalScore & " rank=" & $bot.rank & " firstPlaces=" & $bot.firstPlaces & " survived=" & $bot.survivalCount
|
||||
echo "Winner: " & r2.winners[0]
|
||||
|
||||
echo "\n" & "=".repeat(60)
|
||||
echo "SUMMARY"
|
||||
echo "=".repeat(60)
|
||||
echo "Battle 1 (vs SpinBot): " & (if "ModularBot" in r1.winners: "WON" else: "LOST")
|
||||
echo "Battle 2 (vs Crazy): " & (if "ModularBot" in r2.winners: "WON" else: "LOST")
|
||||
@@ -0,0 +1,39 @@
|
||||
## Unit test for ModularBot gun selection
|
||||
import unittest
|
||||
import gun_harness/virtual_bullets as vb
|
||||
import gun_harness/selector
|
||||
import gun_harness/gun_interface
|
||||
|
||||
suite "Gun Selection":
|
||||
test "selector picks best gun and power":
|
||||
# Create a simple tracker with mock vbullets
|
||||
var t = initTracker(4)
|
||||
|
||||
# Spawn some bullets on gun 1 (linear) to simulate tracking history
|
||||
let state = WorldState(
|
||||
enemyX: 100, enemyY: 100, enemySpeed: 5.0, enemyHeading: 0.0,
|
||||
selfX: 50, selfY: 50, selfSpeed: 0.0, selfHeading: 0.0,
|
||||
selfRadarHeading: 0.0, selfEnergy: 100.0,
|
||||
arenaWidth: 800, arenaHeight: 600, tick: 1
|
||||
)
|
||||
|
||||
# Gun 1 (linear) predictions
|
||||
var linPreds: array[len(PowerBins), GunPrediction]
|
||||
for i in 0..<len(PowerBins):
|
||||
linPreds[i] = GunPrediction(x: 105.0 + i.float, y: 105.0 + i.float)
|
||||
|
||||
t.spawnBullets(1, linPreds, state)
|
||||
|
||||
# Simulate a hit on one of the linear gun bullets
|
||||
t.tickBullets(state, proc(gunId: GunId, binIdx: int, fe: FeedbackEvent) =
|
||||
if gunId == 1 and binIdx == 0:
|
||||
check fe.hit == false # Just verify callback works
|
||||
)
|
||||
|
||||
# Select best shot
|
||||
let (gunId, binIdx, power) = selectShot(t)
|
||||
|
||||
echo "[test] Selected gun=" & $gunId & " binIdx=" & $binIdx & " power=" & $power
|
||||
check gunId >= 0 and gunId < 4 # Should be one of 4 guns
|
||||
check binIdx >= 0 and binIdx < len(PowerBins) # Valid power bin
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import std/os
|
||||
import std/strutils
|
||||
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)
|
||||
|
||||
let modularBotDir = "/home/davide/Projects/SirRoboGarage/ModularBot_garage"
|
||||
let sampleBotsDir = "/home/davide/Downloads/robocode-tankroyale/sample-bots-nim-linux-1.0.7"
|
||||
|
||||
echo "\nSingle round: ModularBot vs SpinBot"
|
||||
let r = runBattle(@[modularBotDir, sampleBotsDir / "SpinBot"], rounds = 1)
|
||||
|
||||
for i, round in r.rounds:
|
||||
echo "\nRound " & $i & " details:"
|
||||
for bot in round.results:
|
||||
echo " " & bot.name & ": score=" & $bot.score & " survived=" & $bot.survived
|
||||
|
||||
echo "\nFinal: " & r.results[0].name & " " & $r.results[0].totalScore & " vs " & r.results[1].name & " " & $r.results[1].totalScore
|
||||
@@ -0,0 +1,70 @@
|
||||
import std/[os, unittest]
|
||||
import test_framework/test_framework
|
||||
import test_framework/battle_result
|
||||
import test_framework/server_manager
|
||||
import test_framework/bot_compiler
|
||||
import test_framework/runner_process
|
||||
|
||||
const
|
||||
modularBotDir = currentSourcePath().parentDir.parentDir
|
||||
tfAdversaries = currentSourcePath().parentDir.parentDir.parentDir /
|
||||
"common_libs" / "test_framework" / "adversaries"
|
||||
sittingDuck = tfAdversaries / "SittingDuck"
|
||||
|
||||
# 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)
|
||||
|
||||
suite "ModularBot basic battle":
|
||||
test "beats SittingDuck in 1 round":
|
||||
# Debug: manually compile and check
|
||||
try:
|
||||
let compiledBots = compileBots(@[modularBotDir, sittingDuck])
|
||||
echo "Compiled bots: ", compiledBots
|
||||
for bot in compiledBots:
|
||||
if fileExists(bot):
|
||||
echo " ✓ ", bot
|
||||
else:
|
||||
echo " ✗ MISSING: ", bot
|
||||
except CatchableError as e:
|
||||
echo "Compilation error: ", e.msg
|
||||
raise
|
||||
|
||||
# Now run battle with longer timeout for ModularBot boot
|
||||
ensureServer()
|
||||
let stdout = runBattleRunner(getServerUrl(), @[modularBotDir, sittingDuck], 1, 180000, true)
|
||||
echo ""
|
||||
echo "Raw battle runner output:"
|
||||
echo stdout
|
||||
echo ""
|
||||
|
||||
let r = parseServerOutput(stdout)
|
||||
|
||||
echo ""
|
||||
echo "=== Battle Result ==="
|
||||
echo "Rounds: ", r.rounds.len
|
||||
echo "Bots: ", r.bots
|
||||
echo ""
|
||||
echo "Final standings:"
|
||||
for result in r.results:
|
||||
echo " ", result.name, ": rank=", result.rank, " score=", result.totalScore,
|
||||
" survived=", result.survivalCount, " first=", result.firstPlaces
|
||||
echo ""
|
||||
echo "Winners: ", r.winners
|
||||
echo ""
|
||||
|
||||
# Basic checks
|
||||
check r.rounds.len == 1
|
||||
check r.results.len == 2
|
||||
check "ModularBot" in r.bots
|
||||
check "SittingDuck" in r.bots
|
||||
|
||||
# ModularBot should win
|
||||
var modularResult: BotResult
|
||||
for b in r.results:
|
||||
if b.name == "ModularBot": modularResult = b
|
||||
check modularResult.name == "ModularBot"
|
||||
check modularResult.rank == 1
|
||||
check "ModularBot" in r.winners
|
||||
Reference in New Issue
Block a user