DevControlBot: an ELM gun, its geometric baseline, and an honest null result
Firing wired in behind a compile-time A/B switch (-d:baselineGun): both guns go through the same predictAim() call and differ only by the learned correction, so the measured difference is attributable. radar.nim now keeps the two most recent scans (velocity, scan age, own displacement). Measured over 20 recorded rounds each vs DrussGT, CassiusClay, Komarious and Phoenix: the ELM gun LOSES to the geometric baseline on three of four opponents (Phoenix 51.0% vs 99.5% hit rate). README has the table, the diagnosis and the two in-game-only bugs measuring exposed (degrees/radians, and features whose in-game range lies outside the corpus).
This commit is contained in:
@@ -311,4 +311,114 @@ cd DevControlBot_garage && nimble runBot
|
||||
|
||||
There are **no tests** in this garage. The `test` task and the `tests/` directory
|
||||
were removed along with the old build layout; see
|
||||
[AGENTS.md](AGENTS.md) for the convention to follow when tests are added.
|
||||
[AGENTS.md](AGENTS.md) for the convention to follow when tests are added.
|
||||
## The ELM gun (learned aim-error correction) — and an honest null result
|
||||
|
||||
The bot used to never fire. It now fires, and the gun is an **ELM that predicts
|
||||
the shooter's own aim error**, not a target position: the classic geometric
|
||||
intercept produces the aim point, the ELM says how far off it the shot habitually
|
||||
lands, and the two are added.
|
||||
|
||||
### Files
|
||||
|
||||
| file | what |
|
||||
|---|---|
|
||||
| `DevControlBot/modules/ELM/elm_features.nim` | THE feature vector — one definition, used by both the trainer and the gun. 18 features, all derived from our own state + scan history. |
|
||||
| `DevControlBot/modules/ELM/elm_gun.nim` | the gun: weights loader, `heuristicAim` (the baseline), `predictAim` |
|
||||
| `DevControlBot/modules/ELM/elm_gun_weights.txt` | exported weights, plain text, format documented at the top of `elm_gun.nim` |
|
||||
| `DevControlBot/modules/radar.nim` | scan history added: previous scan, tick, and our own position at scan time (needed for velocity / age / displacement) |
|
||||
| `tools/elm_bench/train_elm_gun.nim` | trains on the pooled 9-opponent corpus, exports the weights |
|
||||
| `tools/elm_bench/score_battles.py` | scores recordings from the OBSERVER ground truth |
|
||||
|
||||
### Reproduce
|
||||
|
||||
```sh
|
||||
# 1. train + export (~1.5 s)
|
||||
cd DevControlBot_garage/DevControlBot
|
||||
nim c -r --path:. ../../tools/elm_bench/train_elm_gun.nim
|
||||
|
||||
# 2. build the two A/B guns (the define switches the learned term off)
|
||||
nim c -d:release -o /tmp/DevElm DevControlBot.nim # ELM gun
|
||||
nim c -d:release -d:baselineGun -o /tmp/DevBase DevControlBot.nim # geometric only
|
||||
|
||||
# 3. battles (a bot dir needs <Name>.json + <Name>.sh + the binary, all
|
||||
# named after the DIRECTORY; RawRecord needs its --dir to exist)
|
||||
cd tools/raw_recorder
|
||||
JAR=.../robocode-tankroyale-runner.jar
|
||||
java -cp out:$JAR RawRecord --dir /tmp/rec_Elm_DrussGT --rounds 20 \
|
||||
--bot /tmp/bots/DevElm --bot /tmp/tr_bots/DrussGT
|
||||
|
||||
# 4. score from the recording's ground truth
|
||||
python3 tools/elm_bench/score_battles.py /tmp/rec_*
|
||||
```
|
||||
|
||||
### The caveat that was known before the first battle
|
||||
|
||||
The offline benchmark this model comes from beats a constant baseline by -62.6%
|
||||
RMSE, but **one single linear feature, `beliefPredErr`, gives -61.1% of it**: the
|
||||
whole ELM buys ~1.5 points over one fitted coefficient. The fit law is
|
||||
`label ~= 0.87 * beliefPredErr + 0.042 rad`, i.e. "the opponent applies ~13% of
|
||||
the lead it should". It also collapses under strictly-prior scans (97.3% of the
|
||||
corpus shots scan on the tick they fire). Expect a small effect, not a good gun.
|
||||
|
||||
### RESULTS — ELM gun vs geometric baseline, 20 real rounds each
|
||||
|
||||
Hit rate from `BulletFiredEvent` / `BulletHitBotEvent` in the RawRecord streams
|
||||
(observer ground truth, every recording verified CONTIGUOUS). A bullet still in
|
||||
flight at round end counts as a miss.
|
||||
|
||||
| opponent | gun | shots | hits | hit % | bullet damage |
|
||||
|---|---|---|---|---|---|
|
||||
| DrussGT | ELM | 324 | 8 | **2.5%** | 80 |
|
||||
| DrussGT | geometric | 345 | 6 | **1.7%** | 60 |
|
||||
| CassiusClay | ELM | 102 | 1 | **1.0%** | 10 |
|
||||
| CassiusClay | geometric | 49 | 4 | **8.2%** | 40 |
|
||||
| Komarious | ELM | 121 | 5 | **4.1%** | 50 |
|
||||
| Komarious | geometric | 147 | 12 | **8.2%** | 120 |
|
||||
| Phoenix | ELM | 143 | 73 | **51.0%** | 730 |
|
||||
| Phoenix | geometric | 185 | 184 | **99.5%** | 1840 |
|
||||
|
||||
### Verdict: no, it does not beat the heuristic. It loses, badly.
|
||||
|
||||
Three of four opponents get worse. The fourth (Phoenix, near-stationary) is the
|
||||
tell: against a target that barely moves, the geometric intercept is already
|
||||
almost perfect, and the model's fitted **+0.042 rad bias alone** pushes a
|
||||
near-miss over the edge — 99.5% -> 51.0%. That is the whole model doing exactly
|
||||
what it was fitted to do (the in-game median correction is 0.046 rad, matching
|
||||
the fitted intercept), and it is still the wrong thing to do: the corpus's
|
||||
"the opponent under-leads" habit belongs to legacy bots that lead imperfectly,
|
||||
and it is a *bias*, not an advantage. Against an opponent that leads correctly
|
||||
the correction is a pure error.
|
||||
|
||||
The one case where ELM wins (DrussGT, 2.5% vs 1.7%) is a single extra hit out of
|
||||
~330 shots: noise, n too small to claim.
|
||||
|
||||
### Two bugs found by measuring (both were invisible offline)
|
||||
|
||||
1. **Feature-domain shift.** `scanAge`, `logScan`, `disp` and `gunHeat` are
|
||||
structurally out of domain in game (the corpus is 97% same-tick shots by
|
||||
slowly-moving legacy bots with a warm gun; this bot fires when its gun is
|
||||
COOLED, 2-10 ticks after a scan, at up to 8 px/tick). With them the tanh
|
||||
model extrapolated and 95% of in-game shots returned the clamp, spraying
|
||||
bullets into walls. They were cut; the measured ranges are tabulated in
|
||||
`elm_features.nim`. This is a real cost, not a free win: the model is now
|
||||
blind to how stale its belief is.
|
||||
2. **Units.** The API speaks degrees and the model speaks radians. Mixing them
|
||||
made the gun fire at random; the conversions are now explicit in
|
||||
`DevControlBot.nim`.
|
||||
|
||||
Also worth knowing: `bulletSpeed` in the corpus is `power * 10`, NOT the physical
|
||||
`20 - 3*power` (an artifact of `extract_realistic.py`). The gun reproduces the
|
||||
corpus convention verbatim in the *feature*, and uses the physical speed in the
|
||||
geometric intercept.
|
||||
|
||||
### Calibration — not measured, and here is why
|
||||
|
||||
`elm_gun` exposes `lastCorrection` and the bot can log one line per shot
|
||||
(`-d:gunLog`, `ELM_GUN_LOG=file.csv`). The *truth* has to come from the
|
||||
recording, and the join failed: `bot.tick` counts loop iterations (~15.5k in a
|
||||
round the observer numbers to 2.8k), so a shot's tick cannot be mapped to an
|
||||
observer `turnNumber` without a per-round ratio that was not worth measuring.
|
||||
What IS known: the in-game correction distribution is healthy (mean 0.030 rad,
|
||||
median 0.046, 1% at the clamp), i.e. the model is operating in the regime it was
|
||||
fitted in and is not saturating — it is simply wrong for this opponent class.
|
||||
|
||||
Reference in New Issue
Block a user