forked from rdbrck/battlesnake-2017-aleksiys-snake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
point.h
84 lines (71 loc) · 1.22 KB
/
point.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
79
80
81
82
83
#include <string>
#include <iostream>
#include <vector>
#include <assert.h>
#include "game_defs.h"
using namespace std;
class Point {
public:
int x;
int y;
Point();
Point(int x1, int y1);
Point addMove(int move);
Point convert();
float distance(Point p);
vector<Point> expand();
bool compare(Point b);
Point(const Point & obj);
int manDist(Point p);
};
Point::Point(const Point & obj)
: x(obj.x), y(obj.y)
{
}
Point Point::addMove(int move) {
assert(move == NORTH || move == EAST || move == WEST || move == SOUTH);
Point p = Point(x, y);
switch (move) {
case NORTH:
p.y--;
break;
case EAST:
p.x++;
break;
case SOUTH:
p.y++;
break;
case WEST:
p.x--;
break;
}
return p;
}
Point Point::convert() {
return Point(x + 1, y + 1);
}
float Point::distance(Point p) {
return sqrt(pow(x - p.x, 2) + pow(y - p.y, 2));
}
vector<Point> Point::expand() {
vector<Point> moves = vector<Point>();
for (auto m : moveslist) {
Point p = addMove(m);
moves.push_back(p);
}
return moves;
}
bool Point::compare(Point b) {
return (x == b.x) && (y == b.y);
}
Point::Point() {
x = 0;
y = 0;
}
Point::Point(int x1, int y1) {
x = x1;
y = y1;
}
int Point::manDist(Point p){
return abs(x - p.x) + abs(y - p.y);
}