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
+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))