Skip to main content

Module magic

Module magic 

Source
Expand description

Magic bitboards for sliding piece attacks.

Replaces the ray-casting loop with a constant-time table lookup using precomputed magic multipliers.

Tables are initialized once at first use via OnceLock; masks, magic numbers, and index bits are const arrays (zero indirection).

Functionsยง

bishop_attacks
Return the attack set for a bishop on sq given the occupied board.
queen_attacks
Return the attack set for a queen (bishop + rook).
rook_attacks
Return the attack set for a rook on sq given the occupied board.