diff --git a/DevControlBot_garage/DevControlBot/DevControlBot.nim b/DevControlBot_garage/DevControlBot/DevControlBot.nim index 4da6f55..1c653d4 100644 --- a/DevControlBot_garage/DevControlBot/DevControlBot.nim +++ b/DevControlBot_garage/DevControlBot/DevControlBot.nim @@ -40,6 +40,13 @@ const EnemyStaleTicks* = 60 ## drop a scanned enemy not rescanned for this m ## ticks (~1s at 60Hz): a bot seen once would keep ## painting its heat in the field forever +const MaxDeadReckonTicks* = 4 ## How far a constant-velocity guess may be + ## extrapolated past the last scan. The radar + ## lock re-scans almost every tick, so this only + ## bites when the target is genuinely lost: past + ## it, freeze at the last seen position rather + ## than let old vx/vy run the aim away. + # A/B switch, compile time: `-d:baselineGun` builds the geometric-only gun, the # default build is the ELM gun. Both go through the same predictAim() call, so # the two binaries differ by exactly the learned correction and nothing else — @@ -144,9 +151,11 @@ method buildBelief(bot: DevControlBot, power: float): GunBelief = result.winTick[k] = winTick[k] result.vx = vx result.vy = vy - # dead-reckon: last seen position advanced by the estimated velocity - result.ex = lastScan.x + vx * age - result.ey = lastScan.y + vy * age + # dead-reckon: last seen position advanced by the estimated velocity, but no + # farther than a constant-velocity guess stays credible (see the const). + let lead = min(age, float(MaxDeadReckonTicks)) + result.ex = lastScan.x + vx * lead + result.ey = lastScan.y + vy * lead result.power = power result.bulletSpeed = 20.0 - 3.0 * power result.gunHeat = getGunHeat() @@ -184,11 +193,11 @@ proc computeGun(bot: DevControlBot) = echo "[gun] t=", bot.tick, " self=(", getX(), ",", getY(), ") lastScan=(", lastScan.x, ",", lastScan.y, ") age=", scanAge(scanTick), ") aimDeg=", radToDeg(aim.aim), " corr=", aim.correction, " gunDeg=", getGunDirection() - let err = normalizeRelativeAngle(radToDeg(aim.aim) - getGunDirection()) - # `err` is DEGREES: normalizeRelativeAngle returns degrees and the API speaks - # degrees. Comparing it against degToRad(FireSlopDeg) meant "within 0.052 deg", - # not 3 deg - the gun withheld fire long after it was on target. Compare in the - # same unit. + let err = gunAimErrorDeg(aim.aim, getGunDirection()) + # `err` is DEGREES: gunAimErrorDeg is the single rad->deg conversion point and + # its name carries the unit, so `<= FireSlopDeg` can only compare degrees with + # degrees. (The old code compared a degree error against degToRad(FireSlopDeg) + # i.e. 0.052 deg of slop, and withheld fire far past the target.) if abs(err) <= FireSlopDeg: # Park the gun: the pending correction from the previous tick is applied # AFTER firing (TurnProcessor fires before executeBotIntents), so it would diff --git a/DevControlBot_garage/DevControlBot/modules/radar.nim b/DevControlBot_garage/DevControlBot/modules/radar.nim index e1a01ff..e089fdc 100644 --- a/DevControlBot_garage/DevControlBot/modules/radar.nim +++ b/DevControlBot_garage/DevControlBot/modules/radar.nim @@ -72,6 +72,12 @@ type ScanHistory* = object const ScanWinCap* = 8 ## motion-window length kept for the ELM gun +const MaxVelGap* = 3 ## ticks. Two scans farther apart than this give a + ## velocity that averages over too much motion to be + ## trusted; the corpus velocity is a one-tick delta, + ## so anything much wider is a different estimator and + ## worse than not extrapolating at all. + var scanTick*: int ## incremented once per commandRadar() call lastScan*, prevScan*: ScanHistory @@ -107,10 +113,11 @@ proc scanGap*(): float = 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. + ## over or the gap is too wide to be a trustworthy one-tick estimate — the + ## corpus uses the same (0,0) convention for "velocity unknown". if not (haveLast and havePrev): return (0.0, 0.0) let gap = lastScan.tick - prevScan.tick - if gap <= 0: return (0.0, 0.0) + if gap <= 0 or gap > MaxVelGap: return (0.0, 0.0) ((lastScan.x - prevScan.x) / float(gap), (lastScan.y - prevScan.y) / float(gap)) proc ownDisp*(selfX, selfY: float): float =