Chess BitBoards in kotlin. Which datatype?

202 views Asked by At

i think this question has not been asked yet.

Thing is, in chess we use bitboards to speed move-generation-cycles up by representing a position by a bit=1 and other by a bit=0. In chess we have 8*8 positions. In combination with modern cpus its most recommended to implement this in unsigned 64 bit intergers. I c++ we can use an unsigned 64 bit address int64_t and assign it with something like this: 0b00000000_00000001_00000001_00000001_00000001_00000001_00000001_00000001

My question however is, how would we do it in kotlin. Since kotlin inherits java datatypes, we cant have a unsigned 64 bit bitboard, only 63 bits, and thats not enough for chess. Eg.

val whiteInit = 0b11111111_11111111_00000000_00000000_00000000_00000000_00000000_00000000L // cant dos this (=>out of range)
val blackInit = 0b00000000_00000000_00000000_00000000_00000000_00000000_11111111_11111111L // this works

I dont wanna make things worse and split rows in different arrays, like i have read few times, because its ugly and propably not near as fast.

So, in stumbled across the ULong datatype in 'kotlin-stdlib / kotlin / Experimental', and sofar what i have written look promising. So, first of thanks for reading until here, and second of, is this the way to go or am i missing out on something better?

1

There are 1 answers

3
Alexey Romanov On

For a bitboard you care about having 64 bits, but don't care about interpretation as a number. So a Long will do just as well unless I am missing something (and so would Double if bitwise operations were defined for it). Or you could use java.util.BitSet, though it's probably going to be slower.