-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.h
96 lines (75 loc) · 1.55 KB
/
Cell.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
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef CELL_H_
#define CELL_H_
struct Cell
{
int x, y;
Cell(int _x, int _y) : x(_x), y(_y)
{}
};
struct Move
{
int x, y;
double v;
Move(int _x, int _y, double _v) : x(_x), y(_y), v(_v)
{}
bool operator<(const Move &m) const
{
return v < m.v;
};
};
class PathCell
{
public:
int x, y;
int length = 0, h = 0;
PathCell *parent = nullptr;
vector <PathCell> visited;
double GetValue()
{ return (h - (length / 3)); }
bool Compare(PathCell other)
{
if (x == other.x && y == other.y && parent == other.parent && GetValue() == other.GetValue())
return true;
return false;
}
PathCell(int _x, int _y, PathCell *_parent) : x(_x), y(_y), parent(_parent)
{}
PathCell(int _x, int _y, PathCell *_p, int _h, int _l, vector <PathCell> _v) : x(_x), y(_y), parent(_p), h(_h), length(_l), visited(_v)
{}
};
class ASCell //For use in AStar
{
private:
double f, g, h;
ASCell *parent;
public:
int x, y;
void SetValues(double _h, double _g)
{
h = _h;
g = _g;
f = g + h;
}
double G() const
{ return g; }
double F() const
{ return f; }
ASCell Parent() const
{ return *parent; }
void SetParent(ASCell *_p)
{
parent = _p;
}
ASCell(int _x, int _y) : x(_x), y(_y)
{
g = 1000;
h = 1000;
f = g + h;
parent = nullptr;
}
bool operator>(const ASCell &asCell) const
{
return F() > asCell.F();
};
};
#endif /* CELL_H_ */