diff --git a/board/src/piece.rs b/board/src/piece.rs index 4997050..359234d 100644 --- a/board/src/piece.rs +++ b/board/src/piece.rs @@ -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)]