## Regression test: radar lock must hold on a stationary target. ## Run: nim c -r tests/test_radar_lock.nim import std/[math, strformat] import PPO_Bot/enemy_tracker template check(cond: bool, msg: string) = if not cond: quit("FAIL: " & msg, 1) # Bot at arena center; stationary enemy due north (same x, higher y). # Tank Royale: y increases northward. # Radar uses math convention (0°=east, CCW+); north = 90° in that system. let botX = 400.0 let botY = 300.0 let enemyX = 400.0 # same x → dx = 0 let enemyY = 500.0 # north of bot → dy > 0 let trueBearing = 90.0 # north in math convention (0=east, CCW+) # Radar starts pointing at the enemy (radarDirection = 90°, due north in math convention). var radarDir = 90.0 var tracker = initEnemyTracker() # Prime with contact at the known position tracker.update(enemyX, enemyY, 0.0, 0.0, 100.0) echo "Tick | radarDir | trueBearing | bearingErr" for tick in 1 .. 20: let rate = tracker.getRadarTurnRate(botX, botY, 0.0, radarDir) radarDir = (radarDir + rate + 360.0) mod 360.0 # Simulate a successful scan every tick (enemy is stationary) tracker.update(enemyX, enemyY, 0.0, 0.0, 100.0) # Bearing error: signed difference, wrapped to [-180, 180] let err = ((radarDir - trueBearing) + 540.0) mod 360.0 - 180.0 echo &" {tick:2d} | {radarDir:8.3f}° | {trueBearing:8.3f}° | {err:+.3f}°" check abs(err) <= 15.0, &"tick {tick}: radar {radarDir:.1f}° drifted > 15° from target {trueBearing:.1f}°" echo "All radar lock tests passed"