Add magic mask generation

This commit is contained in:
Bruno BELANYI 2022-07-22 10:37:56 +02:00
parent 2601abdc76
commit 1951db0720
3 changed files with 45 additions and 0 deletions

View file

@ -8,3 +8,6 @@ mod king;
mod knight;
mod pawn;
mod rook;
// Magic bitboard generation
mod wizardry;

View file

@ -0,0 +1,41 @@
use crate::board::{Bitboard, File, Rank, Square};
use crate::movegen::bishop::bishop_moves;
use crate::movegen::rook::rook_moves;
/// Compute the relevancy mask for a bishop on a given [Square].
#[allow(unused)] // FIXME: remove once used
pub fn generate_bishop_mask(square: Square) -> Bitboard {
let rays = bishop_moves(square, Bitboard::EMPTY);
let mask = File::A.into_bitboard()
| File::H.into_bitboard()
| Rank::First.into_bitboard()
| Rank::Eighth.into_bitboard();
rays - mask
}
/// Compute the relevancy mask for a rook on a given [Square].
#[allow(unused)] // FIXME: remove once used
pub fn generate_rook_mask(square: Square) -> Bitboard {
let rays = rook_moves(square, Bitboard::EMPTY);
let mask = {
let mut mask = Bitboard::EMPTY;
if square.file() != File::A {
mask = mask | File::A.into_bitboard()
};
if square.file() != File::H {
mask = mask | File::H.into_bitboard()
};
if square.rank() != Rank::First {
mask = mask | Rank::First.into_bitboard()
};
if square.rank() != Rank::Eighth {
mask = mask | Rank::Eighth.into_bitboard()
};
mask
};
rays - mask
}

View file

@ -0,0 +1 @@
mod mask;