cdde60d79f
- Add gotoTick/aimToTick controller functions (#25) - Update network dims: actor 5→6, state 42→44 (#26) - Rewrite mapActions for 6-dim command space (#27) - Delete stale weight files (shape mismatch) - Fix existing tests for new signatures Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
1.2 KiB
Nim
25 lines
1.2 KiB
Nim
## Pure tick-level controllers for goto(x,y) and aimTo(x,y).
|
|
## No bot object needed — all inputs are explicit parameters.
|
|
|
|
import tankroyale_botapi
|
|
|
|
proc gotoTick*(targetX, targetY, botX, botY, direction, speed: float): (float, float) =
|
|
## Returns (targetSpeed, turnRate) to drive toward (targetX, targetY).
|
|
## Selects forward or reverse automatically based on bearing.
|
|
let bearing = normalizeRelativeAngle(directionTo(botX, botY, targetX, targetY) - direction)
|
|
let (dirSign, effBearing) =
|
|
if abs(bearing) > 90.0:
|
|
(-1.0, normalizeRelativeAngle(bearing + 180.0))
|
|
else:
|
|
(1.0, bearing)
|
|
let dist = distanceTo(botX, botY, targetX, targetY)
|
|
let maxTurn = calcMaxTurnRate(speed)
|
|
let turnRate = effBearing.clamp(-maxTurn, maxTurn)
|
|
let rawSpeed = getNewTargetSpeed(MAX_SPEED, abs(speed), dist)
|
|
(dirSign * rawSpeed, turnRate)
|
|
|
|
proc aimToTick*(targetX, targetY, botX, botY, gunDirection: float): float =
|
|
## Returns gunTurnRate (clamped to ±MAX_GUN_TURN_RATE) to rotate gun toward target.
|
|
let bearing = normalizeRelativeAngle(directionTo(botX, botY, targetX, targetY) - gunDirection)
|
|
bearing.clamp(-MAX_GUN_TURN_RATE, MAX_GUN_TURN_RATE)
|