-
Notifications
You must be signed in to change notification settings - Fork 0
/
DA.cpp
88 lines (74 loc) · 2.55 KB
/
DA.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
/*
void actualizar(std::vector<AStarNodo*>& n)
{
std::make_heap(n.begin(),n.end(),menor);//hago uso de monticulo
std::sort_heap(n.begin(),n.end(),menor);
}
*/
void push(std::vector<AStarNode*>& v, AStarNode* current)
{
v.push_back(current);
std::make_heap(v.begin(),v.end(),menor);//hago uso de monticulo
std::sort_heap(v.begin(),v.end(),menor);
}
AStarNode* pop(std::vector<AStarNode*>& o, std::vector<AStarNode*>& c)
{
AStarNode* a = o.back();
o.pop_back();
c.push_back(a);
std::make_heap(o.begin(),o.end(),menor);//hago uso de monticulo
std::sort_heap(o.begin(),o.end(),menor);
return a;
}
void DEF_LIB_EXPORTED calculatePath(AStarNode* originNode, AStarNode* targetNode
, int cellsWidth, int cellsHeight, float mapWidth, float mapHeight
, float** additionalCost, std::list<Vector3> &path) {
std::vector<AStarNode*> o;
std::vector<AStarNode*> c;
AStarNode* actual = originNode;
current->G = 0;
current->H = _sdistance(current->position, targetNode->position);
current->F = current->H + current->G;
push(o, actual);
bool encontrado = false;
while(encontrado == false && o.size() > 0)
{
actual = pop(o,c);
if(actual == targetNode)
{
encontrado = true;
}else
{
for(std::list<AStarNode*>::iterator j = actual->adjacents.begin(); j != actual->adjacents.end();++j)
{
if(search(c,(*j)) == false)//para saber que es distinto de close
{
if(search(o,(*j)) == false)//para saber que es distinesto de open
{
(*j)->parent = actual;
(*j)->G = actual->G + _distance(actual->position, (*j)->position);//duda distance
(*j)->H = _sdistance((*j)->position, targetNode->position)//duda con estimated distance
(*j)->F = (*j)->G + (*j)->H;
push(o,(*j));
}else{
float d = _distance((*i)->position, actual->position);
if((*j)->G > actual->G + d)
{
(*j)->parent = actual;
(*j)->G = actual->G + d;
(*j)->F = (*j)->G + (*j)->H;
actualizar(o);
}
}
}
}
}
}
AStarNode* final = targetNode;
while(final != originNode)
{
path.push_front(final->position);
final = final->parent;
}
path.push_front(final->position);
}