From 1951db07202d4102fbfc0e40a3569ba05bed06f1 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 | 41 ++++++++++++++++++++++++++++++++++++ src/movegen/wizardry/mod.rs | 1 + 3 files changed, 45 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..af1b8fa --- /dev/null +++ b/src/movegen/wizardry/mask.rs @@ -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 +} 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;