Files
SirStone 67d185880d 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.
2026-10-04 18:16:24 +02:00

96 lines
3.7 KiB
Nim

## Resolution + env gating for the universal battle-test runner.
##
## Deliberately thin: everything that already exists in common_libs/test_framework
## (compileBots) is imported, not reimplemented. We only add:
## - stem derivation (strip _garage, see bot_compiler.nim:9)
## - `.battletest.json` per-garage overrides
## - the SKIP-when-no-jars policy
import std/[os, strutils, json]
import ../../common_libs/test_framework/server_manager ## DefaultServerJar (import only, never modified)
type
Overrides* = object
rounds*: int ## 0 = not overridden
opponents*: seq[string] ## empty = not overridden
ResolvedBot* = object
dir*: string ## directory to hand to the battle runner (or stage)
stem*: string ## bot name, _garage stripped
rounds*: int ## effective rounds for this bot (0 = global)
opponents*: seq[string] ## per-garage override, empty = global matrix
const GarageSuffix* = "_garage"
const OverrideFile* = ".battletest.json"
proc stemOf*(path: string): string =
## Mirrors bot_compiler.nim:9 — last path component minus _garage.
result = lastPathPart(absolutePath(path))
if result.endsWith(GarageSuffix):
result = result[0 ..< result.len - GarageSuffix.len]
proc innerBotDir*(path: string): string =
## Some garages keep the actual bot in a nested `<Stem>/` subdir
## (e.g. DevControlBot_garage/DevControlBot/). Descend into it when the
## given dir has no src/ and no binary but has a same-named subdir.
let abs = absolutePath(path)
let stem = stemOf(abs)
if not dirExists(abs / "src") and not fileExists(abs / stem) and
dirExists(abs / stem):
return abs / stem
abs
proc readOverrides*(path: string): Overrides =
let f = absolutePath(path) / OverrideFile
if not fileExists(f): return
try:
let n = parseJson(readFile(f))
if n.hasKey("rounds"): result.rounds = n["rounds"].getInt()
if n.hasKey("opponents"):
for o in n["opponents"].getElems(): result.opponents.add o.getStr()
except JsonParsingError as e:
raise newException(ValueError, f & " is not valid JSON: " & e.msg)
proc resolveBot*(path: string): ResolvedBot =
## path may be a garage (`X_garage`) or a bot dir. Returns the dir the
## runner should use plus the bot's stem and any .battletest.json overrides.
if not dirExists(path):
raise newException(IOError, "bot path is not a directory: " & path)
result.dir = innerBotDir(path)
result.stem = stemOf(result.dir)
let ov = readOverrides(result.dir)
result.rounds = ov.rounds
result.opponents = ov.opponents
# --- env gating -------------------------------------------------------------
const
RepoRoot* = currentSourcePath().parentDir.parentDir.parentDir
AdversaryRoot* = currentSourcePath().parentDir / "adversaries"
const DefaultRunnerJarHint* =
"/home/davide/Projects/tank-royale/runner/examples/lib/robocode-tankroyale-runner.jar"
type
Gate* = object
ok*: bool ## false => SKIP (quit 0), not a failure
reason*: string
serverJar*: string
runnerJar*: string
proc gate*(serverOverride = "", runnerOverride = ""): Gate =
## SKIP (exit 0) when the JARs are missing — root AGENTS.md prescribes this
## and no garage implements it yet. Explicit overrides bypass the env.
result.serverJar =
if serverOverride.len > 0: serverOverride
else: getEnv("TR_SERVER_JAR", DefaultServerJar) ## same default as server_manager.nim
result.runnerJar =
if runnerOverride.len > 0: runnerOverride
else: getEnv("TR_BATTLE_RUNNER", DefaultRunnerJarHint)
if not fileExists(result.serverJar):
result.reason = "TR_SERVER_JAR does not exist: " & result.serverJar
elif not fileExists(result.runnerJar):
result.reason = "TR_BATTLE_RUNNER does not exist: " & result.runnerJar
else:
result.ok = true