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
72
73
74
75
76
77
78
79
80
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Error;
use crate::pieces::util::coord::Coord;
pub const WHITE_STONE: char = '⚫';
pub const BLACK_STONE: char = '⚪';
pub const EMPTY_STONE: char = '.';
#[derive(Eq, PartialEq, Hash, Clone, Copy, Debug)]
pub enum Color {
White = 2,
Black = 1,
None = 0,
}
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub struct Stone {
pub coord: Coord,
pub color: Color,
}
impl From<u8> for Color {
fn from(x: u8) -> Self {
match x {
2 => Color::White,
1 => Color::Black,
0 => Color::None,
_ => panic!("Error int the conversion from u8 to Stone")
}
}
}
impl Into<u8> for Color {
fn into(self) -> u8 {
match self {
Color::Black => 1,
Color::None => 0,
Color::White => 2,
}
}
}
impl From<bool> for Color {
fn from(x: bool) -> Self {
match x {
true => Color::White,
false => Color::Black,
}
}
}
impl Into<bool> for Color {
fn into(self) -> bool {
match self {
Color::White => true,
Color::Black => false,
Color::None => panic!("Tried to convert Empty to a turn")
}
}
}
impl Display for Color {
fn fmt(&self, f: &mut Formatter<>) -> Result<(), Error> {
let color_str = match self {
Color::White => "White",
Color::Black => "Black",
Color::None => "Empty"
};
write!(f, "{}", color_str)
}
}