Add magic mask generation
This commit is contained in:
parent
2601abdc76
commit
1951db0720
|
@ -8,3 +8,6 @@ mod king;
|
||||||
mod knight;
|
mod knight;
|
||||||
mod pawn;
|
mod pawn;
|
||||||
mod rook;
|
mod rook;
|
||||||
|
|
||||||
|
// Magic bitboard generation
|
||||||
|
mod wizardry;
|
||||||
|
|
41
src/movegen/wizardry/mask.rs
Normal file
41
src/movegen/wizardry/mask.rs
Normal 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
|
||||||
|
}
|
1
src/movegen/wizardry/mod.rs
Normal file
1
src/movegen/wizardry/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
mod mask;
|
Loading…
Reference in a new issue