DevControlBot: an ELM gun, its geometric baseline, and an honest null result
Firing wired in behind a compile-time A/B switch (-d:baselineGun): both guns go through the same predictAim() call and differ only by the learned correction, so the measured difference is attributable. radar.nim now keeps the two most recent scans (velocity, scan age, own displacement). Measured over 20 recorded rounds each vs DrussGT, CassiusClay, Komarious and Phoenix: the ELM gun LOSES to the geometric baseline on three of four opponents (Phoenix 51.0% vs 99.5% hit rate). README has the table, the diagnosis and the two in-game-only bugs measuring exposed (degrees/radians, and features whose in-game range lies outside the corpus).
This commit is contained in:
@@ -58,9 +58,57 @@ var
|
||||
targetSeen: bool
|
||||
scanlessTicks: int
|
||||
|
||||
# ── scan history (added for the ELM gun) ─────────────────────────────────────
|
||||
# The gun needs THREE things the plain radar throws away: the previous scan (to
|
||||
# estimate the target's velocity), how many ticks ago the last scan was (the
|
||||
# dead-reckoning age), and how far WE moved in between (one of the 22 features).
|
||||
# The above variables alone cannot express any of them, so the two most recent
|
||||
# scans are kept here. Two is enough — a velocity from exactly two samples is
|
||||
# all the corpus model was fitted with (extract_realistic.py uses hist[-2..-1]).
|
||||
type ScanHistory* = object
|
||||
tick*: int ## tracker tick of the scan (scanlessTicks-free counter)
|
||||
x*, y*: float ## scanned position
|
||||
ownX*, ownY*: float ## OUR position on that same tick (for own displacement)
|
||||
|
||||
var
|
||||
scanTick*: int ## incremented once per commandRadar() call
|
||||
lastScan*, prevScan*: ScanHistory
|
||||
haveLast*, havePrev*: bool
|
||||
|
||||
proc onScanFull*(tick: int, x, y, ownX, ownY: float) =
|
||||
## Full-history variant of `onScan`, called by the bot. Shifts the scan
|
||||
## history instead of overwriting a single slot.
|
||||
prevScan = lastScan
|
||||
havePrev = haveLast
|
||||
lastScan = ScanHistory(tick: tick, x: x, y: y, ownX: ownX, ownY: ownY)
|
||||
haveLast = true
|
||||
|
||||
proc scanAge*(now: int): float =
|
||||
## Ticks since the last scan, or -1 when we have never scanned anything.
|
||||
if not haveLast: -1.0 else: float(now - lastScan.tick)
|
||||
|
||||
proc scanGap*(): float =
|
||||
## Ticks between the last two scans; 0 when there is no earlier scan (a
|
||||
## zero gap is what the corpus uses for "velocity unknown").
|
||||
if not (haveLast and havePrev): 0.0 else: float(lastScan.tick - prevScan.tick)
|
||||
|
||||
proc targetVelocity*(): tuple[vx, vy: float] =
|
||||
## px/tick, from the last two scans. (0,0) when there is no gap to measure
|
||||
## over — the corpus uses the same convention.
|
||||
if not (haveLast and havePrev): return (0.0, 0.0)
|
||||
let gap = lastScan.tick - prevScan.tick
|
||||
if gap <= 0: return (0.0, 0.0)
|
||||
((lastScan.x - prevScan.x) / float(gap), (lastScan.y - prevScan.y) / float(gap))
|
||||
|
||||
proc ownDisp*(selfX, selfY: float): float =
|
||||
## How far WE have moved since the last scan (0 if we never scanned).
|
||||
if not haveLast: 0.0 else: hypot(selfX - lastScan.ownX, selfY - lastScan.ownY)
|
||||
|
||||
proc onScan*(x, y: float) =
|
||||
## Remember a scanned bot as the target. Issues no command: `onScannedBot`
|
||||
## runs AFTER go() has already sent this tick's intent.
|
||||
## Kept for backward compatibility: it drives the radar's own lock, and the
|
||||
## bot calls `onScanFull` when it also wants the history.
|
||||
targetX = x
|
||||
targetY = y
|
||||
targetSeen = true
|
||||
@@ -80,6 +128,7 @@ proc initRadar*() =
|
||||
|
||||
proc commandRadar*() =
|
||||
## Command the radar for THIS tick. Called from run() before go().
|
||||
inc scanTick
|
||||
if targetSeen: inc scanlessTicks
|
||||
if getEnemyCount() == 1 and targetSeen and scanlessTicks <= FreshScanTurns:
|
||||
var turn = normalizeRelativeAngle(
|
||||
|
||||
Reference in New Issue
Block a user