Bots: env reporting, TFIL movement, gun selector and docs refresh
DevControlBot DevControlBot.sh env-file handling and defines, tfil.nim
survival-movement rework, README
ModularBot .env.example, ModularBot.nim, env_report.nim, vbullet_draw.nim
PPO_Bot enemy_tracker.nim
common_libs gun_harness/selector.nim
tests env_report, lead_gain_legacy, rack_membership,
rack_stat_width, tm_pattern_registration adjustments
docs env_reference.md, goto-controller-algorithm.md
This commit is contained in:
@@ -226,6 +226,8 @@ TR_RACK_TMSELECT=off # Tsetlin machine used as the shot selector
|
||||
TR_RACK_TMPATTERN=off # Tsetlin machine used as a pattern matcher
|
||||
TR_RACK_TMHORIZON=off # horizon Tsetlin automata gun
|
||||
TR_RACK_LEADGAIN=off # per-range-band learned lead-gain corrector
|
||||
TR_RACK_KNOWLEDGE=off # learned angular-residual corrector on the lead forecast
|
||||
TR_RACK_WAVEELM=off # online-ELM learned (x,y) offset on the analytic intercept
|
||||
# Give every named gun a fixed share of the turns instead of ranking them.
|
||||
# e.g. TR_RACK_SHARE=PATTERN:60%,HEADON:40% (GUN:weight, comma separated,
|
||||
# the % sign is optional). Empty = the ranking selector. GOTCHA: every gun you
|
||||
@@ -236,8 +238,9 @@ TR_RACK_SHARE=
|
||||
# Drop whole guns by rack id (comma separated, e.g. 16). Empty = keep them all.
|
||||
# Ids: 0 HEADON 1 LINEAR 2 TSETLIN 3 CIRCULAR 4 GUESSFACTOR 5 PATTERN
|
||||
# 6 WALLBOUNCE 7 ACCEL 8 STOPSHOT 9 DISPLACE 10 AVGLEAD 11 DECAYGF 12 KNN
|
||||
# 13 TMSELECT 14 TMPATTERN 15 TMHORIZON 16 LEADGAIN. A disabled gun never even
|
||||
# spawns a virtual bullet, so its fitness stays empty and it cannot be picked.
|
||||
# 13 TMSELECT 14 TMPATTERN 15 TMHORIZON 16 LEADGAIN 17 KNOWLEDGE 18 WAVEELM.
|
||||
# A disabled gun never even spawns a virtual bullet, so its fitness stays empty
|
||||
# and it cannot be picked.
|
||||
GUN_RACK_DISABLE=
|
||||
|
||||
# ── gun selector (which admitted gun fires this tick) ───────────────────────
|
||||
@@ -667,6 +670,35 @@ TR_LEADGAIN_ADAPT=32 # NO-OP: the old adapt interval, no longer used
|
||||
TR_LEADGAIN_CALIB=512 # NO-OP: the old calibration interval, no longer used
|
||||
TR_LEADGAIN_SEED=20240921 # NO-OP: the old seed, no longer used
|
||||
|
||||
# KNOWLEDGE (rack id 17) — the learned additive angular residual on top of the
|
||||
# self-consistent lead forecast. It answers only the aim angle: no power, no
|
||||
# fire decision, no target picking.
|
||||
TR_KNOWLEDGE_MEM= # path of the learned table; EMPTY = memory only
|
||||
# (nothing is ever written to disk). Set to e.g.
|
||||
# /tmp/gun_knowledge.bin to persist across battles.
|
||||
|
||||
# WAVEELM (rack id 18) — the online-ELM gun. Analytic bullet/target intercept
|
||||
# (self-consistent flight time) plus a learned (x, y) offset from a recursive
|
||||
# least-squares ELM trained on the real-shot feedback. Admitted by the rack line
|
||||
# above only; this gun has NO env knobs of its own — see below.
|
||||
#
|
||||
# OFF BY DEFAULT (shipped, like every gun except PATTERN). To enable:
|
||||
# TR_RACK_WAVEELM=both (also: 1v1 | melee; aliases any/empty->both,
|
||||
# single/lock->1v1, only1v1->1v1,
|
||||
# multi/onlymelee->melee, none/disabled/disable->off)
|
||||
# UNRECOGNISED value warns on stderr and falls back to `both` (GOTCHA: a typo
|
||||
# ADDS the gun to the rack, it never turns it off).
|
||||
# FORCED SHARE: TR_RACK_SHARE=WAVEELM:50,PATTERN:50 works, but only if
|
||||
# WAVEELM is admitted above — a share naming an `off` gun is refused.
|
||||
# NOTHING TO TUNE FROM HERE: WaveLambda (0.1 ridge), WaveRho (1.02 forgetting),
|
||||
# WaveIters (20 intercept iterations), WaveMaxResidual, WaveMaxOffset,
|
||||
# WaveTraceSlots and the ELM seed (42) are `const`s in
|
||||
# common_libs/guns/waveelm.nim — changing them needs a REBUILD, not an env var.
|
||||
# No TR_WAVEELME_* variable exists; there is no persisted memory path either
|
||||
# (the ELM is rebuilt from scratch every battle, unlike KNOWLEDGE).
|
||||
# Per-shot behaviour for every admitted gun is logged by the shared stats writer
|
||||
# (GUN_STATS_PATH below).
|
||||
|
||||
# PATTERN — the shipped gun, the only one the rack admits.
|
||||
TR_PATTERN_LEN=10 # ticks of movement history used as the search key
|
||||
TR_PATTERN_DEPTH=500 # how far back the history scan may reach
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## ModularBot — plugin gun architecture tracer bullet.
|
||||
## Guns: HeadOnGun (0), LinearGun (1), TsetlinGun (2), CircularGun (3), GFGun (4), PatternMatcherGun (5), WallBounceGun (6), AccelGun (7), StopShotGun (8), DisplacementGun (9), AveragedLeadGun (10), DecayGFGun (11), KNNGun (12), TmSelectorGun (13), TmPatternGun (14), TmHorizonGun (15), LeadGainGun (16), BitbrainNetGun (17) via GunHarness.
|
||||
## Guns: HeadOnGun (0), LinearGun (1), TsetlinGun (2), CircularGun (3), GFGun (4), PatternMatcherGun (5), WallBounceGun (6), AccelGun (7), StopShotGun (8), DisplacementGun (9), AveragedLeadGun (10), DecayGFGun (11), KNNGun (12), TmSelectorGun (13), TmPatternGun (14), TmHorizonGun (15), LeadGainGun (16), KnowledgeGun (17), WaveElmGun (18) via GunHarness.
|
||||
## Radar: RadarLockModule (1v1) / AdaptiveMeleeRadarModule (2+ enemies), auto-switched per tick.
|
||||
## Movement: OscillatorModule (perpendicular strafing).
|
||||
|
||||
@@ -31,6 +31,8 @@ import guns/tm_selector
|
||||
import guns/tm_pattern
|
||||
import guns/tm_horizon
|
||||
import guns/lead_gain
|
||||
import guns/gun_knowledge
|
||||
import guns/waveelm
|
||||
import movements/phantom_meteor
|
||||
import movements/rammer
|
||||
import movements/ram_decision
|
||||
@@ -158,7 +160,7 @@ let ResultLog* =
|
||||
block:
|
||||
let v = getEnv("TR_RESULT_LOG", "1").strip().toLowerAscii()
|
||||
not (v == "0" or v == "false" or v == "no" or v == "off")
|
||||
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern", "WallBounce", "Accel", "StopShot", "Displace", "AvgLead", "DecayGF", "KNN", "TMSelect", "TMPattern", "TMHorizon", "LeadGain"]
|
||||
const GunNames = ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern", "WallBounce", "Accel", "StopShot", "Displace", "AvgLead", "DecayGF", "KNN", "TMSelect", "TMPattern", "TMHorizon", "LeadGain", "Knowledge", "WaveElm"]
|
||||
|
||||
## Rack id of the new TM pattern gun. It defaults to `TR_RACK_TMPATTERN=off`;
|
||||
## unlike the other guns, its virtual-bullet spawn is gated on rack admission
|
||||
@@ -182,6 +184,25 @@ const TmHorizonId = 15
|
||||
## (backward compatibility; see `gun_harness/selector`).
|
||||
const LeadGainId = 16
|
||||
|
||||
## Rack id of KNOWLEDGE, the learned additive angular residual on top of the
|
||||
## self-consistent lead forecast (`common_libs/guns/gun_knowledge.nim`). It is
|
||||
## APPENDED at the end of the rack, so no existing id moved and every
|
||||
## `tools/ab/arms_*.txt` config still addresses the gun it was written for. It
|
||||
## ships `TR_RACK_KNOWLEDGE=off`, like every gun except Pattern, and its
|
||||
## virtual-bullet spawn is gated on rack admission (`vBulletAdmitted`), so the
|
||||
## shipped default never spawns it and the shared tracker ring head — hence every
|
||||
## other gun's learning order — is byte-for-byte unchanged. Unlike the rest of
|
||||
## the rack it may also touch disk (`TR_KNOWLEDGE_MEM`), which is another reason
|
||||
## it stays out of the default rack.
|
||||
const KnowledgeId = 17
|
||||
|
||||
## Rack id of WAVEELM, the online-ELM gun (`common_libs/guns/waveelm.nim`): an
|
||||
## analytic intercept plus a learned per-tick (x, y) offset trained by an
|
||||
## online sequential ELM on its OWN virtual-bullet feedback. APPENDED at the end
|
||||
## of the rack, so no existing id moved. Ships `TR_RACK_WAVEELM=off`, like every
|
||||
## gun except Pattern, and its virtual-bullet spawn is gated on rack admission.
|
||||
const WaveElmId = 18
|
||||
|
||||
## ── virtual-bullet debug overlay (TR_VBULLET_DEBUG*) ───────────────────────
|
||||
## OFF by default: the shipped bot draws nothing. When on, the tracker's
|
||||
## virtual bullets are overlaid so the training signal the selector learns
|
||||
@@ -254,6 +275,8 @@ type
|
||||
tmPattern: TmPatternGun
|
||||
tmHorizon: TmHorizonGun
|
||||
leadGain: LeadGainGun
|
||||
knowledge: KnowledgeGun
|
||||
waveElm: WaveElmGun
|
||||
mover: TFILModule
|
||||
ringMover: TFILRingModule
|
||||
strafeMover: StrafeModule
|
||||
@@ -1316,6 +1339,8 @@ method run*(bot: ModularBot) =
|
||||
var tmpPreds: array[len(PowerBins), GunPrediction]
|
||||
var tmhPreds: array[len(PowerBins), GunPrediction]
|
||||
var lgPreds: array[len(PowerBins), GunPrediction]
|
||||
var gkPreds: array[len(PowerBins), GunPrediction]
|
||||
var wePreds: array[len(PowerBins), GunPrediction]
|
||||
# ── TR_VBULLET_ADMIT_ONLY gate ──────────────────────────────────────
|
||||
# Rack membership used to filter only SELECTION, so every unselected gun
|
||||
# still ran predict()+spawnBullets() each tick to feed a fitness table the
|
||||
@@ -1332,7 +1357,8 @@ method run*(bot: ModularBot) =
|
||||
admit[gi] = ModuleVBullets and
|
||||
vBulletAdmitted(gi, bot.rackMode, ActiveRackMembership,
|
||||
VBulletAdmitOnly or gi == TmPatternId or
|
||||
gi == TmHorizonId or gi == LeadGainId)
|
||||
gi == TmHorizonId or gi == LeadGainId or
|
||||
gi == KnowledgeId or gi == WaveElmId)
|
||||
for i in 0..<len(PowerBins):
|
||||
if admit[0]: headsUp[i] = bot.headOn.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
if admit[1]: linPreds[i] = bot.linear.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
@@ -1358,6 +1384,18 @@ method run*(bot: ModularBot) =
|
||||
# LEADGAIN: Pattern base, lead scaled by a per-band learned gain.
|
||||
if admit[LeadGainId]:
|
||||
lgPreds[i] = bot.leadGain.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
# KNOWLEDGE: forecast base + a learned additive residual. It is told WHO
|
||||
# it is aiming at (target selection stays with enemy_tracker/target_
|
||||
# selector) and how hot the turret is, and answers only the aim angle.
|
||||
if admit[KnowledgeId]:
|
||||
bot.knowledge.gunHeat = getGunHeat()
|
||||
bot.knowledge.targetId = tid
|
||||
gkPreds[i] = bot.knowledge.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
# WAVEELM: analytic intercept + a learned (x, y) offset from the online
|
||||
# ELM. It is told WHO it aims at, so its per-enemy scan tracks line up.
|
||||
if admit[WaveElmId]:
|
||||
bot.waveElm.targetId = tid
|
||||
wePreds[i] = bot.waveElm.predict(bot.lastState, bulletSpeed(PowerBins[i]))
|
||||
|
||||
if admit[0]: bot.tracker.spawnBullets(0, headsUp, bot.lastState, tid)
|
||||
if admit[1] and not gunDisabled(1): bot.tracker.spawnBullets(1, linPreds, bot.lastState, tid)
|
||||
@@ -1381,6 +1419,10 @@ method run*(bot: ModularBot) =
|
||||
bot.tracker.spawnBullets(TmHorizonId, tmhPreds, bot.lastState, tid)
|
||||
if admit[LeadGainId] and not gunDisabled(LeadGainId):
|
||||
bot.tracker.spawnBullets(LeadGainId, lgPreds, bot.lastState, tid)
|
||||
if admit[KnowledgeId] and not gunDisabled(KnowledgeId):
|
||||
bot.tracker.spawnBullets(KnowledgeId, gkPreds, bot.lastState, tid)
|
||||
if admit[WaveElmId] and not gunDisabled(WaveElmId):
|
||||
bot.tracker.spawnBullets(WaveElmId, wePreds, bot.lastState, tid)
|
||||
|
||||
# Build slim enemy table for tickBullets
|
||||
var enemyPositions: Table[int, tuple[x, y: float, lastSeenTick: int, alive: bool]]
|
||||
@@ -1417,6 +1459,8 @@ method run*(bot: ModularBot) =
|
||||
of TmPatternId: bot.tmPattern.onResult(fe)
|
||||
of TmHorizonId: bot.tmHorizon.onResult(fe)
|
||||
of LeadGainId: bot.leadGain.onResult(fe)
|
||||
of KnowledgeId: bot.knowledge.onResult(fe)
|
||||
of WaveElmId: bot.waveElm.onResult(fe)
|
||||
else: discard
|
||||
if fe.hit: inc bot.virtualHits else: inc bot.virtualMiss
|
||||
if DebugDrawOn and VBulletDebugOn:
|
||||
@@ -1472,6 +1516,8 @@ method run*(bot: ModularBot) =
|
||||
of TmPatternId: bot.tmPattern.predict(bot.lastState, bulletSpeed(power))
|
||||
of TmHorizonId: bot.tmHorizon.predict(bot.lastState, bulletSpeed(power))
|
||||
of LeadGainId: bot.leadGain.predict(bot.lastState, bulletSpeed(power))
|
||||
of KnowledgeId: bot.knowledge.predict(bot.lastState, bulletSpeed(power))
|
||||
of WaveElmId: bot.waveElm.predict(bot.lastState, bulletSpeed(power))
|
||||
else: bot.headOn.predict(bot.lastState, bulletSpeed(power))
|
||||
let aimTarget = aimAngle(getX(), getY(), pred.x, pred.y)
|
||||
|
||||
@@ -1560,7 +1606,7 @@ proc seedSelectorRng() =
|
||||
|
||||
when isMainModule:
|
||||
var bot = ModularBot(
|
||||
tracker: vb.initTracker(NumRackGuns), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern, 6: WallBounce, 7: Accel, 8: StopShot, 9: Displace, 10: AvgLead, 11: DecayGF, 12: KNN, 13: TMSelect, 14: TMPattern, 15: TMHorizon, 16: LeadGain
|
||||
tracker: vb.initTracker(NumRackGuns), # 0: HeadOn, 1: Linear, 2: Tsetlin, 3: Circular, 4: GuessFactor, 5: Pattern, 6: WallBounce, 7: Accel, 8: StopShot, 9: Displace, 10: AvgLead, 11: DecayGF, 12: KNN, 13: TMSelect, 14: TMPattern, 15: TMHorizon, 16: LeadGain, 17: Knowledge, 18: WaveElm
|
||||
headOn: HeadOnGun(),
|
||||
linear: LinearGun(),
|
||||
circular: CircularGun(),
|
||||
@@ -1578,6 +1624,8 @@ when isMainModule:
|
||||
tmPattern: initTmRadialGun(),
|
||||
tmHorizon: initTmHorizonGun(),
|
||||
leadGain: initLeadGainGun(),
|
||||
knowledge: initKnowledgeGun(),
|
||||
waveElm: initWaveElmGun(),
|
||||
radar: RadarLockModule(),
|
||||
meleeRadar: initAdaptiveMeleeRadar(),
|
||||
mover: TFILModule(debugGraphics: DebugDrawOn),
|
||||
|
||||
@@ -34,6 +34,7 @@ import movements/learned_surfer
|
||||
import guns/tm_horizon
|
||||
import guns/lead_gain
|
||||
import guns/pattern_matcher
|
||||
import guns/gun_knowledge
|
||||
import vbullet_draw
|
||||
import geo_overlay
|
||||
|
||||
@@ -469,6 +470,14 @@ proc printEffectiveValues(ctx: EnvReportContext) =
|
||||
if dep.len > 0: emit("legacy TR_BITBRAIN_* aliases honoured", "yes", "legacy")
|
||||
else: emit("legacy TR_BITBRAIN_* aliases honoured", "no", "default")
|
||||
|
||||
# ── KNOWLEDGE, the learned residual gun (rack id 17) ──────────────────────
|
||||
# One knob: where its learned table lives. Unset = memory only, i.e. nothing
|
||||
# is ever written to disk. The table is allocated on FIRST USE, so this line
|
||||
# reports the configured path, not a live table.
|
||||
let gkMem = getEnv(GK_MEM_ENV, "").strip()
|
||||
emit("TR_KNOWLEDGE_MEM", if gkMem.len > 0: gkMem else: "(unset -> memory only)",
|
||||
sourceOf(GK_MEM_ENV))
|
||||
|
||||
# ── Pattern match-shape + radial knobs ────────────────────────────────────
|
||||
# These are resolved lazily inside `predict` (which has not run at boot), so
|
||||
# unless something already forced them we report the raw env value and say so.
|
||||
@@ -629,6 +638,7 @@ proc knownEnvNames*(): seq[string] =
|
||||
TMH_SHIFT_ENV, TMH_BIG_MULT_ENV, TMH_LOG_ENV, TMH_RESET_ON_TARGET_ENV,
|
||||
TMH_WINDOW_ENV, TMH_RESET_DROP_ENV, TMH_NSTATES_ENV, TMH_ACCURVE_ENV,
|
||||
TMH_RETRAIN_EVERY_ENV, TMH_EPOCHS_ENV,
|
||||
GK_MEM_ENV,
|
||||
LG_MEM_ENV, LG_GAINS_ENV, LG_N_ENV, LG_NADE_ENV, LG_RANGE_ENV, LG_LOG_ENV,
|
||||
LG_MIN_OBS_ENV, LG_WARMUP_ENV, LG_ADAPT_ENV, LG_CALIB_ENV, LG_DECAY_ENV,
|
||||
LG_DECAY_FRAC_ENV, LG_SEED_ENV, LG_RESET_ON_TARGET_ENV,
|
||||
|
||||
@@ -100,6 +100,8 @@ proc gunColors*(gunId: int): tuple[turret, bullet: string] =
|
||||
of 14: ("#AAFF00", "#CCFF66") # TMPattern — lime
|
||||
of 15: ("#00AAFF", "#66CCFF") # TMHorizon — sky
|
||||
of 16: ("#FF1493", "#FF69B4") # LEADGAIN — deep pink
|
||||
of 17: ("#8B4513", "#D2691E") # KNOWLEDGE — saddle brown
|
||||
of 18: ("#7B68EE", "#9370DB") # WAVEELM — medium slate blue
|
||||
else: ("#FFFFFF", "#FFFFFF")
|
||||
|
||||
proc gunTurretColor*(gunId: int): string = gunColors(gunId).turret
|
||||
|
||||
Reference in New Issue
Block a user