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
use std::fmt::{Formatter, Display, Error};
#[derive(Debug, PartialEq, Clone)]
pub enum Tile {
BLACK,
WHITE,
FREE,
}
impl Default for Tile {
fn default() -> Self {
Tile::FREE
}
}
impl Tile {
#[allow(dead_code)]
pub fn from_str(s: &str) -> Tile {
match s {
"B" | "b" => Tile::BLACK,
"W" | "w" => Tile::WHITE,
_ => Tile::FREE,
}
}
pub fn is_pawn(&self) -> bool {
*self == Tile::BLACK || *self == Tile::WHITE
}
pub fn ennemy(&self) -> Tile {
match *self {
Tile::BLACK => Tile::WHITE,
Tile::WHITE => Tile::BLACK,
_ => self.clone(),
}
}
}
impl Display for Tile {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self {
&Tile::BLACK => {
let _ = write!(f, "B");
}
&Tile::WHITE => {
let _ = write!(f, "W");
}
&Tile::FREE => {
let _ = write!(f, ".");
}
};
Ok(())
}
}
impl Copy for Tile {}