tfil: hold the committed dodge while a bullet is within 15 tiles

Proposal #2 (active-dodge commit lock), milder half only: while a tracked
bullet is within LockRadiusTiles (15 x 36px), suppress the tile-crossing
replan so the committed dodge direction survives the crossing.  The 15-tick
dwell and the danger safety valve still apply.

A hard freeze until the bullet passed (no dwell expiry) was measured and
reverted: the bot parked on the committed tile and absorbed the shot
(damage taken/round 26.8 -> 53.9 over 12 opponents x 20 rounds).

Measured on 12 opponents x 40 rounds (RawRecord, verified CONTIGUOUS):
damage taken/round 30.8 -> 25.5, damage dealt/round 73.2 -> 72.1,
rounds won 358/480 -> 360/480.

Raising CommitTicks 15 -> 25 (proposal #3) measured harmful and was reverted.
Proposal #1 (speculative bullet on 'could fire') not implemented: TFIL already
spawns a tracked bullet from the same-tick energy drop, and speculation would
be a ~70% false-positive flood.
This commit is contained in:
2026-10-06 20:14:35 +02:00
parent 7f0fbccec6
commit b6425ac7f2
@@ -90,6 +90,8 @@ const
CommitTicks = 15 ## ticks to commit to a dodge point
MinCommitTicks = 5 ## must commit this long before a danger replan
LockRadiusTiles = 15.0 ## freeze the committed dodge while a tracked
## bullet is this many tiles away or closer
DangerReplanThreshold = 25.0 ## replan on serious threats only (bullet core)
CoolestLevels = 2 ## how many distinct lava values count as "cool"
MaxTrackedBullets = 20 ## hard cap on tracked bullets
@@ -299,6 +301,15 @@ proc detectFires(m: var TfilModule, ws: WorldState) =
m.spawnTrackedWave(ws, ei, p)
m.fire.endScan()
proc bulletLock(m: TfilModule, selfX, selfY: float): bool =
## True while any tracked bullet is within LockRadiusTiles of us: an active
## dodge, during which the committed tile is frozen (proposal #2).
let r2 = (LockRadiusTiles * GridSize) * (LockRadiusTiles * GridSize)
for b in m.bullets:
let dx = selfX - b.x
let dy = selfY - b.y
if dx * dx + dy * dy <= r2: return true
proc advanceBullets(m: var TfilModule, selfX, selfY: float) =
## Advance positions and reap bullets that passed us, left the arena, or are
## too old.
@@ -656,8 +667,20 @@ proc computeMove*(m: var TfilModule, ws: WorldState): MoveCommand =
for ei in ws.enemies:
m.fire.prevEnergySet(ei.id, ei.energy)
# Tile-change replan: crossing a tile boundary cancels the commitment.
if (not jumped) and (m.callCount > 0) and (m.commitTicks > 0):
# Per-tick: advance existing bullets, detect new fires
m.advanceBullets(ws.selfX, ws.selfY)
m.detectFires(ws)
# Active-dodge lock: while a tracked bullet is within LockRadiusTiles we stop
# the tile-crossing replan, so the committed dodge direction survives the
# crossing. The 15-tick dwell still expires and the safety valve still fires
# (a hard freeze until the bullet passed measured far worse: the bot parked and
# ate the shot).
let locked = m.bulletLock(ws.selfX, ws.selfY)
# Tile-change replan: crossing a tile boundary cancels the commitment,
# unless we are mid-dodge (locked).
if (not jumped) and (not locked) and (m.callCount > 0) and (m.commitTicks > 0):
let curTileCol = clamp(int((ws.selfX - m.marginX) / GridSize), 0, m.cols - 1)
let curTileRow = clamp(int((ws.selfY - m.marginY) / GridSize), 0, m.rows - 1)
if curTileCol != m.lastTileCol or curTileRow != m.lastTileRow:
@@ -665,10 +688,6 @@ proc computeMove*(m: var TfilModule, ws: WorldState): MoveCommand =
m.cachedHull = @[]
m.cachedInsideTiles = @[]
# Per-tick: advance existing bullets, detect new fires
m.advanceBullets(ws.selfX, ws.selfY)
m.detectFires(ws)
# Recompute the lava field from scratch
for i in 0..<m.lava.len: m.lava[i] = 0.0
for b in m.bullets: m.paintBulletHeat(b)