feat(ModularBot): 6 guns, pattern matcher, melee modules, adversarial bots
- 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
This commit is contained in:
Executable
BIN
Binary file not shown.
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
cd "$(dirname "$0")"
|
||||
exec ./out/ModularBot >> /tmp/modularbot_stdout.log 2>> /tmp/modularbot_stderr.log
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "ModularBot",
|
||||
"version": "0.1.0",
|
||||
"authors": ["Davide Cappellini"],
|
||||
"description": "Plugin gun architecture — head-on gun via virtual bullet harness",
|
||||
"homepage": "",
|
||||
"countryCodes": ["IT"],
|
||||
"gameTypes": ["classic", "1v1"],
|
||||
"platform": "Nim",
|
||||
"programmingLang": "Nim"
|
||||
}
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
cd "$(dirname "$0")"
|
||||
exec ./out/ModularBot >> /tmp/modularbot_stdout.log 2>> /tmp/modularbot_stderr.log
|
||||
@@ -1,5 +1,5 @@
|
||||
## ModularBot — plugin gun architecture tracer bullet.
|
||||
## Guns: HeadOnGun (0), LinearGun (1), TsetlinGun (2), CircularGun (3) via GunHarness.
|
||||
## Guns: HeadOnGun (0), LinearGun (1), TsetlinGun (2), CircularGun (3), GFGun (4), PatternMatcherGun (5) via GunHarness.
|
||||
## Radar: RadarLockModule via radar harness.
|
||||
## Movement: OscillatorModule (perpendicular strafing).
|
||||
|
||||
@@ -14,12 +14,14 @@ import guns/head_on
|
||||
import guns/linear
|
||||
import guns/circular
|
||||
import guns/tsetlin
|
||||
import guns/guess_factor
|
||||
import guns/pattern_matcher
|
||||
import movements/phantom_meteor
|
||||
|
||||
const botJsonPath = currentSourcePath().parentDir / "ModularBot.json"
|
||||
const DebugVBullets = false
|
||||
const DebugCircular = false
|
||||
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular"]
|
||||
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern"]
|
||||
|
||||
type
|
||||
ModularBot = ref object of Bot
|
||||
@@ -32,6 +34,8 @@ type
|
||||
linear: LinearGun
|
||||
circular: CircularGun
|
||||
tsetlin: TsetlinGun
|
||||
guessFactor: GFGun
|
||||
patternMatcher: PatternMatcherGun
|
||||
mover: PhantomMeteorModule
|
||||
virtualHits: int
|
||||
virtualMiss: int
|
||||
@@ -66,16 +70,24 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
|
||||
var linPreds: array[len(PowerBins), GunPrediction]
|
||||
var tmPreds: array[len(PowerBins), GunPrediction]
|
||||
var circPreds: array[len(PowerBins), GunPrediction]
|
||||
var gfPreds: array[len(PowerBins), GunPrediction]
|
||||
var pmPreds: array[len(PowerBins), GunPrediction]
|
||||
for i in 0..<len(PowerBins):
|
||||
headsUp[i] = bot.headOn.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
linPreds[i] = bot.linear.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
tmPreds[i] = bot.tsetlin.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
circPreds[i] = bot.circular.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
gfPreds[i] = bot.guessFactor.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
pmPreds[i] = bot.patternMatcher.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
|
||||
bot.tracker.spawnBullets(0, headsUp, bot.lastState)
|
||||
bot.tracker.spawnBullets(1, linPreds, bot.lastState)
|
||||
bot.tracker.spawnBullets(2, tmPreds, bot.lastState)
|
||||
# Skip TM virtual bullets during warmup so cold predictions don't hurt its fitness window
|
||||
if bot.tsetlin.isWarmedUp():
|
||||
bot.tracker.spawnBullets(2, tmPreds, bot.lastState)
|
||||
bot.tracker.spawnBullets(3, circPreds, bot.lastState)
|
||||
bot.tracker.spawnBullets(4, gfPreds, bot.lastState)
|
||||
bot.tracker.spawnBullets(5, pmPreds, bot.lastState)
|
||||
|
||||
# Resolve bullets that have travelled far enough
|
||||
let st = bot.lastState
|
||||
@@ -90,6 +102,8 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
|
||||
let ax = st.enemyX
|
||||
let ay = st.enemyY
|
||||
echo fmt"[circ-vb] predicted=({fe.prediction.x:.0f},{fe.prediction.y:.0f}) actual=({ax:.0f},{ay:.0f}) miss={fe.missDistance:.1f}px hit={fe.hit}"
|
||||
of 4: bot.guessFactor.onResult(fe)
|
||||
of 5: bot.patternMatcher.onResult(fe)
|
||||
else: discard
|
||||
if fe.hit: inc bot.virtualHits else: inc bot.virtualMiss
|
||||
when DebugVBullets:
|
||||
@@ -110,12 +124,16 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
|
||||
of 1: setTurretColor("#3366FF"); setBulletColor("#6699FF") # Linear: electric blue
|
||||
of 2: setTurretColor("#9933FF"); setBulletColor("#CC66FF") # Tsetlin: violet
|
||||
of 3: setTurretColor("#33CC33"); setBulletColor("#66FF66") # Circular: emerald
|
||||
of 4: setTurretColor("#FFCC00"); setBulletColor("#FFE066") # GuessFactor: yellow
|
||||
of 5: setTurretColor("#FF6600"); setBulletColor("#FF9944") # Pattern: orange
|
||||
else: discard
|
||||
|
||||
let pred = case selectedGun
|
||||
of 1: bot.linear.predict(bot.lastState, bulletSpeed(power))
|
||||
of 2: bot.tsetlin.predict(bot.lastState, bulletSpeed(power))
|
||||
of 3: bot.circular.predict(bot.lastState, bulletSpeed(power))
|
||||
of 4: bot.guessFactor.predict(bot.lastState, bulletSpeed(power))
|
||||
of 5: bot.patternMatcher.predict(bot.lastState, bulletSpeed(power))
|
||||
else: bot.headOn.predict(bot.lastState, bulletSpeed(power))
|
||||
let target = aimAngle(getX(), getY(), pred.x, pred.y)
|
||||
|
||||
@@ -175,11 +193,13 @@ method run*(bot: ModularBot) =
|
||||
|
||||
when isMainModule:
|
||||
var bot = ModularBot(
|
||||
tracker: vb.initTracker(4), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular
|
||||
tracker: vb.initTracker(6), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern
|
||||
headOn: HeadOnGun(),
|
||||
linear: LinearGun(),
|
||||
circular: CircularGun(),
|
||||
tsetlin: initTsetlinGun(),
|
||||
guessFactor: initGFGun(),
|
||||
patternMatcher: PatternMatcherGun(),
|
||||
radar: RadarLockModule(),
|
||||
mover: initPhantomMeteor(),
|
||||
currentGun: -1,
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
## 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 ""
|
||||
Reference in New Issue
Block a user