feat(movement): dodge timing, wall avoidance, distance control, ram finisher

PhantomMeteor:
- Ram finisher: charge at enemy when <200px and their energy <10
- Ram opportunity: charge when <60px and we have >20 energy advantage
- Integrated gunheat tracker for 1-2 tick earlier wave detection
- Distance control: smooth linear ramp toward preferred engagement distance
- Phantom range expanded 150→250px to catch closer threats

WaveSurfer:
- Wall-aware dodge bin selection: penalize bins leading off-arena
- Dodge timing: predict future position 15 ticks ahead for safety
- Distance control: radial blend when outside deadband (350±50px)
- Wall escape: invert strafe if pushing further into wall, blend toward center

ModularBot:
- Wired KNN gun (purple/magenta)
- Shadows tracked for movement (safer GF prediction)
- Bullet lifecycle management (onBulletFired/onBulletHitBot/onBulletHitWall)
- Unified phantom_meteor movement (wave_surfer unplugged)
- Config logging on round start + gun switch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 11:59:05 +02:00
parent 5bbc8cbda7
commit 30d00ba163
3 changed files with 169 additions and 57 deletions
+40 -33
View File
@@ -23,20 +23,22 @@ import guns/stop_shot
import guns/displacement
import guns/averaged_lead
import guns/decay_gf
import guns/knn_gun
import movements/phantom_meteor
import movements/wave_surfer
import movement_harness/virtual_bodies as mvb
import movement_harness/bullet_shadows
const botJsonPath = currentSourcePath().parentDir / "ModularBot.json"
const DebugVBullets = false
const DebugCircular = false
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern", "AntiSurf", "WallBounce", "Accel", "StopShot", "Displace", "AvgLead", "DecayGF"]
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern", "AntiSurf", "WallBounce", "Accel", "StopShot", "Displace", "AvgLead", "DecayGF", "KNN"]
const
CLR_GUN = "\e[33m" # yellow
CLR_MOVE = "\e[36m" # cyan
CLR_FIRE = "\e[31m" # red
CLR_RADAR = "\e[32m" # green
CLR_CHANGE = "\e[32m" # green (highlight for changed module)
CLR_ROUND = "\e[1;37m" # bold white
CLR_RST = "\e[0m" # reset
@@ -60,15 +62,20 @@ type
displace: DisplacementGun
avgLead: AveragedLeadGun
decayGF: DecayGFGun
knnGun: KNNGun
mover: PhantomMeteorModule
waveMover: WaveSurferModule
movementId: int ## 0=phantom, 1=waveSurf
moveTracker: VirtualBodyTracker
virtualHits: int
virtualMiss: int
tick: int
currentGun: int
proc printConfig(bot: ModularBot, changed: string = "") =
let gunName = GunNames[bot.currentGun]
let gunColor = if changed == "gun" or changed == "all": CLR_CHANGE else: CLR_RST
let radarColor = if changed == "radar" or changed == "all": CLR_CHANGE else: CLR_RST
echo CLR_ROUND & "[config]" & CLR_RST & " " & gunColor & "gun=" & gunName & CLR_RST & " | " & CLR_MOVE & "move=phantom_meteor" & CLR_RST & " | " & radarColor & "radar=radar_lock" & CLR_RST
proc buildState(bot: ModularBot, ex, ey, espeed, eheading, eenergy: float): WorldState =
WorldState(
enemyX: ex,
@@ -106,6 +113,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
var dsPreds: array[len(PowerBins), GunPrediction]
var alPreds: array[len(PowerBins), GunPrediction]
var dgPreds: array[len(PowerBins), GunPrediction]
var knnPreds: 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]))
@@ -120,6 +128,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
dsPreds[i] = bot.displace.predict(bot.lastState, bulletSpeed(PowerBins[i]))
alPreds[i] = bot.avgLead.predict(bot.lastState, bulletSpeed(PowerBins[i]))
dgPreds[i] = bot.decayGF.predict(bot.lastState, bulletSpeed(PowerBins[i]))
knnPreds[i] = bot.knnGun.predict(bot.lastState, bulletSpeed(PowerBins[i]))
bot.tracker.spawnBullets(0, headsUp, bot.lastState)
bot.tracker.spawnBullets(1, linPreds, bot.lastState)
@@ -136,6 +145,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
bot.tracker.spawnBullets(10, dsPreds, bot.lastState)
bot.tracker.spawnBullets(11, alPreds, bot.lastState)
bot.tracker.spawnBullets(12, dgPreds, bot.lastState)
bot.tracker.spawnBullets(13, knnPreds, bot.lastState)
# Resolve bullets that have travelled far enough
let st = bot.lastState
@@ -159,6 +169,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
of 10: bot.displace.onResult(fe)
of 11: bot.avgLead.onResult(fe)
of 12: bot.decayGF.onResult(fe)
of 13: bot.knnGun.onResult(fe)
else: discard
if fe.hit: inc bot.virtualHits else: inc bot.virtualMiss
when DebugVBullets:
@@ -172,8 +183,8 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
# Log gun switch + update turret/bullet colors
if selectedGun != bot.currentGun:
echo CLR_GUN & fmt"[gun] switched: {GunNames[selectedGun]}" & CLR_RST
bot.currentGun = selectedGun
bot.printConfig("gun")
case selectedGun
of 0: setTurretColor("#FF3333"); setBulletColor("#FF6666") # HeadOn: warm red
of 1: setTurretColor("#3366FF"); setBulletColor("#6699FF") # Linear: electric blue
@@ -188,6 +199,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
of 10: setTurretColor("#006600"); setBulletColor("#009900") # Displace: dark green
of 11: setTurretColor("#996633"); setBulletColor("#CC9966") # AvgLead: brown
of 12: setTurretColor("#008888"); setBulletColor("#00AAAA") # DecayGF: dark cyan
of 13: setTurretColor("#CC00CC"); setBulletColor("#FF44FF") # KNN: purple/magenta
else: discard
let pred = case selectedGun
@@ -203,6 +215,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
of 10: bot.displace.predict(bot.lastState, bulletSpeed(power))
of 11: bot.avgLead.predict(bot.lastState, bulletSpeed(power))
of 12: bot.decayGF.predict(bot.lastState, bulletSpeed(power))
of 13: bot.knnGun.predict(bot.lastState, bulletSpeed(power))
else: bot.headOn.predict(bot.lastState, bulletSpeed(power))
let target = aimAngle(getX(), getY(), pred.x, pred.y)
@@ -220,14 +233,24 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
setGunTurnRate(normDelta)
method onBulletFired*(bot: ModularBot, e: BulletFiredEvent) =
bot.moveTracker.shadows.addBullet(e.bullet.x, e.bullet.y,
degToRad(e.bullet.direction), e.bullet.power)
method onBulletHitBot*(bot: ModularBot, e: BulletHitBotEvent) =
bot.moveTracker.shadows.removeBulletNear(e.bullet.x, e.bullet.y)
method onBulletHitWall*(bot: ModularBot, e: BulletHitWallEvent) =
bot.moveTracker.shadows.removeBulletNear(e.bullet.x, e.bullet.y)
method onBulletHitBullet*(bot: ModularBot, e: BulletHitBulletEvent) =
bot.moveTracker.shadows.removeBulletNear(e.bullet.x, e.bullet.y)
method onHitByBullet*(bot: ModularBot, e: HitByBulletEvent) =
bot.moveTracker.registerHit(e.bullet.power, e.bullet.direction, getX(), getY())
method onRoundEnded*(bot: ModularBot, e: RoundEndedEventForBot) =
let newId = bot.moveTracker.bestMovement()
if newId != bot.movementId:
echo CLR_MOVE & "[move] switching: " & (if newId == 0: "phantom_meteor" else: "wave_surfer") & CLR_RST
bot.movementId = newId
discard
method onRoundStarted*(bot: ModularBot, e: RoundStartedEvent) =
setAdjustGunForBodyTurn(true)
@@ -235,22 +258,15 @@ method onRoundStarted*(bot: ModularBot, e: RoundStartedEvent) =
setAdjustRadarForGunTurn(true)
setRadarColor("#004444") # RadarLock: dark teal, faint without alpha
setScanColor("#0D4D4D") # RadarLock scan arc: very dark teal, faint without alpha
setBodyColor("#FF9900") # PhantomMeteor: deep orange/gold
bot.radar.init()
bot.mover.resetRound()
bot.hasContact = false
bot.tick = 0
bot.currentGun = -1
bot.moveTracker.resetRound(getX(), getY(), getDirection(), getSpeed())
if bot.movementId == 0:
bot.mover.resetRound()
setBodyColor("#FF9900") # PhantomMeteor: deep orange/gold
echo CLR_MOVE & "[move] using phantom_meteor" & CLR_RST
else:
bot.waveMover.resetRound()
setBodyColor("#0099FF") # WaveSurfer: blue
echo CLR_MOVE & "[move] using wave_surfer" & CLR_RST
echo CLR_GUN & fmt"[gun] starting: {GunNames[0]}" & CLR_RST
bot.currentGun = 0
bot.printConfig("all")
# tracker fitness persists across rounds (rolling window carries over)
method onGameStarted*(bot: ModularBot, e: GameStartedEventForBot) =
@@ -267,24 +283,15 @@ method run*(bot: ModularBot) =
go()
continue
# Movement harness: compute all, feed tracker, apply active
let phantomCmd = bot.mover.computeMove(bot.lastState)
let waveSurfCmd = bot.waveMover.computeMove(bot.lastState)
bot.moveTracker.tick(bot.lastState, [phantomCmd, waveSurfCmd])
let activeId = bot.moveTracker.bestMovement()
if activeId != bot.movementId:
bot.movementId = activeId
echo CLR_MOVE & "[move] switched to: " & (if activeId == 0: "phantom_meteor" else: "wave_surfer") & CLR_RST
let (spd, tr) = if bot.movementId == 0: phantomCmd else: waveSurfCmd
let (spd, tr) = bot.mover.computeMove(bot.lastState)
setTargetSpeed(spd)
setTurnRate(tr)
setRadarTurnRate(bot.radar.computeScan(bot.lastState))
go()
when isMainModule:
var bot = ModularBot(
tracker: vb.initTracker(13), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern, 6: AntiSurf, 7: WallBounce, 8: Accel, 9: StopShot, 10: Displace, 11: AvgLead, 12: DecayGF
tracker: vb.initTracker(14), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern, 6: AntiSurf, 7: WallBounce, 8: Accel, 9: StopShot, 10: Displace, 11: AvgLead, 12: DecayGF, 13: KNN
headOn: HeadOnGun(),
linear: LinearGun(),
circular: CircularGun(),
@@ -298,10 +305,10 @@ when isMainModule:
displace: initDisplacementGun(),
avgLead: initAveragedLeadGun(),
decayGF: initDecayGFGun(),
knnGun: initKNNGun(),
radar: RadarLockModule(),
mover: initPhantomMeteor(),
waveMover: initWaveSurfer(),
moveTracker: mvb.initVirtualBodyTracker(2), # 0=phantom, 1=waveSurf
moveTracker: mvb.initVirtualBodyTracker(1),
currentGun: -1,
)
start(bot, botJsonPath)