diff --git a/core/src/pieces.rs b/core/src/pieces.rs index b49db6d..148f05f 100644 --- a/core/src/pieces.rs +++ b/core/src/pieces.rs @@ -136,30 +136,34 @@ impl Piece { is_shape!(is_king, King); pub fn to_ascii(&self) -> char { - self.shape.to_ascii() + let ch = self.shape.to_ascii(); + match self.color { + Color::White => ch, + Color::Black => ch.to_ascii_lowercase(), + } + } + + fn to_unicode(&self) -> char { + match (self.color, self.shape) { + (Color::Black, Shape::Pawn) => '♟', + (Color::Black, Shape::Knight) => '♞', + (Color::Black, Shape::Bishop) => '♝', + (Color::Black, Shape::Rook) => '♜', + (Color::Black, Shape::Queen) => '♛', + (Color::Black, Shape::King) => '♚', + (Color::White, Shape::Pawn) => '♙', + (Color::White, Shape::Knight) => '♘', + (Color::White, Shape::Bishop) => '♗', + (Color::White, Shape::Rook) => '♖', + (Color::White, Shape::Queen) => '♕', + (Color::White, Shape::King) => '♔', + } } } impl fmt::Display for Piece { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{}", - match (self.color, self.shape) { - (Color::Black, Shape::Pawn) => '♟', - (Color::Black, Shape::Knight) => '♞', - (Color::Black, Shape::Bishop) => '♝', - (Color::Black, Shape::Rook) => '♜', - (Color::Black, Shape::Queen) => '♛', - (Color::Black, Shape::King) => '♚', - (Color::White, Shape::Pawn) => '♙', - (Color::White, Shape::Knight) => '♘', - (Color::White, Shape::Bishop) => '♗', - (Color::White, Shape::Rook) => '♖', - (Color::White, Shape::Queen) => '♕', - (Color::White, Shape::King) => '♔', - } - ) + write!(f, "{}", self.to_unicode()) } }