Add magic mask generation

This commit is contained in:
Bruno BELANYI 2022-07-22 10:37:56 +02:00
parent 6b0563b1bd
commit acbbfc7c8b
3 changed files with 43 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,39 @@
use crate::board::{Bitboard, File, Rank, Square};
use crate::movegen::bishop::bishop_moves;
use crate::movegen::rook::rook_moves;
#[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
}
#[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;