0

so for university I programm the game "Pentago" in Java. Everything is fine but I stuck at a point.

Because of the AI I need to build huge Trees using alpha beta prunning. Storing the board as a 2d array or something is just to big.

So we need to save the board (6x6) as a BigInteger. I thought about transform the board into a BitSet and then save it as BigInt.

Before I just simply created a 36 characters long String with 0 for empty cell, 1 for players cell and 2 for enemies cell and it loked like this "012010012002001020102000100020102012".. Then I just used the BigInteger Constructor to create a BigInteger from this String. But I think its not the way its ment to be. Now I want to create a BitSet and use 2 Bits for every cell. like "00" - empty "01" player "10" enemy.

Can someone help me out here? I read the Documentation of BitSet and tried to use just the BitSet.set(index) method but I get weirdly negativ bigInteger values and the .toString(2) method shows something totaly diffrent I wanted to build.

Thank you guys, If I need to give you more informations or wrote anything stupid I will edit it, just let me know.

edit: or is there a better way to create a 72 bit long data, set the bits to 1 and 0 as I need and pass it into a biginteger?

Danny Bergs
  • 91
  • 1
  • 2
  • 8
  • So board is 6x6 = 36, then multiply it with 2 - it is 72 bits. What do you mean by "weirdly negative"? – Michał Krzywański Jul 31 '19 at 17:31
  • Have a look at [this](https://stackoverflow.com/questions/29526985/java-from-biginteger-to-bitset-and-back) – Michał Krzywański Jul 31 '19 at 17:46
  • Yeah I just created an index and iterated over my board and just used bittSet.set(index) to set the bits I need to 1. But for example I get something like that "-1010011010101010101010101010101010101010101010101010101010101010101010111111111" when I try to transform the board 200000000000000000000000000000000001 and the BigInteger I create with new BigInteger(bitSet.toBitArray()) looks like -393530540239137101141503 – Danny Bergs Jul 31 '19 at 17:46

0 Answers0