-
Notifications
You must be signed in to change notification settings - Fork 0
/
Move.cpp
87 lines (72 loc) · 1.9 KB
/
Move.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
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
79
80
81
82
83
84
85
86
87
#include "Move.h"
Coords::Coords() :
row(0), column(0) {
}
Coords::Coords(coord row, coord column) :
row(row), column(column) {
}
bool Coords::operator==(const Coords& coords) const {
return row == coords.row && column == coords.column;
}
Coords Coords::operator-(const Coords& otherCoords) const {
return Coords(row - otherCoords.row, column - otherCoords.column);
}
Coords Coords::operator+(const Coords& otherCoords) const {
return Coords(row + otherCoords.row, column + otherCoords.column);
}
Coords Coords::mirror() const {
return Coords(coord(3) - row, coord(3) - column);
}
std::ostream& operator<<(std::ostream& ostream, const Coords& coords) {
ostream << '[' << ((int) coords.row) << ',' << ((int) coords.column) << ']';
return ostream;
}
std::ostream& operator<<(std::ostream& ostream, const SlideDirection& direction) {
switch (direction) {
case SD_UP:
ostream << 'U';
break;
case SD_DOWN:
ostream << 'D';
break;
case SD_LEFT:
ostream << 'L';
break;
case SD_RIGHT:
ostream << 'R';
break;
}
return ostream;
}
std::istream& operator>>(std::istream& istream, SlideDirection& direction) {
char c;
istream >> c;
switch (c) {
case 'U':
direction = SD_UP;
break;
case 'D':
direction = SD_DOWN;
break;
case 'L':
direction = SD_LEFT;
break;
case 'R':
direction = SD_RIGHT;
break;
default:
// I don't f*cking know
break;
}
return istream;
}
Move::Move() { }
Move::Move(const Coords& coords) :
coords(coords) {
}
Move::Move(coord row, coord column) :
coords(row, column) {
}
Move::Move(const SlideDirection& direction) :
direction(direction) {
}