chess:programming:magic_bitboards:calculate_magic_numbers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
chess:programming:magic_bitboards:calculate_magic_numbers [2021/10/27 23:10] – [Determine Magic Numbers] peter | chess:programming:magic_bitboards:calculate_magic_numbers [2021/10/28 00:00] (current) – [Determine Magic Numbers] peter | ||
---|---|---|---|
Line 95: | Line 95: | ||
<WRAP info> | <WRAP info> | ||
**NOTE: | **NOTE: | ||
+ | |||
+ | * **magic** is the random 64-bit number. | ||
+ | * At this time this is done by trial-and-error, | ||
+ | * It is just luck/ | ||
+ | * Ideally no gaps should be between each index, i.e. a perfect hash. | ||
* This should result in 64 magic rook numbers and 64 magic bishop numbers. | * This should result in 64 magic rook numbers and 64 magic bishop numbers. | ||
+ | * The index returned by the magic formula is always an integer less than the total number of BlockerBoards. | ||
+ | |||
+ | * These indexes will be used to determine where to store each BlockerBoards corresponding MoveBoard within an array. | ||
+ | * The MoveBoard are just stored at the index calculated by these pre-programmed good magics. | ||
+ | |||
+ | * While this example of the Rook at e4 has 1024 BlockerBoards, | ||
+ | * For two different BlockerBoards that have the same MoveBoard, the magic could calculate two different indices or it could calculate the same index for both. | ||
+ | * As long as the MoveBoards are the same, it is okay for the index to collide. | ||
</ | </ | ||
Line 103: | Line 116: | ||
**WARNING: | **WARNING: | ||
- | * For a certain Piece/ | + | * For a certain Piece/ |
</ | </ | ||
Line 113: | Line 126: | ||
All of the Blocker Masks, Blocker Boards, and Move Boards should be initialized. | All of the Blocker Masks, Blocker Boards, and Move Boards should be initialized. | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * Each BB has a corresponding MoveBoard (MB). | ||
+ | * When searching for magics, each MB is being calculated | ||
+ | * At engine startup, the MBs are recalculated with the slow algorithm and then they are just stored at the index calculated by your pre-programmed good magics. | ||
+ | |||
+ | </ | ||
---- | ---- | ||
Line 124: | Line 146: | ||
<code cpp> | <code cpp> | ||
// Retrieves the Move Board for the given square and occupancy board. | // Retrieves the Move Board for the given square and occupancy board. | ||
- | uint64_t magic_move_rook | + | uint64_t magic_move_rook(int8_t square, uint64_t occupancy) |
{ | { | ||
// Remove occupants that are not in the Blocker Mask for this square. | // Remove occupants that are not in the Blocker Mask for this square. | ||
Line 136: | Line 158: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * **index** points to the right spot in the moveboard array. | ||
+ | |||
+ | </ | ||
---- | ---- | ||
chess/programming/magic_bitboards/calculate_magic_numbers.1635376204.txt.gz · Last modified: 2021/10/27 23:10 by peter