HOG2
SearchUnit.h
Go to the documentation of this file.
1 /*
2  * $Id: SearchUnit.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 10/4/04.
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 "Unit.h"
13 #include "Map.h"
14 #include "SearchAlgorithm.h"
16 #include "AbsMapUnit.h"
17 
18 #ifndef SearchUnit_H
19 #define SearchUnit_H
20 
26 class SearchUnit : public AbsMapUnit {
27 public:
28  SearchUnit(int x, int y, AbsMapUnit *target, SearchAlgorithm *alg);
29  virtual ~SearchUnit();
30  virtual const char *GetName() { if (algorithm) return algorithm->GetName(); return "none"; }
31  virtual SearchAlgorithm* getAlgorithm() { return algorithm; }
32  //void setUnitSimulation(unitSimulation *_US) { US = _US; algorithm->setSimulationEnvironment(US); }
33  virtual bool Done() { return onTarget; }
34 
35  void GetGoal(xyLoc &gs) { if (target) target->GetLocation(gs); else GetLocation(gs); }
36  //xyLoc GetGoal() { return target->GetLocation(); }
37  virtual void setTarget(AbsMapUnit *u) { target = u; }
38 
39  //using unit::makeMove;
40  // this is where the World says you are
41  virtual bool MakeMove(AbsMapEnvironment *ame, OccupancyInterface<xyLoc,tDirection> *, AbsMapSimulationInfo *si, tDirection &dir)
42  { return makeMove(ame->GetMapAbstraction(), 0, si,dir); }
43  virtual bool makeMove(MapProvider *, reservationProvider *, AbsMapSimulationInfo *simInfo, tDirection &dir);
44 
45  void UpdateLocation(AbsMapEnvironment *, xyLoc &l, bool success, AbsMapSimulationInfo *si) { updateLocation(l.x, l.y, success, si); }
46  virtual void updateLocation(int _x, int _y, bool, AbsMapSimulationInfo *);
47  virtual void OpenGLDraw(const AbsMapEnvironment *, const AbsMapSimulationInfo *) const;
48  //void printRoundStats(FILE *f);
49  void LogStats(StatCollection *stats);
50  void LogFinalStats(StatCollection *stats);
51 protected:
52  virtual void addPathToCache(path *p);
53  bool getCachedMove(tDirection &dir);
56  std::vector<tDirection> moves;
57  // path *p;
61 
63 
64  double targetTime;
65  bool onTarget;
66 };
67 
68 #endif
spreadExecSearchAlgorithm
Definition: SpreadExecSearchAlgorithm.h:17
SearchUnit::getCachedMove
bool getCachedMove(tDirection &dir)
Definition: SearchUnit.cpp:89
SearchUnit::addPathToCache
virtual void addPathToCache(path *p)
Definition: SearchUnit.cpp:222
SearchUnit::OpenGLDraw
virtual void OpenGLDraw(const AbsMapEnvironment *, const AbsMapSimulationInfo *) const
Definition: SearchUnit.cpp:283
SimulationInfo
Definition: SimulationInfo.h:13
SearchUnit::setTarget
virtual void setTarget(AbsMapUnit *u)
Definition: SearchUnit.h:37
SearchUnit::~SearchUnit
virtual ~SearchUnit()
Definition: SearchUnit.cpp:79
MapProvider
Definition: MapProvider.h:23
SearchUnit::nodesExpanded
int nodesExpanded
Definition: SearchUnit.h:54
xyLoc::y
uint16_t y
Definition: Map2DEnvironment.h:42
AbsMapUnit
A simple map-based unit.
Definition: AbsMapUnit.h:24
SearchAlgorithm.h
SearchUnit::Done
virtual bool Done()
Definition: SearchUnit.h:33
xyLoc
Definition: Map2DEnvironment.h:37
SearchUnit::MakeMove
virtual bool MakeMove(AbsMapEnvironment *ame, OccupancyInterface< xyLoc, tDirection > *, AbsMapSimulationInfo *si, tDirection &dir)
Definition: SearchUnit.h:41
SearchUnit::moves
std::vector< tDirection > moves
Definition: SearchUnit.h:56
xyLoc::x
uint16_t x
Definition: Map2DEnvironment.h:41
SearchUnit::GetGoal
void GetGoal(xyLoc &gs)
Definition: SearchUnit.h:35
SearchUnit::targetTime
double targetTime
Definition: SearchUnit.h:64
SearchUnit
A general unit which collects path information from a SearchAlgorithm and incrementally executes that...
Definition: SearchUnit.h:26
AbsMapUnit.h
SearchUnit::makeMove
virtual bool makeMove(MapProvider *, reservationProvider *, AbsMapSimulationInfo *simInfo, tDirection &dir)
Definition: SearchUnit.cpp:108
SearchUnit::GetName
virtual const char * GetName()
Definition: SearchUnit.h:30
SearchUnit::target
AbsMapUnit * target
Definition: SearchUnit.h:62
SearchAlgorithm::GetName
virtual const char * GetName()=0
tDirection
tDirection
Definition: Map2DEnvironment.h:77
SearchUnit::SearchUnit
SearchUnit(int x, int y, AbsMapUnit *target, SearchAlgorithm *alg)
Definition: SearchUnit.cpp:20
SearchUnit::spread_cache
path * spread_cache
Definition: SearchUnit.h:60
SearchUnit::nodesTouched
int nodesTouched
Definition: SearchUnit.h:55
SearchUnit::UpdateLocation
void UpdateLocation(AbsMapEnvironment *, xyLoc &l, bool success, AbsMapSimulationInfo *si)
Definition: SearchUnit.h:45
SearchUnit::getAlgorithm
virtual SearchAlgorithm * getAlgorithm()
Definition: SearchUnit.h:31
SearchUnit::algorithm
SearchAlgorithm * algorithm
Definition: SearchUnit.h:58
SearchUnit::updateLocation
virtual void updateLocation(int _x, int _y, bool, AbsMapSimulationInfo *)
Definition: SearchUnit.cpp:270
StatCollection
The StatCollection class is for collecting stats across different parts of the simulation.
Definition: StatCollection.h:34
SearchUnit::s_algorithm
spreadExecSearchAlgorithm * s_algorithm
Definition: SearchUnit.h:59
reservationProvider
Definition: ReservationProvider.h:33
SearchAlgorithm
A generic algorithm which can be used for pathfinding.
Definition: SearchAlgorithm.h:25
SearchUnit::onTarget
bool onTarget
Definition: SearchUnit.h:65
Map.h
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
AbsMapUnit::GetLocation
virtual void GetLocation(xyLoc &l)
Definition: AbsMapUnit.h:34
SpreadExecSearchAlgorithm.h
SearchUnit::LogFinalStats
void LogFinalStats(StatCollection *stats)
log any final one-time stats before a simulation is ended
Definition: SearchUnit.cpp:346
Unit.h
SearchUnit::LogStats
void LogStats(StatCollection *stats)
log an stats that may have been computed during the last run
Definition: SearchUnit.cpp:330
OccupancyInterface< xyLoc, tDirection >