In my previous post I mentioned that we’d talk about how we store the state in Ataxx, or as I’ll call it from now on, Pookie Pookie.
Not all squares on the 7×7 game board are free, some of them can have a wall or obstacle, making that particular square permanently occupied. The walls are mirrored on all four quadants like these examples:

If we label the squares in the top-left quadrant 0-15, we can encode the walls with 16 bits, where a 0 signifies an empty square and a 1 is a square with a wall. The previous 3 examples would be encoded as 0111100010001000, 000000110100010, and 1000000100100100 respectively or 0×7888, 0×01A2, and 0×8124.

Note that bits 3, 7, 11, 12, 13, 14, and 15 are shared between two or more quadrants. Because the players always start at the corners, bit 0 can never be 1 so there really are 2^15 possible board layouts. Of those 32k board types, many will result in the players being “locked in” unable to move causing the game to automatically end since there are no more moves. It takes a minimum of 8 “on” bits to make sure that the game is over before it starts. I find that 6 “on” bits is about the most you can do and still have interesting playable boards, so really, the number of functional game boards is much smaller.
Weird Math…
If I’ve done my math right, any 6 bits out 15, 5 out of 15, 4 out of 15, 3 out of 15, 2 out of 15, 1 out of 15 and all zeros are valid boards. “X choose Y” is calculated byso the equation should be
which should equal to 9949 boards! If someone sees fault with this, please let me know
![]()
Now that we know how to encode the board type, how do we encode the board itself?
Assuming we do a two player game, each square can have one of four states: it’s free, it has a piece from player 1, it has a piece from player 2, or it has a wall. (4 player is similar, just requires a little extra work). Since we have 4 different states we can encode each cell with 2 bits, making each row 14 bits. If we squeeze this into the lower bits of a 16-bit integer, the whole board gets encoded in 14 bytes! How’s that for frugal?
We’ve accomplished a few goals by having created such a small data structure for the representation of the board. We have very little data that we have to transfer in a multiplayer game over the ‘net, and we’re minimizing the ammount of memory needed by the AI to figure out what move to make. As well see in the next post, we’ll be very glad that our board data is so small!
Also, I promise that the next one will have less math, certainly it won’t have any equations!
so the equation should be
which should equal to 9949 boards! If someone sees fault with this, please let me know