[core] Move the Unicode piece table to a helper to_unicode() method on Piece
This commit is contained in:
parent
742b00119a
commit
0201668563
1 changed files with 23 additions and 19 deletions
|
@ -136,30 +136,34 @@ impl Piece {
|
||||||
is_shape!(is_king, King);
|
is_shape!(is_king, King);
|
||||||
|
|
||||||
pub fn to_ascii(&self) -> char {
|
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 {
|
impl fmt::Display for Piece {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(f, "{}", self.to_unicode())
|
||||||
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) => '♔',
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue