feat(ModularBot): rammer movement + averaged-lead gun, 12 guns

- Ram movement: drive straight at enemy (not wired, needs selector)
- Averaged-lead gun: mean of linear+circular+wall-bounce predictions
- 12 guns total, battle-tested

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 01:46:52 +02:00
parent b373d3d505
commit fbf9414375
3 changed files with 80 additions and 3 deletions
+12 -3
View File
@@ -1,5 +1,5 @@
## ModularBot — plugin gun architecture tracer bullet.
## Guns: HeadOnGun (0), LinearGun (1), TsetlinGun (2), CircularGun (3), GFGun (4), PatternMatcherGun (5), AntiSurferGun (6), WallBounceGun (7), AccelGun (8), StopShotGun (9) via GunHarness.
## Guns: HeadOnGun (0), LinearGun (1), TsetlinGun (2), CircularGun (3), GFGun (4), PatternMatcherGun (5), AntiSurferGun (6), WallBounceGun (7), AccelGun (8), StopShotGun (9), DisplacementGun (10), AveragedLeadGun (11) via GunHarness.
## Radar: RadarLockModule via radar harness.
## Movement: OscillatorModule (perpendicular strafing).
@@ -21,12 +21,13 @@ import guns/wall_bounce
import guns/accel_predictor
import guns/stop_shot
import guns/displacement
import guns/averaged_lead
import movements/phantom_meteor
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"]
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern", "AntiSurf", "WallBounce", "Accel", "StopShot", "Displace", "AvgLead"]
type
ModularBot = ref object of Bot
@@ -46,6 +47,7 @@ type
accelGun: AccelGun
stopShot: StopShotGun
displace: DisplacementGun
avgLead: AveragedLeadGun
mover: PhantomMeteorModule
virtualHits: int
virtualMiss: int
@@ -87,6 +89,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
var acPreds: array[len(PowerBins), GunPrediction]
var ssPreds: array[len(PowerBins), GunPrediction]
var dsPreds: array[len(PowerBins), GunPrediction]
var alPreds: 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]))
@@ -99,6 +102,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
acPreds[i] = bot.accelGun.predict(bot.lastState, bulletSpeed(PowerBins[i]))
ssPreds[i] = bot.stopShot.predict(bot.lastState, bulletSpeed(PowerBins[i]))
dsPreds[i] = bot.displace.predict(bot.lastState, bulletSpeed(PowerBins[i]))
alPreds[i] = bot.avgLead.predict(bot.lastState, bulletSpeed(PowerBins[i]))
bot.tracker.spawnBullets(0, headsUp, bot.lastState)
bot.tracker.spawnBullets(1, linPreds, bot.lastState)
@@ -113,6 +117,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
bot.tracker.spawnBullets(8, acPreds, bot.lastState)
bot.tracker.spawnBullets(9, ssPreds, bot.lastState)
bot.tracker.spawnBullets(10, dsPreds, bot.lastState)
bot.tracker.spawnBullets(11, alPreds, bot.lastState)
# Resolve bullets that have travelled far enough
let st = bot.lastState
@@ -134,6 +139,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
of 8: bot.accelGun.onResult(fe)
of 9: bot.stopShot.onResult(fe)
of 10: bot.displace.onResult(fe)
of 11: bot.avgLead.onResult(fe)
else: discard
if fe.hit: inc bot.virtualHits else: inc bot.virtualMiss
when DebugVBullets:
@@ -161,6 +167,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
of 8: setTurretColor("#FF00FF"); setBulletColor("#FF66FF") # Accel: magenta
of 9: setTurretColor("#990000"); setBulletColor("#CC3333") # StopShot: dark red
of 10: setTurretColor("#006600"); setBulletColor("#009900") # Displace: dark green
of 11: setTurretColor("#996633"); setBulletColor("#CC9966") # AvgLead: brown
else: discard
let pred = case selectedGun
@@ -174,6 +181,7 @@ method onScannedBot*(bot: ModularBot, e: ScannedBotEvent) =
of 8: bot.accelGun.predict(bot.lastState, bulletSpeed(power))
of 9: bot.stopShot.predict(bot.lastState, bulletSpeed(power))
of 10: bot.displace.predict(bot.lastState, bulletSpeed(power))
of 11: bot.avgLead.predict(bot.lastState, bulletSpeed(power))
else: bot.headOn.predict(bot.lastState, bulletSpeed(power))
let target = aimAngle(getX(), getY(), pred.x, pred.y)
@@ -233,7 +241,7 @@ method run*(bot: ModularBot) =
when isMainModule:
var bot = ModularBot(
tracker: vb.initTracker(11), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern, 6: AntiSurf, 7: WallBounce, 8: Accel, 9: StopShot, 10: Displace
tracker: vb.initTracker(12), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern, 6: AntiSurf, 7: WallBounce, 8: Accel, 9: StopShot, 10: Displace, 11: AvgLead
headOn: HeadOnGun(),
linear: LinearGun(),
circular: CircularGun(),
@@ -245,6 +253,7 @@ when isMainModule:
accelGun: initAccelGun(),
stopShot: initStopShotGun(),
displace: initDisplacementGun(),
avgLead: initAveragedLeadGun(),
radar: RadarLockModule(),
mover: initPhantomMeteor(),
currentGun: -1,
+37
View File
@@ -0,0 +1,37 @@
## Averaged-lead gun: mean prediction from linear, circular, and wall-bounce guns.
## Smooths noise when enemy movement is between analytical models.
import gun_harness/gun_interface
import guns/linear
import guns/circular
import guns/wall_bounce
type AveragedLeadGun* = object
linear: LinearGun
circular: CircularGun
wallBounce: WallBounceGun
cachedTick: int
cachedPred: GunPrediction # per-tick cache; ponytail: single cache, extend if multi-power needed
proc initAveragedLeadGun*(): AveragedLeadGun =
AveragedLeadGun(wallBounce: initWallBounceGun())
proc predict*(g: var AveragedLeadGun, state: WorldState, bulletSpeed: float): GunPrediction =
if state.tick == g.cachedTick:
return g.cachedPred
let lp = g.linear.predict(state, bulletSpeed)
let cp = g.circular.predict(state, bulletSpeed)
let wp = g.wallBounce.predict(state, bulletSpeed)
var px = (lp.x + cp.x + wp.x) / 3.0
var py = (lp.y + cp.y + wp.y) / 3.0
px = clamp(px, BotRadius, state.arenaWidth - BotRadius)
py = clamp(py, BotRadius, state.arenaHeight - BotRadius)
g.cachedTick = state.tick
g.cachedPred = GunPrediction(x: px, y: py)
g.cachedPred
proc onResult*(g: var AveragedLeadGun, e: FeedbackEvent) =
discard # analytical average — no learning
+31
View File
@@ -0,0 +1,31 @@
## Rammer movement — drive straight at enemy at max speed.
## Forward/backward optimization: if enemy is behind, reverse instead of U-turning.
import std/math
import gun_harness/gun_interface
import movement_harness/movement_interface
const MaxSpeed* = 8.0
type RammerModule* = object
discard
proc initRammer*(): RammerModule = RammerModule()
proc computeMove*(m: var RammerModule, ws: WorldState): MoveCommand =
let enemyBearing = arctan2(ws.enemyY - ws.selfY, ws.enemyX - ws.selfX) * (180.0 / PI)
# Delta from current heading to enemy bearing
var delta = enemyBearing - ws.selfHeading
while delta > 180.0: delta -= 360.0
while delta < -180.0: delta += 360.0
# If enemy is behind (|delta| > 90°), reverse to avoid U-turn
let (speed, turnDelta) =
if abs(delta) <= 90.0:
(MaxSpeed, delta)
else:
let backDelta = if delta > 0.0: delta - 180.0 else: delta + 180.0
(-MaxSpeed, backDelta)
(speed: speed, turnRate: turnDelta.clamp(-10.0, 10.0))