chessfriend/board/src/macros.rs

74 lines
2.2 KiB
Rust
Raw Normal View History

// Eryn Wells <eryn@erynwells.me>
#[macro_export]
macro_rules! test_board {
($to_move:ident, [ $($color:ident $shape:ident on $square:ident),* $(,)? ], $en_passant:ident) => {
{
2025-05-03 16:02:56 -07:00
let mut board = $crate::Board::empty();
2025-05-08 17:37:51 -07:00
$(let _ = board.place_piece(
2025-05-03 16:02:56 -07:00
chessfriend_core::Piece::new(
chessfriend_core::Color::$color,
chessfriend_core::Shape::$shape
),
2025-05-08 17:37:51 -07:00
chessfriend_core::Square::$square,
$crate::PlacePieceStrategy::default());
2025-05-03 16:02:56 -07:00
)*
board.set_active_color(chessfriend_core::Color::$to_move);
2025-05-03 16:02:56 -07:00
board.en_passant_target = Some(chessfriend_core::Square::$en_passant);
println!("{}", board.display());
board
}
};
($to_move:ident, [ $($color:ident $shape:ident on $square:ident),* $(,)? ]) => {
{
2025-05-03 16:02:56 -07:00
let mut board = $crate::Board::empty();
2025-05-08 17:37:51 -07:00
$(let _ = board.place_piece(
2025-05-03 16:02:56 -07:00
chessfriend_core::Piece::new(
chessfriend_core::Color::$color,
chessfriend_core::Shape::$shape
),
chessfriend_core::Square::$square,
$crate::PlacePieceStrategy::default());
)*
2025-05-08 17:37:51 -07:00
board.active_color = chessfriend_core::Color::$to_move;
println!("{}", board.display());
2025-05-03 16:02:56 -07:00
board
}
};
($($color:ident $shape:ident on $square:ident),* $(,)?) => {
{
2025-05-03 16:02:56 -07:00
let mut board = $crate::Board::empty();
2025-05-08 17:37:51 -07:00
$(let _ = board.place_piece(
2025-05-03 16:02:56 -07:00
chessfriend_core::Piece::new(
chessfriend_core::Color::$color,
chessfriend_core::Shape::$shape
),
chessfriend_core::Square::$square,
$crate::PlacePieceStrategy::default());
)*
println!("{}", board.display());
board
}
};
(empty) => {
{
let board = Board::empty();
println!("{}", board.display());
board
}
};
(starting) => {
{
let board = Board::starting();
println!("{}", board.display());
board
}
};
}