feat(BNNBot): switch to Gray code encoding for smooth Hamming distance
This commit is contained in:
Binary file not shown.
@@ -14,10 +14,14 @@ type
|
|||||||
|
|
||||||
const MAX_DISTANCE = 1414.0 # diagonal of 1000x1000 arena
|
const MAX_DISTANCE = 1414.0 # diagonal of 1000x1000 arena
|
||||||
|
|
||||||
|
proc toGray(value: int): int =
|
||||||
|
value xor (value shr 1)
|
||||||
|
|
||||||
proc toBits(value: int, bits: int): seq[uint8] =
|
proc toBits(value: int, bits: int): seq[uint8] =
|
||||||
result = newSeq[uint8](bits)
|
result = newSeq[uint8](bits)
|
||||||
|
let gray = toGray(value)
|
||||||
for i in 0..<bits:
|
for i in 0..<bits:
|
||||||
result[bits - 1 - i] = uint8((value shr i) and 1)
|
result[bits - 1 - i] = uint8((gray shr i) and 1)
|
||||||
|
|
||||||
proc encode*(scan: ScanData): BinaryVector =
|
proc encode*(scan: ScanData): BinaryVector =
|
||||||
var offset = 0
|
var offset = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user