-
Notifications
You must be signed in to change notification settings - Fork 0
/
coord.h
60 lines (53 loc) · 1.06 KB
/
coord.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
#pragma once
#include <map>
#include <list>
#include <queue>
#include <memory>
#include <random>
#include <ncurses.h>
#include <algorithm>
enum Direction {NONE, RIGHT, UPRIGHT, UP, UPLEFT, LEFT, DOWNLEFT, DOWN, DOWNRIGHT};
struct coord {
int row;
int col;
// convenient way to get the coordinates from a relative direction
coord to_the(Direction dir) {
int r = row;
int c = col;
switch (dir) {
case RIGHT:
c++;
break;
case UPRIGHT:
c++; r--;
break;
case UP:
r--;
break;
case UPLEFT:
c--; r--;
break;
case LEFT:
c--;
break;
case DOWNLEFT:
r++; c--;
break;
case DOWN:
r++;
break;
case DOWNRIGHT:
c++; r++;
break;
default: break;
}
return {r, c};
}
};
// lexicographical ordering
inline bool operator< (const coord& lhs, const coord& rhs) {
if (lhs.row == rhs.row)
return lhs.col < rhs.col;
else
return lhs.row < rhs.row;
}