[board] Implement helpful piecewise constructors on Piece

This commit is contained in:
Eryn Wells 2023-12-26 21:31:05 -07:00
parent 371d37f688
commit 8e9da6aeff

View file

@ -101,10 +101,28 @@ pub struct Piece {
pub shape: Shape,
}
macro_rules! piece_constructor {
($func_name:ident, $type:tt) => {
pub fn $func_name(color: Color) -> Piece {
Piece {
color,
shape: Shape::$type,
}
}
};
}
impl Piece {
pub fn new(color: Color, shape: Shape) -> Piece {
Piece { color, shape }
}
piece_constructor!(pawn, Pawn);
piece_constructor!(knight, Knight);
piece_constructor!(bishop, Bishop);
piece_constructor!(rook, Rook);
piece_constructor!(queen, Queen);
piece_constructor!(king, King);
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]