-1

I recently started working on my school project which is writing a chinese chess game with a computer player in Java, I want to represent the board with bitboards, however since the board is 9x10, bigint or double aren't large enough to represent it. I though about using the BigInteger class from java.math, however I'm afraid it isn't efficient and therefore I will run into problems whnen writing the code for the computer player.... Does anyone know how efficient the BigInteger class is? Will I run into problems with it when trying to calculate the best computer moves? Thanks.

  • Maybe give BitSet class a try? – Hitobat Nov 27 '21 at 08:40
  • 1
    I mean utility class. See JavaDoc here: https://docs.oracle.com/javase/8/docs/api/java/util/BitSet.html Also see basic intro guide; https://www.baeldung.com/java-bitset – Hitobat Nov 27 '21 at 08:50

1 Answers1

1

Either the Java SE BitSet or BigInteger classes could be used to represent a bitboard. And I nooticed that there are alternatives to the standard Java SE implementations1.

But the real question is whether you could come up with an alternative implementation of the bitboard abstraction that is more efficient than those general purpose data structures.

For example, if your bitboard requires 80 bits, then you could represent it as a long array of length 2 or an int array of length 3. This should be at least as fast as the better of BitSet or BigInteger, because those Java SEclasses both use arrays of integers under the hood.

1 - A Google search is advised ...


My advice: pick whatever representation is easiest to use. Get interesting part of your game implementation working first. Then test it to see how fast it is. If it is not fast enough ... put some effort into profiling and optimizing it; e.g. by tuning the bitboard implementation. Don't optimize too early.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216