chore: rename libs→common_libs, all bot dirs to _garage suffix, fix all path refs
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
## Standalone radar lock module for Robocode Tank Royale (1v1).
|
||||
## No bot-specific imports — takes plain floats, returns radarTurnRate.
|
||||
##
|
||||
## Tank Royale radar uses standard math convention: 0° = east, CCW positive.
|
||||
## Angles are in degrees.
|
||||
|
||||
import std/math
|
||||
|
||||
const
|
||||
MaxRadarTurn* = 45.0
|
||||
DefaultOvershootDeg* = 5.0
|
||||
|
||||
var overShootDeg* = DefaultOvershootDeg
|
||||
|
||||
proc init*() =
|
||||
## Reset module to defaults.
|
||||
## In your bot's constructor set:
|
||||
## adjustRadarForBodyTurn = true
|
||||
## adjustRadarForGunTurn = true
|
||||
overShootDeg = DefaultOvershootDeg
|
||||
|
||||
proc normalizeRelative(angle: float64): float64 {.inline.} =
|
||||
result = angle mod 360.0
|
||||
if result >= 180.0: result -= 360.0
|
||||
elif result < -180.0: result += 360.0
|
||||
|
||||
proc doRadar*(currentRadarHeading, enemyBearing: float64): float64 =
|
||||
## Returns radarTurnRate (degrees/tick, positive = clockwise).
|
||||
##
|
||||
## currentRadarHeading: current radar direction in degrees (0=east, CCW+).
|
||||
## enemyBearing: absolute bearing to enemy in same coordinate system.
|
||||
##
|
||||
## Handles angle wrapping, clamps to [-45, +45], adds overshoot sweep.
|
||||
var turn = normalizeRelative(enemyBearing - currentRadarHeading)
|
||||
# Add overshoot in the same direction as the turn to maintain lock
|
||||
if turn < 0.0: turn -= overShootDeg
|
||||
else: turn += overShootDeg
|
||||
result = turn.clamp(-MaxRadarTurn, MaxRadarTurn)
|
||||
Reference in New Issue
Block a user