Move naive move generation into sub-module
This commit is contained in:
parent
23d01d4d3f
commit
868edda9d7
|
@ -2,12 +2,8 @@
|
||||||
pub mod magic;
|
pub mod magic;
|
||||||
pub use magic::*;
|
pub use magic::*;
|
||||||
|
|
||||||
// Move generation implementation details
|
// Naive move generation
|
||||||
pub(crate) mod bishop;
|
pub mod naive;
|
||||||
pub(crate) mod king;
|
|
||||||
pub(crate) mod knight;
|
|
||||||
pub(crate) mod pawn;
|
|
||||||
pub(crate) mod rook;
|
|
||||||
|
|
||||||
// Magic bitboard generation
|
// Magic bitboard generation
|
||||||
pub(crate) mod wizardry;
|
pub(crate) mod wizardry;
|
||||||
|
|
|
@ -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
|
/// Compute a king's movement. No castling moves included
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
@ -10,22 +10,6 @@ pub fn king_moves(square: Square) -> Bitboard {
|
||||||
.fold(Bitboard::EMPTY, |lhs, rhs| lhs | rhs)
|
.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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -186,40 +170,4 @@ mod test {
|
||||||
| Square::F6
|
| 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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
14
src/movegen/naive/mod.rs
Normal file
14
src/movegen/naive/mod.rs
Normal file
|
@ -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::*;
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::board::{Bitboard, Square};
|
use crate::board::{Bitboard, Square};
|
||||||
use crate::movegen::bishop::bishop_moves;
|
use crate::movegen::naive::{bishop_moves, rook_moves};
|
||||||
use crate::movegen::rook::rook_moves;
|
|
||||||
use crate::movegen::Magic;
|
use crate::movegen::Magic;
|
||||||
|
|
||||||
use super::mask::{generate_bishop_mask, generate_rook_mask};
|
use super::mask::{generate_bishop_mask, generate_rook_mask};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::board::{Bitboard, File, Rank, Square};
|
use crate::board::{Bitboard, File, Rank, Square};
|
||||||
use crate::movegen::bishop::bishop_moves;
|
use crate::movegen::naive::{bishop::bishop_moves, rook::rook_moves};
|
||||||
use crate::movegen::rook::rook_moves;
|
|
||||||
|
|
||||||
/// Compute the relevancy mask for a bishop on a given [Square].
|
/// Compute the relevancy mask for a bishop on a given [Square].
|
||||||
pub fn generate_bishop_mask(square: Square) -> Bitboard {
|
pub fn generate_bishop_mask(square: Square) -> Bitboard {
|
||||||
|
|
Loading…
Reference in a new issue