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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::constants::*;
pub type Figure = usize;
pub trait FigureTrait {
fn symbol(self) -> &'static str;
}
impl FigureTrait for Figure {
fn symbol(self) -> &'static str {
FIGURE_FEN_SYMBOLS[self]
}
}
pub type Color = usize;
pub type Piece = usize;
pub fn color_figure(col: Color, fig: Figure) -> Piece {
(2 * fig) + col
}
pub trait PieceTrait {
fn color(self) -> Color;
fn figure(self) -> Figure;
fn fen_symbol(self) -> &'static str;
fn san_symbol(self) -> &'static str;
fn uci_symbol(self) -> &'static str;
fn san_letter(self) -> &'static str;
}
impl PieceTrait for Piece {
fn color(self) -> Color {
return if self & 1 == 0 { BLACK } else { WHITE };
}
fn figure(self) -> Figure {
self >> 1
}
fn fen_symbol(self) -> &'static str {
PIECE_FEN_SYMBOLS[self]
}
fn san_symbol(self) -> &'static str {
return color_figure(WHITE, self.figure()).fen_symbol();
}
fn uci_symbol(self) -> &'static str {
return self.figure().symbol();
}
fn san_letter(self) -> &'static str {
FIGURE_SAN_LETTERS[self.figure()]
}
}