-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition.cpp
50 lines (40 loc) · 1001 Bytes
/
position.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
#include <cmath>
#include "position.hpp"
namespace cprogame{
/**
* Default constructor, initialized to (0,0)
*/
Position::Position():x(0),y(0){}
/**
* Constructor that initilize position to (x, y)
*/
Position::Position(const unsigned & _x, const unsigned & _y):x(_x),y(_y){}
/**
* Resets position to the specified values
*/
void Position::set_pos(const unsigned & _x, const unsigned & _y){
x = _x;
y = _y;
}
/**
* Returns the manhattan distance between two positions.
*/
unsigned int Position::operator-(const Position & other){
return std::abs(x-other.x)+std::abs(y-other.y);
}
/**
* Returns a modifier to the specified position parameter.
*/
unsigned int & Position::operator()(const POS_DIM & pd){
return pd?y:x;
}
/**
* Accessor to the specified position parameter.
*/
const unsigned int & Position::operator()(const POS_DIM & pd) const{
return pd?y:x;
}
bool Position::operator==(const Position & other){
return x == other.x && y == other.y;
}
} //namespace cprogame