0

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?

Plagueis
  • 173
  • 1
  • 3
  • 12

1 Answers1

0

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.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • in theory i can get behind that as long (Long :D) you have 64 bit you get it to run. With tweaks i can even imagine less. But, i ask you, how would you write it down: val whiteInit = 0b11111111_11111111_00000000_00000000_00000000_00000000_00000000_00000000L // cant dos this (=>out of range) – Plagueis Jul 03 '20 at 18:51
  • 1
    The most straightforward way I can think of is `BigInteger("1111111111111111000000000000000000000000000000000000000000000000", 2).toLong()` (import `java.math.BigInteger`). Or split into 2 parts: `(0b11111111_11111111_00000000_00000000L shl 32) + 0b00000000_00000000_00000000_00000000L`. – Alexey Romanov Jul 03 '20 at 20:36
  • That might work, but it looks totally irritating to me. I have couple hundreds bitboards. I will just stick to ULong, I dont think they will get rid of it, and they cant change much fundamentally, that it no longer works in my code. Appreciated ! – Plagueis Jul 03 '20 at 21:26