-
Notifications
You must be signed in to change notification settings - Fork 0
/
direction.h
78 lines (67 loc) · 1.39 KB
/
direction.h
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
/**
* @file direction.h
* @author DSN
* @brief Defines a \c Direction
* @version 0.1
* @date 2023-10-13
*/
#ifndef DIRECTION_H
#define DIRECTION_H
#include <string_view>
#include <vector>
#include <iostream>
/**
* @brief Defines the cardinal directions.
* @details We define four of them:
* - UP (corresponds to 'w')
* - LEFT (corresponds to 'a')
* - DOWN (corresponds to 's')
* - RIGHT (corresponds to 'd')
*/
enum class Direction
{
up,
left,
down,
right,
max_directions
};
using enum Direction;
using Cell = std::pair<int, int>;
inline const std::vector<Cell> directions{ {-1, 0}, {0, -1}, {1, 0}, {0, 1} };
/**
* @brief Get the string form of a given direction
*
* @param dir: A \c Direction value
* @return std::string_view
*/
std::string_view getName(Direction dir);
/**
* @brief Return an unsinged int form of a given direction.
*
* @param dir: A \c Direction value
* @return std::size_t
*/
std::size_t operator+(Direction dir);
/**
* @brief Return the opposite direction of a given direction.
*
* @param dir
* @return Direction
*/
Direction operator-(Direction dir);
/**
* @brief Output the string form of \c dir
*
* @param out
* @param dir
* @return std::ostream&
*/
std::ostream& operator<<(std::ostream& out, Direction dir);
/**
* @brief Randomly pick a direction
*
* @return Direction
*/
Direction getRandomDirection();
#endif