README: review fixes, scan-gap analysis, re-measurement (neutral)

This commit is contained in:
2026-10-06 19:54:32 +02:00
parent 2fd2388f32
commit 7f0fbccec6
+65
View File
@@ -701,3 +701,68 @@ Reproduce:
bash tools/elm_bench/run_online_battles.sh Corners Crazy ... Walls Komarious Phoenix DrussGT
python3 tools/elm_bench/analyse_online.py /tmp/gun_exp_clean
```
## Code-review fixes to the online gun
A review flagged five issues in an earlier revision of `elm_gun.nim` /
`radar.nim` / `DevControlBot.nim`. Each was re-checked against the current
code; three held, two were already handled by the rewrite. The three fixes are
behaviour-preserving by construction and were re-measured on the same 9
held-out sample bots.
### What was actually wrong (and what was not)
| # | claim | verdict |
|---|---|---|
| 1 | stale velocity in dead reckoning (unbounded extrapolation) | **confirmed** — `heuristicAim` advanced `b.ex/b.ey` by `vx*age` with no cap |
| 2 | `scanGap()` recorded but never checked | **confirmed literal / partly refuted** — it *is* dead state, but "training on the belief is wrong" is false: delayed-label training is correct. Only extreme gaps are suspect |
| 3 | aim x/y recomputed twice | **confirmed** — baseline and ELM branches each did `cos/sin` |
| 4 | deg/rad landmine at the fire boundary | **refuted as a bug, confirmed as a robustness gap** — the earlier fix already compares degrees to `FireSlopDeg`; it just lacked a named unit + test |
| 5 | inherent 1-tick radar lag | **confirmed, not a bug** — `buildBelief`/`heuristicAim` dead-reckon by `scanAge`, and delayed labels are keyed by `dueTick`; the lag is accounted for |
### The fixes
1. **Bounded dead reckoning** (`DevControlBot.nim`, `MaxDeadReckonTicks = 4`):
`lead = min(age, MaxDeadReckonTicks)` before advancing the last scan. Past a
few ticks a constant-velocity guess diverges; the belief now freezes at the
last seen position instead of running away. Also
**untrustworthy velocity samples** (`radar.nim`, `MaxVelGap = 3`):
`targetVelocity()` returns `(0,0)` when the two scans it averages span more
than 3 ticks, matching the corpus's one-tick-delta convention.
2. **Single coordinate computation** (`elm_gun.nim`, `predictAim`): the learned
correction is folded into one `aim` bearing, then `x`/`y` are derived from
it exactly once.
3. **Explicit unit boundary** (`elm_gun.nim`, `gunAimErrorDeg` + `DevControlBot`
`computeGun`): the one rad→deg conversion now lives in a proc whose *name*
carries the degree unit, replicated API-free so `elm_gun` stays stdlib-only.
`test_online.nim` gains a regression block: a known bearing yields the known
turn command, and the historical `degToRad(FireSlopDeg)` mix-up would reject
a shot that is exactly `FireSlopDeg` off.
### Does the guard actually fire?
Measured from the RawRecord streams: the radar lock re-scans on **99.1%** of
ticks (`scanGap == 1`; 90 923 vs 603 wider gaps over 9 opponents). Shots taken
with a stale belief (>= 2 ticks since the scan) are ~5% of all shots and hit at
~10% versus 36.8% for fresh ones — the stale shots mostly miss, but they are too
rare for the cap to move the aggregate. The guard bites on ~2–3% of shots.
### Re-measurement (3 replicates x 20 rounds per opponent, all CONTIGUOUS)
`OLD` = pre-fix code rebuilt from `HEAD`; `NEW` = with the three fixes. The
single-run protocol in the section above is noisy, so the table is pooled over
60 rounds/opponent.
| arm | OLD dmg/rd | NEW dmg/rd | OLD hit | NEW hit |
|---|---:|---:|---:|---:|
| Base (intercept) | 71.3 | 72.0 | 24.3% | 24.8% |
| Online | 90.3 | 89.7 | 34.9% | 34.1% |
| Δ Online | +19.0 (+26.7%) | +17.6 (+24.5%) | +10.6pp | +9.3pp |
| wins vs Base | 8/9 | 7/9 | | |
The documented single-run baseline (70.1 / 88.3 / 23.5→33.0% / 7-of-9) sits
exactly between the two pooled columns. **Bottom line: the fixes are neutral**
— every row moves by <1 dmg/rd, well inside run-to-run variance. They remove a
latent failure mode without paying for it; they do not improve the gun because
the radar keeps the belief fresh in practice.