[position] Implement all the example positions from Peter Ellis Jones' blog post

https://peterellisjones.com/posts/generating-legal-chess-moves-efficiently/
This commit is contained in:
Eryn Wells 2024-02-03 15:16:00 -08:00
parent 6c14851806
commit f4e57d7d6c
5 changed files with 282 additions and 3 deletions

View file

@ -16,10 +16,48 @@ macro_rules! position {
};
}
#[cfg(test)]
#[macro_export]
macro_rules! test_position {
[$($color:ident $shape:ident on $square:ident),* $(,)?] => {
($to_move:ident, [ $($color:ident $shape:ident on $square:ident),* $(,)? ], $en_passant:ident) => {
{
let pos = $crate::PositionBuilder::new()
$(.place_piece(
chessfriend_core::PlacedPiece::new(
chessfriend_core::Piece::new(
chessfriend_core::Color::$color,
chessfriend_core::Shape::$shape
),
chessfriend_core::Square::$square
))
)*
.to_move(chessfriend_core::Color::$to_move)
.en_passant_square(Some(chessfriend_core::Square::$en_passant))
.build();
println!("{pos}");
pos
}
};
($to_move:ident, [ $($color:ident $shape:ident on $square:ident),* $(,)? ]) => {
{
let pos = $crate::PositionBuilder::new()
$(.place_piece(
chessfriend_core::PlacedPiece::new(
chessfriend_core::Piece::new(
chessfriend_core::Color::$color,
chessfriend_core::Shape::$shape
),
chessfriend_core::Square::$square
))
)*
.to_move(chessfriend_core::Color::$to_move)
.build();
println!("{pos}");
pos
}
};
($($color:ident $shape:ident on $square:ident),* $(,)?) => {
{
let pos = $crate::PositionBuilder::new()
$(.place_piece(