Search code examples
algorithmbitboard

Bitboard algorithms for board sizes greater than 64?


I know the Magic BitBoard technique is useful for modern games that are on a n 8x8 grid because you it aligns perfectly with a single 64-bit integer, but is the idea extensible to board sizes greater than 64 squares?

Some games like Shogi have larger board sizes such as 81 squares, which doesn't cleanly fit into a 64-bit integer.

I assume you'd have to use multiple integers but would it would it be better to use 2 64-bit integers or something like 3 32-bit ones?

I know there probably isn't a trivial answer to this, but what kind of knowledge would I need in order to research something like this? I only have some basic/intermediate algorithms and data structures knowledge.


Solution

  • Yes, you could do this with a structure that contains multiple integers of varying lengths. For example, you could use 11 unsigned bytes. Or a 64-bit integer and a 32-bit integer, etc. Anything that will add up to 81 or more bits.

    I rather like the idea of three 32-bit integers because you can store three rows per integer. It makes your indexing code simpler than if you used a 64-bit integer and a 32-bit integer. 9 16-bit words would work well, too, but you're wasting almost half your bits.

    You could use 11 unsigned bytes, but the indexing is kind of ugly.

    All things considered, I'd probably go with the 3 32-bit integers, using the low 27 bits of each.