1#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3pub enum Direction {
4 Up,
5 UpRight,
6 Right,
7 DownRight,
8 Down,
9 DownLeft,
10 Left,
11 UpLeft,
12}
13
14pub const NUM_LINES: usize = 4;
16
17pub const ALL_LINE: [Direction; NUM_LINES] = [
19 Direction::Up,
20 Direction::Right,
21 Direction::Down,
22 Direction::Left,
23];
24
25pub const NUM_DIAGONAL: usize = 4;
27
28pub const ALL_DIAGONAL: [Direction; NUM_DIAGONAL] = [
30 Direction::UpRight,
31 Direction::DownRight,
32 Direction::DownLeft,
33 Direction::UpLeft,
34];
35
36pub const NUM_DIRECTION: usize = NUM_LINES + NUM_DIAGONAL;
38
39pub const ALL_DIRECTION: [Direction; NUM_DIRECTION] = [
41 Direction::Up,
42 Direction::UpRight,
43 Direction::Right,
44 Direction::DownRight,
45 Direction::Down,
46 Direction::DownLeft,
47 Direction::Left,
48 Direction::UpLeft,
49];
50
51impl Direction {
52 pub fn has(&self, direction: Direction) -> bool {
67 if *self == direction {
68 return true;
69 }
70 match *self {
71 Direction::UpRight => matches!(direction, Direction::Up | Direction::Right),
72 Direction::DownRight => matches!(direction, Direction::Down | Direction::Right),
73 Direction::DownLeft => matches!(direction, Direction::Down | Direction::Left),
74 Direction::UpLeft => matches!(direction, Direction::Up | Direction::Left),
75 _ => false,
76 }
77 }
78}