[board] Add a piece! macro
This macro implements a tiny DSL for creating Pieces and PlacedPieces. "White King" → Piece::new(Color::White, Shape::King) "White King on E4" → PlacedPiece::new(Piece::new(Color::White, Shape::King), Square::E4)
This commit is contained in:
parent
d2ee9244c2
commit
94ab64d277
2 changed files with 11 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
mod bitboard;
|
||||
mod moves;
|
||||
#[macro_use]
|
||||
pub mod piece;
|
||||
pub mod position;
|
||||
mod square;
|
||||
|
|
|
@ -118,6 +118,16 @@ pub enum PiecePlacementError {
|
|||
ExistsOnSquare,
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! piece {
|
||||
($color:ident $shape:ident) => {
|
||||
Piece::new(Color::$color, Shape::$shape)
|
||||
};
|
||||
($color:ident $shape:ident on $square:ident) => {
|
||||
PlacedPiece::new(piece!($color $shape), Square::$square)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Piece {
|
||||
color: Color,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue