Add magic mask generation
This commit is contained in:
parent
6b0563b1bd
commit
acbbfc7c8b
|
@ -8,3 +8,6 @@ mod king;
|
|||
mod knight;
|
||||
mod pawn;
|
||||
mod rook;
|
||||
|
||||
// Magic bitboard generation
|
||||
mod wizardry;
|
||||
|
|
39
src/movegen/wizardry/mask.rs
Normal file
39
src/movegen/wizardry/mask.rs
Normal 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
|
||||
}
|
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