[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 bitboard;
|
||||||
mod display;
|
mod display;
|
||||||
mod r#move;
|
mod r#move;
|
||||||
mod move_generator;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
mod macros;
|
||||||
|
mod move_generator;
|
||||||
pub mod piece;
|
pub mod piece;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod position;
|
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,
|
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)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub struct Piece {
|
pub struct Piece {
|
||||||
color: Color,
|
color: Color,
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
mod diagram_formatter;
|
mod diagram_formatter;
|
||||||
mod flags;
|
mod flags;
|
||||||
mod pieces;
|
mod pieces;
|
||||||
#[macro_use]
|
|
||||||
mod position;
|
mod position;
|
||||||
|
|
||||||
pub use diagram_formatter::DiagramFormatter;
|
pub use diagram_formatter::DiagramFormatter;
|
||||||
|
|
|
@ -18,15 +18,6 @@ pub(crate) enum BoardSide {
|
||||||
Queen,
|
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)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
color_to_move: Color,
|
color_to_move: Color,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue