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
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Direction {
Up,
UpRight,
Right,
DownRight,
Down,
DownLeft,
Left,
UpLeft,
}
pub const NUM_LINES: usize = 4;
pub const ALL_LINE: [Direction; NUM_LINES] = [
Direction::Up,
Direction::Right,
Direction::Down,
Direction::Left,
];
pub const NUM_DIAGONAL: usize = 4;
pub const ALL_DIAGONAL: [Direction; NUM_DIAGONAL] = [
Direction::UpRight,
Direction::DownRight,
Direction::DownLeft,
Direction::UpLeft,
];
pub const NUM_DIRECTION: usize = NUM_LINES + NUM_DIAGONAL;
pub const ALL_DIRECTION: [Direction; NUM_DIRECTION] = [
Direction::Up,
Direction::UpRight,
Direction::Right,
Direction::DownRight,
Direction::Down,
Direction::DownLeft,
Direction::Left,
Direction::UpLeft,
];
impl Direction {
pub fn has(&self, direction: Direction) -> bool {
if *self == direction {
return true;
}
match *self {
Direction::UpRight => matches!(direction, Direction::Up | Direction::Right),
Direction::DownRight => matches!(direction, Direction::Down | Direction::Right),
Direction::DownLeft => matches!(direction, Direction::Down | Direction::Left),
Direction::UpLeft => matches!(direction, Direction::Up | Direction::Left),
_ => false,
}
}
}