-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction.cpp
51 lines (46 loc) · 842 Bytes
/
direction.cpp
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
#include "direction.h"
#include "random.h"
std::string_view getName(Direction dir)
{
switch (dir)
{
case up:
return "up";
case down:
return "down";
case left:
return "left";
case right:
return "right";
default:
return "???";
}
}
std::size_t operator+(Direction dir)
{
return static_cast<std::size_t>(dir);
}
Direction operator-(Direction dir)
{
switch (dir)
{
case up:
return down;
case down:
return up;
case left:
return right;
case right:
return left;
default:
return dir;
}
}
std::ostream& operator<<(std::ostream& out, Direction dir)
{
return out << getName(dir);
}
Direction getRandomDirection()
{
return static_cast<Direction>(Random::get(0, +max_directions - 1));
}