From a024a2e32b5d98068e77b841a713b64869452541 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Tue, 6 Oct 2026 08:28:15 +0200 Subject: [PATCH] =?UTF-8?q?DevControlBot:=20fix=20gun=20plumbing=20?= =?UTF-8?q?=E2=80=94=20detach=20from=20body=20turn,=20non-blocking=20fire,?= =?UTF-8?q?=20degree=20slop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gun turn math is written for setAdjustGunForBodyTurn(true) (absolute bearing -> normalizeRelativeAngle(bearing - getGunDirection())), but the flag was never set: the gun inherited the body's turn. Set the three adjust flags. Two firing bugs found while measuring the geometric baseline against a stationary SittingDuck: - computeGun called the BLOCKING fire(), which calls go() itself, and the run loop called go() again => every shot double-stepped the server. Use setFire. - the fire slop compared a degrees error against degToRad(FireSlopDeg) = 0.052 deg. Compare in degrees; 1 deg (3 deg fired mid-slew, up to 3 deg off). Baseline vs stationary: 110/112 hits, aim error sd 0.04 deg. --- .../DevControlBot/DevControlBot.nim | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/DevControlBot_garage/DevControlBot/DevControlBot.nim b/DevControlBot_garage/DevControlBot/DevControlBot.nim index ddf0c86..450f96d 100644 --- a/DevControlBot_garage/DevControlBot/DevControlBot.nim +++ b/DevControlBot_garage/DevControlBot/DevControlBot.nim @@ -46,10 +46,15 @@ const EnemyStaleTicks* = 60 ## drop a scanned enemy not rescanned for this m # which is what makes the measured difference attributable. const UseElm* = not defined(baselineGun) -const FireSlopDeg = 3.0'f64 ## fire inside this much gun error. The gun turns - ## at most MAX_GUN_TURN_RATE, so a tighter slop - ## just means waiting a tick for no gain: at any - ## real range 3 deg is well under the hit radius. +const FireSlopDeg = 1.0'f64 ## fire inside this much gun error, in + ## DEGREES (the API's unit). + ## + ## Was 3.0 but compared against radians + ## (`degToRad(FireSlopDeg)` = 0.052 deg): fixing + ## the unit made the gun fire mid-slew, up to + ## 3 deg off, and cost hits. 1 deg is tight + ## enough that the shot is on target while + ## still firing the tick after a correction. type DevControlBot* = ref object of Bot mover: TfilModule @@ -161,9 +166,21 @@ proc computeGun(bot: DevControlBot) = ") age=", scanAge(scanTick), ") aimDeg=", radToDeg(aim.aim), " corr=", aim.correction, " gunDeg=", getGunDirection() let err = normalizeRelativeAngle(radToDeg(aim.aim) - getGunDirection()) - if abs(err) <= degToRad(FireSlopDeg): + # `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. + 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 + # only over-rotate the gun on the NEXT turn. Zeroing it keeps the gun on the + # aim point while it holds fire. + setGunTurnRate(0.0) if getGunHeat() == 0.0: - fire(FirePower) + # Non-blocking. `fire()` is the BLOCKING variant: it calls go() itself, so + # the outer loop's go() ran a second, empty turn - the bot double-stepped + # the server on every shot, desyncing tick/scan bookkeeping from the game. + discard setFire(FirePower) inc bot.shotsFired when defined(gunLog): # One line per shot: what the gun THOUGHT. The truth (the aim error it @@ -178,11 +195,13 @@ proc computeGun(bot: DevControlBot) = $(radToDeg(baseAim)) & "," & $(radToDeg(aim.aim)) & "," & $(getGunDirection()) & "," & buildFeatures(belief).mapIt($it).join(" ") & "\n") - setGunTurnRate(0.0) else: setGunTurnRate(err) method run*(bot: DevControlBot) = + setAdjustGunForBodyTurn(true) # turret ignores body rotation + setAdjustRadarForBodyTurn(true) # radar ignores body rotation + setAdjustRadarForGunTurn(true) # radar ignores turret rotation too initRadar() # once: radar + scan turn BLACK = programmed while isRunning(): # One radar command and one movement command per tick, unconditionally,