DevControlBot 1.2.0: TFIL survival movement + universal battle runner
Ported "the floor is lava" (TFIL) movement into DevControlBot as a self-contained module, DevControlBot/modules/tfil.nim. It has no runtime dependency on common_libs/: the port is a standalone implementation, parity-verified against the common_libs original over 2000 differential ticks with zero divergences. Do not re-introduce the dependency and do not edit the original to match. Debug graphics (per-tile lava heat, tracked bullets and their danger corridors, enemy core/aura, reachable hull, committed tile) are OFF by default and compile-time gated behind -d:tfilDebug; see README.md for the plain `nim c` invocation, since nimble runBot does not forward compile flags. Wired into DevControlBot.nim: movement computed between commandRadar() and go(), fire-event tracking wired up, staleness handling for scanned enemies, and body colour set to BLACK at init (movement and radar both claim colour now). Also adds tools/test_runner, a shared battle-test runner usable by any garage, with an Observer adversary for quick floor checks.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
## DevControlBot — control skeleton: boots, stands still, and drives nothing but
|
||||
## the radar. It never moves and it never fires.
|
||||
## DevControlBot — control skeleton: boots, drives the radar every tick and keeps
|
||||
## itself alive with the TFIL survival movement. It never fires.
|
||||
##
|
||||
## Team convention: white means "not programmed yet". At startup body, turret, gun
|
||||
## and radar are all plain WHITE. The radar then claims its OWN colours when it
|
||||
## starts working: initRadar() paints the radar and the scan arc BLACK, leaving
|
||||
## body/turret/gun white (this bot never moves and never fires, so they stay
|
||||
## "not programmed"). Colors are applied once, never per tick.
|
||||
## Team convention: white means "not programmed yet". Each module claims its own
|
||||
## colours when its init runs, and nothing paints white after that: initTFIL()
|
||||
## (constructor) paints body, turret and gun BLACK — movement is programmed —
|
||||
## and initRadar() (first line of run) paints the radar and the scan arc BLACK.
|
||||
## The bot therefore ends up fully BLACK. Colors are applied once, never per tick.
|
||||
##
|
||||
## This module is both the bot type and the program entry point (see isMainModule
|
||||
## below). All radar logic lives in modules/radar.nim; the bot keeps no state.
|
||||
@@ -15,32 +15,96 @@
|
||||
## The order matters — go() sends the intent first and dispatches the pending
|
||||
## events last, so onScannedBot only feeds the NEXT tick.
|
||||
##
|
||||
## Movement: modules/tfil.nim ("The Floor Is Lava"), vendored into this folder so
|
||||
## the bot depends on nothing but the API. It is asked for a command every tick,
|
||||
## BEFORE go(), exactly like the radar, and the result is applied with
|
||||
## setTargetSpeed/setTurnRate — same contract as ModularBot's mover.
|
||||
##
|
||||
## Debug graphics: TFIL's drawing needs NO plumbing here. The API's graphics
|
||||
## procs are global; the SVG buffer is flushed and cleared by the API after every
|
||||
## tick, so anything drawn before `go()` (i.e. inside computeMove) reaches the
|
||||
## viewer. It is compiled only with `-d:tfilDebug`; see README "Debug graphics".
|
||||
##
|
||||
## API: robocode_tankroyale_botapi 1.0.7 (the renamed tankroyale_botapi package).
|
||||
import std/[os]
|
||||
import std/[os, sequtils]
|
||||
import robocode_tankroyale_botapi
|
||||
import modules/radar
|
||||
import modules/tfil
|
||||
|
||||
const MaxScannedEnemies* = 16 ## movers see every alive enemy; the radar feeds
|
||||
## only what it scans, so this is a cap, not a limit
|
||||
|
||||
const EnemyStaleTicks* = 60 ## drop a scanned enemy not rescanned for this many
|
||||
## ticks (~1s at 60Hz): a bot seen once would keep
|
||||
## painting its heat in the field forever
|
||||
|
||||
type DevControlBot* = ref object of Bot
|
||||
mover: TfilModule
|
||||
tick: int
|
||||
enemies: seq[EnemyInfo] ## fed by onScannedBot, cleared on round end
|
||||
|
||||
proc newDevControlBot*(): DevControlBot =
|
||||
result = DevControlBot()
|
||||
setBodyColor(WHITE)
|
||||
setTurretColor(WHITE)
|
||||
setGunColor(WHITE)
|
||||
setRadarColor(WHITE)
|
||||
result.mover = initTFIL() # movement is programmed -> body/turret/gun BLACK
|
||||
setRadarColor(WHITE) # overwritten by initRadar() before the first tick
|
||||
|
||||
method onScannedBot*(bot: DevControlBot, e: ScannedBotEvent) =
|
||||
onScan(e.x, e.y) # remembered; commandRadar() re-aims every tick
|
||||
# (e.scannedBotId, schemas.nim:305, is the
|
||||
# scanned bot's identity; unused here)
|
||||
# scanned bot's identity)
|
||||
# ...and remembered for the movement: the heat field paints every enemy it
|
||||
# knows about. One entry per id, refreshed in place, oldest dropped past the cap.
|
||||
for i, ei in bot.enemies:
|
||||
if ei.id == e.scannedBotId:
|
||||
bot.enemies[i].x = e.x
|
||||
bot.enemies[i].y = e.y
|
||||
bot.enemies[i].heading = e.direction
|
||||
bot.enemies[i].speed = e.speed
|
||||
bot.enemies[i].energy = e.energy
|
||||
bot.enemies[i].lastSeenTick = bot.tick
|
||||
return
|
||||
if bot.enemies.len >= MaxScannedEnemies:
|
||||
bot.enemies.delete(0)
|
||||
bot.enemies.add EnemyInfo(id: e.scannedBotId, x: e.x, y: e.y,
|
||||
heading: e.direction, speed: e.speed, energy: e.energy,
|
||||
lastSeenTick: bot.tick)
|
||||
|
||||
method onHitByBullet*(bot: DevControlBot, e: HitByBulletEvent) =
|
||||
# an enemy bullet hit us -> tell the fire tracker, else the same tick reads as
|
||||
# "no fire" and the enemy's shot goes uncounted (see modules/tfil.nim, FireFix)
|
||||
bot.mover.noteEnemyBulletHit(e.bullet.power)
|
||||
|
||||
method onBulletHit*(bot: DevControlBot, e: BulletHitBotEvent) =
|
||||
bot.mover.noteDamageDealt(e.damage)
|
||||
|
||||
method onRoundEnded*(bot: DevControlBot, e: RoundEndedEventForBot) =
|
||||
bot.enemies = @[]
|
||||
bot.mover.resetRound()
|
||||
|
||||
method ageEnemies(bot: DevControlBot) =
|
||||
# heat field is only as good as the freshest scans; stale entries stay
|
||||
# plausible-looking but poison the grid, so they go
|
||||
bot.enemies = bot.enemies.filterIt(it.lastSeenTick >= bot.tick - EnemyStaleTicks)
|
||||
|
||||
method buildWorldState(bot: DevControlBot): WorldState =
|
||||
WorldState(selfX: getX(), selfY: getY(),
|
||||
selfSpeed: getSpeed(), selfHeading: getDirection(),
|
||||
selfRadarHeading: getRadarDirection(), selfEnergy: getEnergy(),
|
||||
arenaWidth: getArenaWidth().float, arenaHeight: getArenaHeight().float,
|
||||
tick: bot.tick, enemies: bot.enemies)
|
||||
|
||||
method run*(bot: DevControlBot) =
|
||||
initRadar() # once: radar + scan turn BLACK = programmed
|
||||
while isRunning():
|
||||
# One radar command per tick, unconditionally, BEFORE go() — so the command
|
||||
# is part of this tick's intent and no tick is ever left without one.
|
||||
# One radar command and one movement command per tick, unconditionally,
|
||||
# BEFORE go() — so both are part of this tick's intent.
|
||||
commandRadar()
|
||||
bot.ageEnemies() # stale scans dropped before they paint heat
|
||||
let (speed, turnRate) = bot.mover.computeMove(bot.buildWorldState())
|
||||
setTargetSpeed(speed)
|
||||
setTurnRate(turnRate)
|
||||
go()
|
||||
inc bot.tick
|
||||
|
||||
when isMainModule:
|
||||
# argv[1] may override the metadata file (used by DevControlBot/DevControlBot.sh);
|
||||
|
||||
Reference in New Issue
Block a user