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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user