guns/elm.nim online sequential ELM (ridge/RLS), fixed random
hidden layer, one pass, no backprop
guns/waveelm.nim the WaveElm gun: a simulated omnidirectional expanding
ring of probes fired from the SHOOTER, where the ELM
learns a BIAS CORRECTION to the ring's reconstructed
position (predicting the position outright was measured
and refuted: it collapses on abrupt/burst movement)
guns/gun_knowledge.nim GUNK: a learned additive angular residual on top of
the self-consistent lead forecast. Only answers "which
absolute gun direction", nothing else
guns/docs/ the open-access OS-ELM / ELM reference set plus
fetch_papers.sh, which re-downloads it idempotently
Plus the matching test and measurement harnesses (test_waveelm*, test_elm,
test_gun_knowledge, test_knowledge_registration, gk_aim_probe,
measure_gk_{residual,virtual}.py) and the docs README with the citations.
121 lines
4.2 KiB
Nim
121 lines
4.2 KiB
Nim
## ONLINE REAL-BATTLE check for the WAVEELM gun (rack id 18,
|
|
## `common_libs/guns/waveelm.nim` — the online-ELM gun).
|
|
##
|
|
## It answers one question the offline suites cannot: does the LIVE ModularBot
|
|
## actually DISCOVER and USE the gun? Two short battles (3 rounds each, the
|
|
## `maxSpeed` default) force WAVEELM alone in the rack with env vars only —
|
|
## `TR_RACK_WAVEELM=both`, every other gun `off` — against the two shared
|
|
## adversaries: SittingDuck (passive) and OscillatorBot (fights back).
|
|
##
|
|
## Each battle is read from the bot's own per-round gun dump
|
|
## (`GUN_STATS_PATH`), and the gun is only "discovered and used" if the live
|
|
## loop SPAWNED virtual bullets for id 18 (vShots > 0) and the live selector
|
|
## SELECTED it (selected > 0).
|
|
##
|
|
## Run:
|
|
## TR_SERVER_JAR=... TR_BATTLE_RUNNER=... \
|
|
## nim c -r common_libs/tests/test_waveelm_rack_live.nim
|
|
##
|
|
## Skips (exit 0) when the TR JARs are absent, matching the other live tests.
|
|
|
|
import std/[os, json, strutils]
|
|
import test_framework/test_framework
|
|
import gun_harness/selector
|
|
import gun_harness/virtual_bullets
|
|
|
|
const
|
|
repoRoot = currentSourcePath().parentDir.parentDir.parentDir
|
|
modularBotDir = repoRoot / "ModularBot_garage"
|
|
adversariesDir = repoRoot / "common_libs" / "test_framework" / "adversaries"
|
|
statsPath = "/tmp/waveelm_rack_stats.jsonl"
|
|
|
|
const WaveElmId = 18
|
|
|
|
var failures = 0
|
|
proc check(name: string, ok: bool) =
|
|
if ok: echo "PASS: ", name
|
|
else: echo "FAIL: ", name; inc failures
|
|
|
|
proc lastRound(path: string): JsonNode =
|
|
result = nil
|
|
for line in lines(path):
|
|
let s = line.strip()
|
|
if s.len == 0: continue
|
|
let node = parseJson(s)
|
|
if node.hasKey("guns"): result = node
|
|
|
|
proc runOne(adversary: string) =
|
|
let advDir = adversariesDir / adversary
|
|
if not dirExists(advDir):
|
|
echo "Skipping: adversary not found: ", advDir
|
|
quit(0)
|
|
if fileExists(statsPath): removeFile(statsPath)
|
|
|
|
# Force the new gun alone: every other rack entry off, WAVEELM in both racks.
|
|
for i, name in RackGunNames:
|
|
putEnv("TR_RACK_" & name, if i == WaveElmId: "both" else: "off")
|
|
putEnv("GUN_STATS_PATH", statsPath)
|
|
defer:
|
|
for name in RackGunNames: delEnv("TR_RACK_" & name)
|
|
delEnv("GUN_STATS_PATH")
|
|
|
|
echo "=== live: ModularBot (only WAVEELM racked) vs ", adversary, ", 3 rounds ==="
|
|
let battle = runBattle(@[modularBotDir, advDir], rounds = 3)
|
|
for res in battle.results:
|
|
echo " ", res.name, " rank=", res.rank, " score=", res.totalScore
|
|
|
|
if not fileExists(statsPath):
|
|
echo "FAIL: no gun_stats dump at ", statsPath
|
|
inc failures
|
|
return
|
|
let round = lastRound(statsPath)
|
|
check adversary & ": gun_stats.jsonl has a round record", round != nil
|
|
if round == nil: return
|
|
|
|
var shots = 0
|
|
var selected = 0
|
|
var otherSelected = 0
|
|
for g in round["guns"]:
|
|
if g["id"].getInt() == WaveElmId:
|
|
shots = g["vShots"].getInt()
|
|
selected = g["selected"].getInt()
|
|
elif g["selected"].getInt() > 0:
|
|
otherSelected += g["selected"].getInt()
|
|
|
|
echo "gun ", WaveElmId, " (WaveElm): vShots=", shots, " selected=", selected,
|
|
" other-gun selections=", otherSelected
|
|
check adversary & ": the live loop SPAWNED virtual bullets for gun 18 (vShots > 0)",
|
|
shots > 0
|
|
check adversary & ": the live selector SELECTED gun 18 (selected > 0)",
|
|
selected > 0
|
|
check adversary & ": no other gun was selected while WAVEELM was forced alone",
|
|
otherSelected == 0
|
|
|
|
proc main() =
|
|
let serverJar = getEnv("TR_SERVER_JAR", "")
|
|
let runnerJar = getEnv("TR_BATTLE_RUNNER", "")
|
|
if serverJar.len == 0 or runnerJar.len == 0:
|
|
echo "Skipping: TR_SERVER_JAR / TR_BATTLE_RUNNER not set"
|
|
quit(0)
|
|
if not fileExists(serverJar) or not fileExists(runnerJar):
|
|
echo "Skipping: TR JARs not found (server=", serverJar, ", runner=", runnerJar, ")"
|
|
quit(0)
|
|
if not fileExists(modularBotDir / "src" / "ModularBot.nim"):
|
|
echo "Skipping: ModularBot source not found"
|
|
quit(0)
|
|
|
|
check "rack: WAVEELM is registered at id 18", RackGunNames[WaveElmId] == "WAVEELM"
|
|
check "rack: WAVEELM ships `off`, like every gun except Pattern",
|
|
ActiveRackMembership[WaveElmId] == rmOff
|
|
|
|
runOne("SittingDuck")
|
|
runOne("OscillatorBot")
|
|
|
|
if failures > 0:
|
|
echo "\n", failures, " check(s) FAILED"
|
|
quit(1)
|
|
echo "\nWaveElm live rack check passed."
|
|
|
|
when isMainModule:
|
|
main()
|