feat(BNNBot): add wall distances for both bots to binary encoding (100 bits total)

8 new fields in ScanData (myWallN/S/E/W, enemyWallN/S/E/W), 7 bits each via Gray code,
appended after existing 44 bits. TOTAL_BITS 44 → 100.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 23:17:26 +02:00
parent f82a74731d
commit 938c259260
2 changed files with 40 additions and 5 deletions
+24 -1
View File
@@ -1,7 +1,7 @@
import std/math
const
TOTAL_BITS* = 44
TOTAL_BITS* = 100
type
BinaryVector* = array[TOTAL_BITS, uint8]
@@ -11,6 +11,14 @@ type
distance*: float # 0-1414 pixels (will be converted to 0-100%)
velocity*: float # -8 to +8 integer steps
heading*: float # 0-360 degrees
myWallN*: float # our distance to north wall
myWallS*: float # our distance to south wall
myWallE*: float # our distance to east wall
myWallW*: float # our distance to west wall
enemyWallN*: float # enemy distance to north wall
enemyWallS*: float # enemy distance to south wall
enemyWallE*: float # enemy distance to east wall
enemyWallW*: float # enemy distance to west wall
const MAX_DISTANCE = 1414.0 # diagonal of 1000x1000 arena
@@ -60,6 +68,21 @@ proc encode*(scan: ScanData): BinaryVector =
let hCos = int((cos(degToRad(scan.heading)) + 1.0) / 2.0 * 199.0)
let hCosBits = toBits(clamp(hCos, 0, 199), 8)
for i in 0..<8: result[offset + i] = hCosBits[i]
offset += 8
# 7. My wall distances (7 bits each, 0-100% of arena dimension)
for wall in [scan.myWallN, scan.myWallS, scan.myWallE, scan.myWallW]:
let pct = int(clamp(wall / 1000.0 * 99.0, 0.0, 99.0))
let bits = toBits(pct, 7)
for i in 0..<7: result[offset + i] = bits[i]
offset += 7
# 8. Enemy wall distances (7 bits each)
for wall in [scan.enemyWallN, scan.enemyWallS, scan.enemyWallE, scan.enemyWallW]:
let pct = int(clamp(wall / 1000.0 * 99.0, 0.0, 99.0))
let bits = toBits(pct, 7)
for i in 0..<7: result[offset + i] = bits[i]
offset += 7
proc formatBinary*(vec: BinaryVector): string =
for b in vec: