From acbbfc7c8bc90db6217466c82e1c871b5306ca01 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 22 Jul 2022 10:37:56 +0200 Subject: [PATCH] Add magic mask generation --- src/movegen/mod.rs | 3 +++ src/movegen/wizardry/mask.rs | 39 ++++++++++++++++++++++++++++++++++++ src/movegen/wizardry/mod.rs | 1 + 3 files changed, 43 insertions(+) create mode 100644 src/movegen/wizardry/mask.rs create mode 100644 src/movegen/wizardry/mod.rs diff --git a/src/movegen/mod.rs b/src/movegen/mod.rs index d379194..3d22eb0 100644 --- a/src/movegen/mod.rs +++ b/src/movegen/mod.rs @@ -8,3 +8,6 @@ mod king; mod knight; mod pawn; mod rook; + +// Magic bitboard generation +mod wizardry; diff --git a/src/movegen/wizardry/mask.rs b/src/movegen/wizardry/mask.rs new file mode 100644 index 0000000..13d7cd6 --- /dev/null +++ b/src/movegen/wizardry/mask.rs @@ -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 +} diff --git a/src/movegen/wizardry/mod.rs b/src/movegen/wizardry/mod.rs new file mode 100644 index 0000000..f6053c6 --- /dev/null +++ b/src/movegen/wizardry/mod.rs @@ -0,0 +1 @@ +mod mask;