Files
SirRoboGarage/PPO_Bot/tests/test_radar_lock.nim
T
SirStone cdde60d79f feat(PPO_Bot): command abstraction layer — goto/aimTo controllers (#24)
- Add gotoTick/aimToTick controller functions (#25)
- Update network dims: actor 5→6, state 42→44 (#26)
- Rewrite mapActions for 6-dim command space (#27)
- Delete stale weight files (shape mismatch)
- Fix existing tests for new signatures

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-17 19:20:40 +02:00

43 lines
1.5 KiB
Nim

## Regression test: radar lock must hold on a stationary target.
## Run: nim c -r tests/test_radar_lock.nim
import std/[math, strformat]
import "../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"