MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / AstarEntry

Class AstarEntry

source/gamemap/GameMap.cpp:87–150  ·  view source on GitHub ↗

! \brief A helper class for the A* search in the GameMap::path function. * * This class stores the requisite information about a tile which is placed in * the search queue for the A-star, or A*, algorithm which is used to * calculate paths in the path function. * * The A* description can be found here: * http://en.wikipedia.org/wiki/A*_search_algorithm */

Source from the content-addressed store, hash-verified

85* http://en.wikipedia.org/wiki/A*_search_algorithm
86*/
87class AstarEntry
88{
89public:
90 AstarEntry() :
91 tile (nullptr),
92 parent (nullptr),
93 g (0.0),
94 h (0.0)
95 {}
96
97 AstarEntry(Tile* tile, int x1, int y1, int x2, int y2) :
98 mHasBeenProcessed (false),
99 tile (tile),
100 parent (nullptr),
101 g (0.0),
102 h (0.0)
103 {
104 h = computeHeuristic(x1, y1, x2, y2);
105 }
106
107 static double computeHeuristic(const int& x1, const int& y1, const int& x2, const int& y2)
108 {
109 return fabs(static_cast<double>(x2 - x1)) + fabs(static_cast<double>(y2 - y1));
110 }
111
112 void setHeuristic(const int& x1, const int& y1, const int& x2, const int& y2)
113 {
114 h = fabs(static_cast<double>(x2 - x1)) + fabs(static_cast<double>(y2 - y1));
115 }
116
117 inline double fCost() const
118 { return g + h; }
119
120 inline Tile* getTile() const
121 { return tile; }
122
123 inline bool getHasBeenProcessed() const
124 { return mHasBeenProcessed; }
125
126 inline void setHasBeenProcessed()
127 { mHasBeenProcessed = true; }
128
129 inline void setTile(Tile* newTile)
130 { tile = newTile; }
131
132 inline AstarEntry* getParent() const
133 { return parent; }
134
135 inline void setParent(AstarEntry* newParent)
136 { parent = newParent; }
137
138 inline const double& getG() const
139 { return g; }
140
141 inline void setG(const double& newG)
142 { g = newG; }
143
144private:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected