## Construction test for the Dodger archetype (tests/archetypes/Dodger). ## The bot's run loop contains no decision logic: it calls `dodgeDecision` and ## applies the result, so pinning the spec function's outputs on synthetic ## inputs pins the bot's behaviour by construction. Pure Nim, no Java. import std/[math] import dodger_spec var failed = 0 proc check(name: string, cond: bool, detail: string = "") = if cond: echo " ok ", name else: echo " FAIL ", name, " [", detail, "]"; inc failed proc approx(a, b: float64): bool = abs(a - b) < 1e-9 block: echo "dodger 1: wave ETA" let w = DodgeWave(originX: 0.0, originY: 0.0, fireTick: 0, bulletSpeed: 16.0) check("eta = dist/speed - elapsed", approx(waveETA(w, 160.0, 0.0, 0), 10.0), $waveETA(w, 160.0, 0.0, 0)) check("eta decreases one tick per tick", approx(waveETA(w, 160.0, 0.0, 4), 6.0)) check("eta negative once past", waveETA(w, 160.0, 0.0, 20) < 0.0) block: echo "dodger 2: far wave -> patrol" let w = DodgeWave(originX: 0.0, originY: 0.0, fireTick: 0, bulletSpeed: 16.0) let c = dodgeDecision(w, DodgeOwn(x: 1600.0, y: 0.0, heading: 0.0), 0, 800.0, 600.0, 1.0) check("not dodging", not c.dodging) check("patrol speed", approx(c.targetSpeed, PatrolSpeed)) check("no turn", approx(c.turnRate, 0.0)) check("strafe sign carried", approx(c.strafeSign, 1.0)) block: echo "dodger 3: spent wave -> patrol" let w = DodgeWave(originX: 0.0, originY: 0.0, fireTick: 100, bulletSpeed: 16.0) let c = dodgeDecision(w, DodgeOwn(x: 160.0, y: 0.0, heading: 0.0), 0, 800.0, 600.0, -1.0) check("not dodging", not c.dodging) check("strafe sign retained", approx(c.strafeSign, -1.0)) block: echo "dodger 4: close wave -> strafe perpendicular" let w = DodgeWave(originX: 0.0, originY: 300.0, fireTick: 0, bulletSpeed: 16.0) let c = dodgeDecision(w, DodgeOwn(x: 160.0, y: 300.0, heading: 0.0), 0, 800.0, 600.0, 1.0) check("dodging", c.dodging) check("full throttle", approx(c.targetSpeed, StrafeSpeed)) check("turns toward +90 bearing (clamped to 10)", approx(c.turnRate, 10.0), $c.turnRate) check("strafe sign +1", approx(c.strafeSign, 1.0)) let c2 = dodgeDecision(w, DodgeOwn(x: 160.0, y: 300.0, heading: 90.0), 0, 800.0, 600.0, 1.0) check("already perpendicular -> no turn", approx(c2.turnRate, 0.0), $c2.turnRate) block: echo "dodger 5: corner flip near a wall" let w = DodgeWave(originX: 0.0, originY: 0.0, fireTick: 0, bulletSpeed: 16.0) check("nearWall true inside the band", nearWall(50.0, 300.0, 800.0, 600.0)) check("nearWall false in the open", not nearWall(400.0, 300.0, 800.0, 600.0)) let c = dodgeDecision(w, DodgeOwn(x: 50.0, y: 0.0, heading: 0.0), 0, 800.0, 600.0, 1.0) check("strafe sign flipped", approx(c.strafeSign, -1.0), $c.strafeSign) check("turns toward -90 bearing", approx(c.turnRate, -10.0), $c.turnRate) let c2 = dodgeDecision(w, DodgeOwn(x: 50.0, y: 0.0, heading: 0.0), 0, 800.0, 600.0, -1.0) check("flip is an involution on the sign", approx(c2.strafeSign, 1.0)) block: echo "dodger 6: determinism" let w = DodgeWave(originX: 10.0, originY: 20.0, fireTick: 3, bulletSpeed: 17.0) let a = dodgeDecision(w, DodgeOwn(x: 120.0, y: 40.0, heading: 33.0), 7, 800.0, 600.0, 1.0) let b = dodgeDecision(w, DodgeOwn(x: 120.0, y: 40.0, heading: 33.0), 7, 800.0, 600.0, 1.0) check("identical inputs -> identical output", a.turnRate == b.turnRate and a.targetSpeed == b.targetSpeed and a.strafeSign == b.strafeSign and a.dodging == b.dodging) check("reaction window is 14 ticks", ReactionTicks == 14.0) echo "" if failed == 0: echo "all dodger tests passed" else: echo failed, " dodger test(s) FAILED"; quit(1)