[board] Implement helpful piecewise constructors on Piece
This commit is contained in:
parent
371d37f688
commit
8e9da6aeff
1 changed files with 18 additions and 0 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue