[board] Move piece! and position! macros to a new macros.rs module
This commit is contained in:
parent
e56b3259e2
commit
2269df2ed9
5 changed files with 22 additions and 21 deletions
|
@ -4,8 +4,9 @@
|
|||
mod bitboard;
|
||||
mod display;
|
||||
mod r#move;
|
||||
mod move_generator;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod move_generator;
|
||||
pub mod piece;
|
||||
#[macro_use]
|
||||
pub mod position;
|
||||
|
|
20
board/src/macros.rs
Normal file
20
board/src/macros.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! piece {
|
||||
($color:ident $shape:ident) => {
|
||||
$crate::piece::Piece::new($crate::piece::Color::$color, $crate::piece::Shape::$shape)
|
||||
};
|
||||
($color:ident $shape:ident on $square:ident) => {
|
||||
$crate::piece::PlacedPiece::new(piece!($color $shape), $crate::square::Square::$square)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! position {
|
||||
[$($color:ident $shape:ident on $square:ident),* $(,)?] => {
|
||||
$crate::PositionBuilder::new()
|
||||
$(.place_piece(piece!($color $shape on $square)))*
|
||||
.build()
|
||||
};
|
||||
}
|
|
@ -121,16 +121,6 @@ pub enum PiecePlacementError {
|
|||
ExistsOnSquare,
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! piece {
|
||||
($color:ident $shape:ident) => {
|
||||
$crate::piece::Piece::new($crate::piece::Color::$color, $crate::piece::Shape::$shape)
|
||||
};
|
||||
($color:ident $shape:ident on $square:ident) => {
|
||||
$crate::piece::PlacedPiece::new(piece!($color $shape), $crate::square::Square::$square)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Piece {
|
||||
color: Color,
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
mod diagram_formatter;
|
||||
mod flags;
|
||||
mod pieces;
|
||||
#[macro_use]
|
||||
mod position;
|
||||
|
||||
pub use diagram_formatter::DiagramFormatter;
|
||||
|
|
|
@ -18,15 +18,6 @@ pub(crate) enum BoardSide {
|
|||
Queen,
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! position {
|
||||
[$($color:ident $shape:ident on $square:ident,)*] => {
|
||||
$crate::Position::from_iter([
|
||||
$($crate::piece!($color $shape on $square)),*
|
||||
].into_iter())
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct Position {
|
||||
color_to_move: Color,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue