feat(BNNBot): add energy (8+8 bits) and gun ready (1 bit) — 117 bits total

Added myEnergy, enemyEnergy, and canFire to ScanData. Energy fields quantize 0-150 → 8 bits each; gun ready is 1 bit (1 = can fire, 0 = can't). Updated total encoding from 100 to 117 bits.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 23:21:39 +02:00
parent 938c259260
commit 152fcba0cc
2 changed files with 34 additions and 13 deletions
+15 -12
View File
@@ -41,18 +41,21 @@ method onScannedBot*(bot: BNNBot, e: ScannedBotEvent) =
let enemyX = e.x
let enemyY = e.y
let scan = ScanData(
bearing: bot.enemyBearing,
distance: bot.distance,
velocity: bot.velocity,
heading: bot.heading,
myWallN: arenaH - by,
myWallS: by,
myWallE: arenaW - bx,
myWallW: bx,
enemyWallN: arenaH - enemyY,
enemyWallS: enemyY,
enemyWallE: arenaW - enemyX,
enemyWallW: enemyX,
bearing: bot.enemyBearing,
distance: bot.distance,
velocity: bot.velocity,
heading: bot.heading,
myWallN: arenaH - by,
myWallS: by,
myWallE: arenaW - bx,
myWallW: bx,
enemyWallN: arenaH - enemyY,
enemyWallS: enemyY,
enemyWallE: arenaW - enemyX,
enemyWallW: enemyX,
myEnergy: getEnergy(),
enemyEnergy: e.energy,
canFire: getGunHeat() <= 0.0,
)
let vec = encode(scan)
let hamming = if bot.hasPrev: hammingDistance(bot.prevVec, vec) else: 0
+19 -1
View File
@@ -1,7 +1,7 @@
import std/math
const
TOTAL_BITS* = 100
TOTAL_BITS* = 117
type
BinaryVector* = array[TOTAL_BITS, uint8]
@@ -19,6 +19,9 @@ type
enemyWallS*: float # enemy distance to south wall
enemyWallE*: float # enemy distance to east wall
enemyWallW*: float # enemy distance to west wall
myEnergy*: float # 0-150
enemyEnergy*: float # 0-150
canFire*: bool # gun heat == 0
const MAX_DISTANCE = 1414.0 # diagonal of 1000x1000 arena
@@ -84,6 +87,21 @@ proc encode*(scan: ScanData): BinaryVector =
for i in 0..<7: result[offset + i] = bits[i]
offset += 7
# 9. My energy (8 bits, 0-150)
let myE = int(clamp(scan.myEnergy / 150.0 * 149.0, 0.0, 149.0))
let myEBits = toBits(myE, 8)
for i in 0..<8: result[offset + i] = myEBits[i]
offset += 8
# 10. Enemy energy (8 bits, 0-150)
let enE = int(clamp(scan.enemyEnergy / 150.0 * 149.0, 0.0, 149.0))
let enEBits = toBits(enE, 8)
for i in 0..<8: result[offset + i] = enEBits[i]
offset += 8
# 11. Can fire (1 bit)
result[offset] = if scan.canFire: 1'u8 else: 0'u8
proc formatBinary*(vec: BinaryVector): string =
for b in vec:
result &= (if b == 1: "1" else: "0")