HOG2
PRAStarUnit.cpp
Go to the documentation of this file.
1 /*
2  * $Id: praStarUnit.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 1/16/05.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include "PRAStarUnit.h"
13 
14 praStarUnit::praStarUnit(int _x, int _y, AbsMapUnit *_target, praStar *_alg)
15 :SearchUnit(_x, _y, _target, _alg), algorithm(_alg)
16 { cache = 0; }
17 
18 //praStarUnit::praStarUnit(int _x, int _y, int _r, int _g, int _b, unit *_target, praStar *_alg)
19 //:SearchUnit(_x, _y, _r, _g, _b, _target, _alg), algorithm(_alg)
20 //{ cache = 0; }
21 
22 
24 {
25  MapAbstraction *aMap = mp->GetMapAbstraction();
26 
28  if (moves.size() != 0)
29  {
30  return SearchUnit::makeMove(mp, rp, simInfo);
31  }
32  if (cache != 0)
33  {
34  node *n = aMap->GetNodeFromMap(loc.x, loc.y);
35  node *l = aMap->GetNthParent(n, cache->n->GetLabelL(kAbstractionLevel));
36  while (cache && (l != cache->n))
37  {
38  path *tmp = cache;
39  cache = cache->next;
40  tmp->next = 0;
41  delete tmp;
42  }
43  if (cache)
44  assert(l == cache->n);
45  if (cache && (cache->next == 0))
46  {
47  delete cache;
48  cache = 0;
49  }
50  }
52  //printf("--- cached PRA --- start ---\n");
53  tDirection where = SearchUnit::makeMove(mp, rp, simInfo);
54  //printf("--- cached PRA --- finish ---\n");
55  return where;
56 }
loc::x
int x
Definition: MapGenerators.cpp:296
praStarUnit::algorithm
praStar * algorithm
Definition: PRAStarUnit.h:32
MapProvider::GetMapAbstraction
virtual MapAbstraction * GetMapAbstraction()=0
SimulationInfo
Definition: SimulationInfo.h:13
MapProvider
Definition: MapProvider.h:23
loc::y
int y
Definition: MapGenerators.cpp:296
AbsMapUnit
A simple map-based unit.
Definition: AbsMapUnit.h:24
path::n
node * n
Definition: Path.h:22
praStarUnit::makeMove
tDirection makeMove(MapProvider *, reservationProvider *, SimulationInfo *simInfo)
Definition: PRAStarUnit.cpp:23
SearchUnit::moves
std::vector< tDirection > moves
Definition: SearchUnit.h:56
praStar::setCache
void setCache(path **p)
Definition: PRAStar.cpp:28
praStarUnit::cache
path * cache
Definition: PRAStarUnit.h:31
SearchUnit
A general unit which collects path information from a SearchAlgorithm and incrementally executes that...
Definition: SearchUnit.h:26
loc
Definition: MapGenerators.cpp:296
SearchUnit::makeMove
virtual bool makeMove(MapProvider *, reservationProvider *, AbsMapSimulationInfo *simInfo, tDirection &dir)
Definition: SearchUnit.cpp:108
GraphAbstractionConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: GraphAbstraction.h:25
tDirection
tDirection
Definition: Map2DEnvironment.h:77
reservationProvider
Definition: ReservationProvider.h:33
praStar
The pra* search algorithm which does partial pathfinding using abstraction.
Definition: PRAStar.h:23
praStarUnit::praStarUnit
praStarUnit(int _x, int _y, unit *_target, praStar *_alg)
Definition: PRAStarUnit.cpp:14
path::next
path * next
Definition: Path.h:23
node::GetLabelL
long GetLabelL(unsigned int index) const
Definition: Graph.h:220
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
PRAStarUnit.h
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
praStar::setExpandSearchRadius
void setExpandSearchRadius(bool _expandSearchRadius)
Definition: PRAStar.h:34