1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::fmt;
#[derive(PartialEq, Eq, Ord, PartialOrd, Copy, Clone)]
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];
pub const NUM_PROMOTION_PIECES: usize = 4;
pub const PROMOTION_PIECES: [Piece; 4] = [ Piece::Queen, Piece::Knight, Piece::Rook, Piece::Bishop ];
impl Piece {
pub fn to_index(&self) -> usize {
*self as usize
}
}
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"
})
}
}