Files
SirRoboGarage/common_libs/gun_harness/gun_interface.nim
T
SirStone 1ed7797cb6 feat(ModularBot): 6 guns, pattern matcher, melee modules, adversarial bots
- New guns: guess-factor (GF histogram), pattern-matcher (movement tape replay)
- New modules: minimum-risk melee movement, spinning melee radar
- New test bots: PatternMover, RandomMover, WaveSurfer
- Fixed: FeedbackEvent now carries actualX/actualY for proper GF learning
- Fixed: TM gun warmup gating + directional residuals
- Fixed: circular gun integrated formula + multi-bin omega cache
- Fixed: oscillator wall-bounce lockout
- Fixed: phantom meteor perpendicular body orientation
- 6/6 battle wins across all enemy types
2026-09-20 00:59:53 +02:00

51 lines
1.4 KiB
Nim

## Gun harness — shared types and Gun concept.
## Coordinate system: 0° = East, CCW positive (Tank Royale standard).
## Bullet speed formula: 20 - 3 * power.
import std/math
const BotRadius* = 18.0 ## hit detection radius in px
type
WorldState* = object
## All raw data given to every gun every tick.
# Enemy
enemyX*, enemyY*: float
enemySpeed*, enemyHeading*: float
# Self
selfX*, selfY*: float
selfSpeed*, selfHeading*: float
selfRadarHeading*: float
selfEnergy*: float
enemyEnergy*: float
# Arena
arenaWidth*, arenaHeight*: float
# Meta
tick*: int
GunPrediction* = object
## Absolute (x, y) where the gun predicts the enemy will be.
x*, y*: float
FeedbackEvent* = object
## Outcome of a resolved virtual bullet.
prediction*: GunPrediction
actualX*, actualY*: float ## actual enemy position at resolution time
bulletPower*: float
missDistance*: float ## px; < BotRadius = hit
hit*: bool
proc bulletSpeed*(power: float): float {.inline.} =
20.0 - 3.0 * power
## Gun concept — any type T implementing these two procs is a valid gun.
template isGun*(T: typedesc): bool =
compiles(
block:
var g: T
let ws = WorldState()
let p: GunPrediction = g.predict(ws, 0.0)
let fe = FeedbackEvent()
g.onResult(fe)
)