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
use std::ops::Not;
use rank::Rank;
#[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) -> Rank {
match *self {
Color::White => Rank::First,
Color::Black => Rank::Eighth
}
}
pub fn to_their_backrank(&self) -> Rank {
match *self {
Color::White => Rank::Eighth,
Color::Black => Rank::First
}
}
pub fn to_second_rank(&self) -> Rank {
match *self {
Color::White => Rank::Second,
Color::Black => Rank::Seventh
}
}
pub fn to_seventh_rank(&self) -> Rank {
match *self {
Color::White => Rank::Seventh,
Color::Black => Rank::Second
}
}
}
impl Not for Color {
type Output = Color;
fn not(self) -> Color {
if self == Color::White {
Color::Black
} else {
Color::White
}
}
}