feat(reservoir): warm-start grid with analytical lead values

Pre-populate all LeadGrid cells with arcsin(vPerp/bulletSpeed) so the
grid starts warm instead of cold, avoiding the early-round 0-data
fallback to -999 (no-lead) firing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 08:38:37 +02:00
parent 2d7413666c
commit a20796cf9b
+11 -1
View File
@@ -16,8 +16,18 @@ type
LeadGrid* = object
cells: array[VPERP_BINS * DIST_BINS, GridCell] # 17 × 8 = 136 cells
const BULLET_SPEED = 14.0 # power 2 bullet speed in pixels/tick
proc initLeadGrid*(): LeadGrid =
result = LeadGrid()
for vBin in 0..<VPERP_BINS:
for dBin in 0..<DIST_BINS:
let vPerp = float(vBin) - 8.0
let sinVal = clamp(vPerp / BULLET_SPEED, -1.0, 1.0)
let offsetRad = arcsin(sinVal)
let idx = vBin * DIST_BINS + dBin
result.cells[idx].sumSin = sin(offsetRad)
result.cells[idx].sumCos = cos(offsetRad)
result.cells[idx].count = 1
proc cellIndex(vPerp: float, distance: float): int {.inline.} =
let vBin = clamp(int(vPerp + 8.5), 0, VPERP_BINS - 1)