It's getting close to Christmas which is the time of year that I normally dust off Monarch and give it a polish.
Monarch is currently uses a postbox system to represent the board. However, it would seem that magic bitboards are interesting and with the ubiquity of 64 bit machines I think bitboards certainly make sense (and more importantly will be fun to program). So a couple of questions before I start:
1. What's the "best practice" data structure for magic bitboards? Is it a 2D array [Color][Piece_Type]? e.g. [white][Bishops]?
2. Do most people maintain other bitboards e.g. AllPieces, AllWhitePieces and AllBlackPieces?
3.*Really Basic Question* suppose I calculate an attack array for a queen, how do I generate the captures (I'm guessing that I'll use AllOpponentsPiece bitboard), but how do I know what sort of piece is being captured? Iterating through the bitboards seems somewhat expensive (but this may be an illusion).
4.Do most engines also maintain a postbox structure as well?
Thanks,
Steve
Starting to convert to Magic Bitboard - A Few Questions...
Moderator: Ras
-
- Posts: 1297
- Joined: Wed Mar 08, 2006 8:28 pm
- Location: Florida, USA
-
- Posts: 2251
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: Starting to convert to Magic Bitboard - A Few Questions.
Color don't cares since black or white bishops/rooks attack same squares, if from square and relevant occupancy are equal. Since Magic BB have separate tables for every square, it makes sense to have one huge array for the pre-calculated attack BBs, and an array[64] of structs (or struct of arrays) for rook and bishops each, containing pre-mask of the relevant occupancy, magic factor, shift, and a pointer to attack array, see f.i. Sample Code.Steve Maughan wrote:It's getting close to Christmas which is the time of year that I normally dust off Monarch and give it a polish.
Monarch is currently uses a postbox system to represent the board. However, it would seem that magic bitboards are interesting and with the ubiquity of 64 bit machines I think bitboards certainly make sense (and more importantly will be fun to program). So a couple of questions before I start:
1. What's the "best practice" data structure for magic bitboards? Is it a 2D array [Color][Piece_Type]? e.g. [white][Bishops]?
If you refer to the pure board representation, which is not exactly related to Magic BBs, I guess most often an one-dimensional array is used indexed by colored pieces in any arbitrary order.
Makes sense since they are used often, but I would like to index the piece BBs by color, i.e . AllPieces[2].Steve Maughan wrote: 2. Do most people maintain other bitboards e.g. AllPieces, AllWhitePieces and AllBlackPieces?
One bitscan-loop is common with lookup the postbox[to] to score captures by MVV. In my staged movegen I use disjoint target-sets. Captured piece is member of the move-structure.Steve Maughan wrote: 3.*Really Basic Question* suppose I calculate an attack array for a queen, how do I generate the captures (I'm guessing that I'll use AllOpponentsPiece bitboard), but how do I know what sort of piece is being captured? Iterating through the bitboards seems somewhat expensive (but this may be an illusion).
Most do, I do not.Steve Maughan wrote: 4.Do most engines also maintain a postbox structure as well?
Steve Maughan wrote:
Thanks,
Steve
-
- Posts: 1297
- Joined: Wed Mar 08, 2006 8:28 pm
- Location: Florida, USA
Re: Starting to convert to Magic Bitboard - A Few Questions.
Gerd,
Many thanks. I've got to sit down and figure out how exactly I'm going to do this and make sure I understand the magic.
Thx,
Steve
Many thanks. I've got to sit down and figure out how exactly I'm going to do this and make sure I understand the magic.
Thx,
Steve
-
- Posts: 928
- Joined: Sun Nov 19, 2006 9:16 pm
- Location: Russia
- Full name: Aleks Peshkov
Re: Starting to convert to Magic Bitboard - A Few Questions.
"Magic Bitboards" is the only one of many methods to generate a bitboard of attacks of sliding pieces. It is light in processor instructions on x86 platform in 64-bit mode for the cost of large array (>800Kb) of precalculated tables and an array of ugly magic numbers inside program source.