From 868edda9d7db09e682bc135fc4c4be315b9f277b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 24 Jul 2022 16:24:35 +0200 Subject: [PATCH] Move naive move generation into sub-module --- src/movegen/mod.rs | 8 ++--- src/movegen/{ => naive}/bishop.rs | 0 src/movegen/{ => naive}/king.rs | 54 +----------------------------- src/movegen/{ => naive}/knight.rs | 0 src/movegen/naive/mod.rs | 14 ++++++++ src/movegen/{ => naive}/pawn.rs | 0 src/movegen/{ => naive}/rook.rs | 0 src/movegen/wizardry/generation.rs | 3 +- src/movegen/wizardry/mask.rs | 3 +- 9 files changed, 19 insertions(+), 63 deletions(-) rename src/movegen/{ => naive}/bishop.rs (100%) rename src/movegen/{ => naive}/king.rs (74%) rename src/movegen/{ => naive}/knight.rs (100%) create mode 100644 src/movegen/naive/mod.rs rename src/movegen/{ => naive}/pawn.rs (100%) rename src/movegen/{ => naive}/rook.rs (100%) diff --git a/src/movegen/mod.rs b/src/movegen/mod.rs index 26b60a3..9ddbf36 100644 --- a/src/movegen/mod.rs +++ b/src/movegen/mod.rs @@ -2,12 +2,8 @@ pub mod magic; pub use magic::*; -// Move generation implementation details -pub(crate) mod bishop; -pub(crate) mod king; -pub(crate) mod knight; -pub(crate) mod pawn; -pub(crate) mod rook; +// Naive move generation +pub mod naive; // Magic bitboard generation pub(crate) mod wizardry; diff --git a/src/movegen/bishop.rs b/src/movegen/naive/bishop.rs similarity index 100% rename from src/movegen/bishop.rs rename to src/movegen/naive/bishop.rs diff --git a/src/movegen/king.rs b/src/movegen/naive/king.rs similarity index 74% rename from src/movegen/king.rs rename to src/movegen/naive/king.rs index ce99b25..9080667 100644 --- a/src/movegen/king.rs +++ b/src/movegen/naive/king.rs @@ -1,4 +1,4 @@ -use crate::board::{Bitboard, CastleRights, Color, Direction, File, Square}; +use crate::board::{Bitboard, Direction, Square}; /// Compute a king's movement. No castling moves included #[allow(unused)] @@ -10,22 +10,6 @@ pub fn king_moves(square: Square) -> Bitboard { .fold(Bitboard::EMPTY, |lhs, rhs| lhs | rhs) } -/// Compute a king's castling moves, given its [Color] and [CastleRights]. -#[allow(unused)] -pub fn king_castling_moves(color: Color, castle_rights: CastleRights) -> Bitboard { - let rank = color.first_rank(); - - let king_side_square = Square::new(File::G, rank); - let queen_side_square = Square::new(File::C, rank); - - match castle_rights { - CastleRights::NoSide => Bitboard::EMPTY, - CastleRights::KingSide => king_side_square.into_bitboard(), - CastleRights::QueenSide => queen_side_square.into_bitboard(), - CastleRights::BothSides => king_side_square | queen_side_square, - } -} - #[cfg(test)] mod test { use super::*; @@ -186,40 +170,4 @@ mod test { | Square::F6 ); } - - #[test] - fn castling_moves() { - assert_eq!( - king_castling_moves(Color::White, CastleRights::NoSide), - Bitboard::EMPTY - ); - assert_eq!( - king_castling_moves(Color::Black, CastleRights::NoSide), - Bitboard::EMPTY - ); - assert_eq!( - king_castling_moves(Color::White, CastleRights::KingSide), - Square::G1.into_bitboard() - ); - assert_eq!( - king_castling_moves(Color::Black, CastleRights::KingSide), - Square::G8.into_bitboard() - ); - assert_eq!( - king_castling_moves(Color::White, CastleRights::QueenSide), - Square::C1.into_bitboard() - ); - assert_eq!( - king_castling_moves(Color::Black, CastleRights::QueenSide), - Square::C8.into_bitboard() - ); - assert_eq!( - king_castling_moves(Color::White, CastleRights::BothSides), - Square::C1 | Square::G1 - ); - assert_eq!( - king_castling_moves(Color::Black, CastleRights::BothSides), - Square::C8 | Square::G8 - ); - } } diff --git a/src/movegen/knight.rs b/src/movegen/naive/knight.rs similarity index 100% rename from src/movegen/knight.rs rename to src/movegen/naive/knight.rs diff --git a/src/movegen/naive/mod.rs b/src/movegen/naive/mod.rs new file mode 100644 index 0000000..1c64606 --- /dev/null +++ b/src/movegen/naive/mod.rs @@ -0,0 +1,14 @@ +pub mod bishop; +pub use bishop::*; + +pub mod king; +pub use king::*; + +pub mod knight; +pub use knight::*; + +pub mod pawn; +pub use pawn::*; + +pub mod rook; +pub use rook::*; diff --git a/src/movegen/pawn.rs b/src/movegen/naive/pawn.rs similarity index 100% rename from src/movegen/pawn.rs rename to src/movegen/naive/pawn.rs diff --git a/src/movegen/rook.rs b/src/movegen/naive/rook.rs similarity index 100% rename from src/movegen/rook.rs rename to src/movegen/naive/rook.rs diff --git a/src/movegen/wizardry/generation.rs b/src/movegen/wizardry/generation.rs index a5e47e2..23da62a 100644 --- a/src/movegen/wizardry/generation.rs +++ b/src/movegen/wizardry/generation.rs @@ -1,6 +1,5 @@ use crate::board::{Bitboard, Square}; -use crate::movegen::bishop::bishop_moves; -use crate::movegen::rook::rook_moves; +use crate::movegen::naive::{bishop_moves, rook_moves}; use crate::movegen::Magic; use super::mask::{generate_bishop_mask, generate_rook_mask}; diff --git a/src/movegen/wizardry/mask.rs b/src/movegen/wizardry/mask.rs index aca9f4f..5a6c56e 100644 --- a/src/movegen/wizardry/mask.rs +++ b/src/movegen/wizardry/mask.rs @@ -1,6 +1,5 @@ use crate::board::{Bitboard, File, Rank, Square}; -use crate::movegen::bishop::bishop_moves; -use crate::movegen::rook::rook_moves; +use crate::movegen::naive::{bishop::bishop_moves, rook::rook_moves}; /// Compute the relevancy mask for a bishop on a given [Square]. pub fn generate_bishop_mask(square: Square) -> Bitboard {