[board] Clean up interfaces of pieces and square structs
This commit is contained in:
parent
301fe1a4f4
commit
41421dddbb
5 changed files with 57 additions and 31 deletions
|
@ -111,8 +111,8 @@ pub enum PiecePlacementError {
|
|||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Piece {
|
||||
pub color: Color,
|
||||
pub shape: Shape,
|
||||
color: Color,
|
||||
shape: Shape,
|
||||
}
|
||||
|
||||
macro_rules! piece_constructor {
|
||||
|
@ -137,6 +137,14 @@ impl Piece {
|
|||
piece_constructor!(rook, Rook);
|
||||
piece_constructor!(queen, Queen);
|
||||
piece_constructor!(king, King);
|
||||
|
||||
pub fn color(&self) -> Color {
|
||||
self.color
|
||||
}
|
||||
|
||||
pub fn shape(&self) -> Shape {
|
||||
self.shape
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Piece {
|
||||
|
@ -147,14 +155,22 @@ impl fmt::Display for Piece {
|
|||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct PlacedPiece {
|
||||
pub piece: Piece,
|
||||
pub square: Square,
|
||||
piece: Piece,
|
||||
square: Square,
|
||||
}
|
||||
|
||||
impl PlacedPiece {
|
||||
pub fn new(piece: Piece, square: Square) -> PlacedPiece {
|
||||
PlacedPiece { piece, square }
|
||||
}
|
||||
|
||||
pub fn piece(&self) -> Piece {
|
||||
self.piece
|
||||
}
|
||||
|
||||
pub fn square(&self) -> Square {
|
||||
self.square
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue