I’m working on Code of Ice and Fire at the moment and I’m thinking that it would be well suited to using bitboards. I haven’t really used them before and I’m not clear on weather or not they are worth the additional code complexity.
From what I understand, instead of storing your game state info in a 2D array, you store it in a number, with each bit representing a cell in the grid. I understand that they are a great way to speed up complex queries, using bitwise operators. Update can also be made quick using bitmasks. Am I right so far?
There are two main things that aren’t quite clear to me and have been holding me back from trying to use bitboards.
Game information needs to be converted from game coordinates to bit arrays and then from bit arrays to game coordinates.
- How is that typically handled.
- Doesn’t the need to constantly convert to and from bit arrays kind of negate the potential gains from faster querying.
So let’s say I’m getting the following inputs from CG for a 12 X 12 grid:
- #: void
- .: neutral
- O: owned and active cell
- o: owned and inactive
- X: active opponent cell
- x: inactive opponent cell
So 144 positions means that I need 5 32bit ints for each data set. How does one go about taking those inputs and converting them to a bitboard representation efficiently, and then back to outputs that can be used by the rest of your code and fed to CG?