ChimeraBot_garage: M6 — residual head, predictor fusion, fallback influence, G7 head-to-head
This commit is contained in:
@@ -94,21 +94,18 @@ proc guardSkip*() =
|
||||
echo "Skipping bench: TR_SERVER_JAR / TR_BATTLE_RUNNER / sample bots missing."
|
||||
quit(0)
|
||||
|
||||
proc runBattleHard*(serverUrl: string, botDirs: seq[string], rounds: int,
|
||||
timeoutMs = 90000, maxSpeed = true): bool =
|
||||
## Hard-timeout battle: `test_framework.runBattleRunner` can block forever when
|
||||
## the Java runner stops emitting output while still alive, so benches use this
|
||||
## wrapper (shell redirect to a log, poll, then kill). Battles normally take
|
||||
## 1-3 s, so 90 s is generous and bounds a hang.
|
||||
proc runBattleHardLog*(serverUrl: string, botDirs: seq[string], rounds: int,
|
||||
timeoutMs = 90000, maxSpeed = true,
|
||||
logName = "chimera_runner"): tuple[ok: bool, logPath: string] =
|
||||
## Hard-timeout battle that KEEPS the runner log, for benches that need the
|
||||
## per-round results (G7). `battle_runner`'s TestBattleRunner emits JSON lines.
|
||||
let jar = getEnv("TR_BATTLE_RUNNER", RunnerJar)
|
||||
let classDir = getEnv("TR_BATTLE_RUNNER_DIR", RunnerDir)
|
||||
let logf = getTempDir() / "chimera_runner.log"
|
||||
let logf = getTempDir() / (logName & ".log")
|
||||
var args = "--server-url " & quoteShell(serverUrl) &
|
||||
" --rounds " & $rounds &
|
||||
" --bot-dirs " & quoteShell(botDirs.join(","))
|
||||
if maxSpeed: args.add " --max-speed"
|
||||
# coreutils `timeout -s KILL` is the hard guarantee: if the Java runner blocks
|
||||
# and ignores SIGTERM (shutdown hooks), the shell still kills it at the limit.
|
||||
let hardSec = int(timeoutMs div 1000) + 5
|
||||
let cmd = "timeout -s KILL " & $hardSec & " java -cp " &
|
||||
quoteShell(classDir & ":" & jar) &
|
||||
@@ -126,10 +123,18 @@ proc runBattleHard*(serverUrl: string, botDirs: seq[string], rounds: int,
|
||||
sleep(200)
|
||||
if p.peekExitCode() == -1: p.kill()
|
||||
p.close()
|
||||
return false
|
||||
result = p.peekExitCode() == 0
|
||||
return (false, logf)
|
||||
result = (p.peekExitCode() == 0, logf)
|
||||
p.close()
|
||||
|
||||
proc runBattleHard*(serverUrl: string, botDirs: seq[string], rounds: int,
|
||||
timeoutMs = 90000, maxSpeed = true): bool =
|
||||
## Hard-timeout battle: `test_framework.runBattleRunner` can block forever when
|
||||
## the Java runner stops emitting output while still alive, so benches use this
|
||||
## wrapper (shell redirect to a log, poll, then kill). Battles normally take
|
||||
## 1-3 s, so 90 s is generous and bounds a hang.
|
||||
runBattleHardLog(serverUrl, botDirs, rounds, timeoutMs, maxSpeed).ok
|
||||
|
||||
proc deps*(): seq[string] =
|
||||
for p in ["robocode_tankroyale_botapi", "jsony"]:
|
||||
let (outp, _) = execCmdEx("nimble path " & p)
|
||||
@@ -139,10 +144,14 @@ proc deps*(): seq[string] =
|
||||
if line.len == 0: quit("Cannot resolve dependency: " & p)
|
||||
result.add "--path:" & line
|
||||
|
||||
proc stageBot*(tag: string, defines: seq[string] = @[]): string =
|
||||
## Compile ChimeraBot into a throwaway /tmp dir with its json + boot script.
|
||||
let botDir = getTempDir() / ("chimera_stage_" & tag) / "ChimeraBot"
|
||||
removeDir(getTempDir() / ("chimera_stage_" & tag))
|
||||
proc stageBot*(tag: string, defines: seq[string] = @[], name = "ChimeraBot"): string =
|
||||
## Compile ChimeraBot into a throwaway /tmp dir with a json + boot script. The
|
||||
## optional `name` gives a distinct identity so two staged arms can fight in
|
||||
## one battle (G7 head-to-head); the default "ChimeraBot" keeps the older
|
||||
## benches byte-identical.
|
||||
let root = getTempDir() / ("chimera_stage_" & tag)
|
||||
let botDir = root / name
|
||||
removeDir(root)
|
||||
createDir(botDir)
|
||||
let bin = botDir / "ChimeraBot"
|
||||
var cmd = "nim c -d:release --hints:off "
|
||||
@@ -152,10 +161,15 @@ proc stageBot*(tag: string, defines: seq[string] = @[]): string =
|
||||
let (outp, code) = execCmdEx(cmd, options = {poEvalCommand})
|
||||
if code != 0 or not fileExists(bin):
|
||||
quit("ChimeraBot (" & tag & ") compile failed:\n" & outp)
|
||||
copyFile(GarageSrc / "ChimeraBot.json", botDir / "ChimeraBot.json")
|
||||
writeFile(botDir / "ChimeraBot.sh",
|
||||
"#!/bin/sh\ncd -- \"$(dirname -- \"$0\")\"\nexec \"./ChimeraBot\"\n")
|
||||
let sh = botDir / "ChimeraBot.sh"
|
||||
# Identity JSON: rename only the `name` field, then launch with it explicitly
|
||||
# (the binary's compile-time default is the garage ChimeraBot.json).
|
||||
var js = readFile(GarageSrc / "ChimeraBot.json")
|
||||
js = js.replace("\"ChimeraBot\"", "\"" & name & "\"")
|
||||
writeFile(botDir / (name & ".json"), js)
|
||||
writeFile(botDir / (name & ".sh"),
|
||||
"#!/bin/sh\ncd -- \"$(dirname -- \"$0\")\"\nexec \"./ChimeraBot\" \"" &
|
||||
name & ".json\"\n")
|
||||
let sh = botDir / (name & ".sh")
|
||||
setFilePermissions(sh, getFilePermissions(sh) + {fpUserExec, fpGroupExec, fpOthersExec})
|
||||
botDir
|
||||
|
||||
|
||||
Reference in New Issue
Block a user