diff --git a/BNNBot_garage/src/BNNBot.nim b/BNNBot_garage/src/BNNBot.nim index 413e728..e5c5b71 100644 --- a/BNNBot_garage/src/BNNBot.nim +++ b/BNNBot_garage/src/BNNBot.nim @@ -36,11 +36,23 @@ method onScannedBot*(bot: BNNBot, e: ScannedBotEvent) = bot.hasLastPos = true bot.hasContact = true + let arenaW = getArenaWidth().float + let arenaH = getArenaHeight().float + let enemyX = e.x + let enemyY = e.y let scan = ScanData( - bearing: bot.enemyBearing, - distance: bot.distance, - velocity: bot.velocity, - heading: bot.heading, + 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, ) let vec = encode(scan) let hamming = if bot.hasPrev: hammingDistance(bot.prevVec, vec) else: 0 diff --git a/BNNBot_garage/src/binary_encoding.nim b/BNNBot_garage/src/binary_encoding.nim index 2acce7e..708e950 100644 --- a/BNNBot_garage/src/binary_encoding.nim +++ b/BNNBot_garage/src/binary_encoding.nim @@ -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: