Bitboard Tricks for Large Chess Variants
Posted: Sat Nov 01, 2014 3:20 am
After seeing how my old code for a 10x8 variant is doing against some new players in the field, I think it is time for a complete rewrite.
Gothic Vortex (white) lost to Bihasa (black) from this position, which is well on the path to its demise already.
Vortex is a 10x8 port of much older Crafty code, going back to the days of its 45 degree rotated bitboards for Bishop sliding moves. Then I started thinking about my own 64-bit move generator for the game of checkers, which is set up like this:
Those who are familiar with checkers may wonder what good are 64-bits on a game that uses only 32 squares? The answer is: you get a much simpler move generator using 64-bits on the squares show.
Every checker move to the top-right is a shift of 9 bits. Every such shift always results in a legal destination. If there is not bit specified, such as 44 + 9 = 53, then that is "off the board." Likewise, moves to the top-left are upward shifts of 1-bit. If you numbered the squares 1-32 instead, you have to check odd/even ranks, and do different bit masks depending on where you are. It adds branch points to the code, as well as some complexity. I believe my entire move generator was something like 39 lines of code.
Anyway, I was wondering if those of you with 10x8 variant move generators have any pseudo-magic squares for use with your bitboards, so you don't have to resort to rotated bitboards or other contortionist moves? I was just playing around with a Knight Bitboard for 10x8:
This is a 107-bit ugly looking thing, but with operator overloading (making things like >> work seamlessly) your code could look very clean.
Every knight hop up-2-and-over-1 is an upward shift of 13 bits. Likewise, where there is no number specified, the bit falls off of the destination bitboard via a simple stamping mask.
Other offset moves of the Knight are shown.
Do any of you bother to do something like this for larger boards? Or is it a waste of time, and you just use Mailbox offsets in arrays?
Gothic Vortex (white) lost to Bihasa (black) from this position, which is well on the path to its demise already.
Vortex is a 10x8 port of much older Crafty code, going back to the days of its 45 degree rotated bitboards for Bishop sliding moves. Then I started thinking about my own 64-bit move generator for the game of checkers, which is set up like this:
Those who are familiar with checkers may wonder what good are 64-bits on a game that uses only 32 squares? The answer is: you get a much simpler move generator using 64-bits on the squares show.
Every checker move to the top-right is a shift of 9 bits. Every such shift always results in a legal destination. If there is not bit specified, such as 44 + 9 = 53, then that is "off the board." Likewise, moves to the top-left are upward shifts of 1-bit. If you numbered the squares 1-32 instead, you have to check odd/even ranks, and do different bit masks depending on where you are. It adds branch points to the code, as well as some complexity. I believe my entire move generator was something like 39 lines of code.
Anyway, I was wondering if those of you with 10x8 variant move generators have any pseudo-magic squares for use with your bitboards, so you don't have to resort to rotated bitboards or other contortionist moves? I was just playing around with a Knight Bitboard for 10x8:
This is a 107-bit ugly looking thing, but with operator overloading (making things like >> work seamlessly) your code could look very clean.
Every knight hop up-2-and-over-1 is an upward shift of 13 bits. Likewise, where there is no number specified, the bit falls off of the destination bitboard via a simple stamping mask.
Other offset moves of the Knight are shown.
Do any of you bother to do something like this for larger boards? Or is it a waste of time, and you just use Mailbox offsets in arrays?