use std::fmt;
use super::Color;
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Debug)]
pub enum Piece {
Pawn,
Knight,
Bishop,
Rook,
Queen,
King,
}
pub const NUM_PIECES: usize = 6;
pub const ALL_PIECES: [Piece; NUM_PIECES] = [
Piece::Pawn,
Piece::Knight,
Piece::Bishop,
Piece::Rook,
Piece::Queen,
Piece::King,
];
impl Piece {
#[inline]
pub fn to_index(&self) -> usize {
*self as usize
}
#[inline]
pub fn to_string(&self, color: Color) -> String {
let piece = format!("{}", self);
match color {
Color::White => piece.to_uppercase(),
Color::Black => piece,
}
}
}
impl fmt::Display for Piece {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Piece::Pawn => "p",
Piece::Knight => "n",
Piece::Bishop => "b",
Piece::Rook => "r",
Piece::Queen => "q",
Piece::King => "k",
}
)
}
}