diff --git a/BNNBot_garage/src/BNNBot.nim b/BNNBot_garage/src/BNNBot.nim index e5c5b71..6592e7f 100644 --- a/BNNBot_garage/src/BNNBot.nim +++ b/BNNBot_garage/src/BNNBot.nim @@ -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 diff --git a/BNNBot_garage/src/binary_encoding.nim b/BNNBot_garage/src/binary_encoding.nim index 708e950..d02623b 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* = 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")