## Deterministic, offline check of the virtual-bullet overlay (`vbullet_draw`). ## ## NO battle, NO Java, NO server: it fabricates a tracker state, calls the same ## `collectVirtualBulletPrims` / `emitVbPrims` the live bot calls, and asserts ## the primitive counts, the geometry (path and aim point are collinear), the ## filter and cap behaviour, and the SVG emission. It also pins the shared ## turret/overlay colour table. ## ## Run: nim c -r ModularBot_garage/tests/test_vbullet_draw.nim import std/[math, strutils, tables, sequtils] import robocode_tankroyale_botapi import gun_harness/gun_interface import gun_harness/virtual_bullets as vb import vbullet_draw var failures = 0 proc check(name: string, ok: bool) = if ok: echo "PASS: ", name else: echo "FAIL: ", name; inc failures # ── a fixed tracker: gun 1 (Linear) and gun 5 (Pattern), 4 power bins each ──── const SelfX = 100.0 const SelfY = 100.0 const AimX = 300.0 const AimY = 300.0 const TargetId = 7 proc makeTracker(): VirtualTracker = result = vb.initTracker(17) let s0 = WorldState(selfX: SelfX, selfY: SelfY, enemyX: AimX, enemyY: AimY, enemySpeed: 0.0, enemyHeading: 0.0, arenaWidth: 1000.0, arenaHeight: 1000.0, tick: 0) var preds: array[len(PowerBins), GunPrediction] for i in 0.. 0 and sel.allIt(it.gunId == 1) check "named filter (Pattern id 5) yields only gun 5", p5.len > 0 and p5.allIt(it.gunId == 5) check "all filter yields both guns", all.len == sel.len + p5.len proc testCap() = var t = makeTracker() let one = collectVirtualBulletPrims(t, 1, VbFilterAll, 1) var bullets = 0 for p in one: if p.kind == vpPath: inc bullets check "cap=1 draws exactly one bullet", bullets == 1 proc testResolved() = let resolved = @[ VbResolved(gunId: 1, aimX: AimX, aimY: AimY, actualX: AimX + 25.0, actualY: AimY, hit: false), VbResolved(gunId: 5, aimX: AimX, aimY: AimY, actualX: AimX + 3.0, actualY: AimY, hit: true), ] let miss = collectResolvedPrims(resolved, 1, VbFilterAll, 100) check "one resolved bullet -> miss vector + marker (2 prims): " & $miss.len, miss.len == 4 check "first resolved is a MISS marker", miss[0].kind == vpMiss and miss[1].kind == vpMissMark check "second resolved is a HIT marker", miss[2].kind == vpMiss and miss[3].kind == vpHit proc testEmit() = clearGraphics() var t = makeTracker() let prims = collectVirtualBulletPrims(t, 1, VbFilterSelected, 100) let n = emitVbPrims(prims, ["HeadOn", "Linear", "Tsetlin", "Circular", "GuessFactor", "Pattern"]) let svg = svgOutput() check "emit returns the primitive count: " & $n, n == prims.len check "SVG carries one per path primitive", svg.count(" 0: echo "\n", failures, " check(s) FAILED" quit(1) echo "\nAll vbullet-draw checks passed."