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
use std::ops::Not;
#[derive(PartialOrd, PartialEq, Copy, Clone)]
pub enum Color {
White,
Black
}
pub const NUM_COLORS: usize = 2;
pub const ALL_COLORS: [Color; NUM_COLORS] = [Color::White, Color::Black];
impl Color {
pub fn to_index(&self) -> usize {
*self as usize
}
pub fn to_my_backrank(&self) -> u8 {
(self.to_index() * 7) as u8
}
pub fn to_their_backrank(&self) -> u8 {
((1 - self.to_index()) * 7) as u8
}
pub fn to_second_rank(&self) -> u8 {
(self.to_index() * 5 + 1) as u8
}
}
impl Not for Color {
type Output = Color;
fn not(self) -> Color {
if self == Color::White {
Color::Black
} else {
Color::White
}
}
}