mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
calculating heuristics in a function
ending pathpoint generation early for empty paths
This commit is contained in:
@@ -16,6 +16,15 @@ namespace battleship{
|
||||
return pathfinder;
|
||||
}
|
||||
|
||||
vector<float> Pathfinder::calcHeuristics(vector<Map::Cell> &cells, int dest){
|
||||
vector<float> heuristics;
|
||||
|
||||
for(Map::Cell &cell : cells)
|
||||
heuristics.push_back(145 * (cells[dest].pos.getDistanceFrom(cell.pos)));
|
||||
|
||||
return heuristics;
|
||||
}
|
||||
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, vector<float> &heuristics, int source, int dest, Vehicle *vehicle){
|
||||
const int size = cells.size();
|
||||
u32 *distances = new u32[size];
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace battleship{
|
||||
class Pathfinder{
|
||||
public:
|
||||
static Pathfinder* getSingleton();
|
||||
std::vector<float> calcHeuristics(std::vector<Map::Cell>&, int);
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, std::vector<float>&, int, int, Vehicle* = nullptr);
|
||||
inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;}
|
||||
inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;}
|
||||
|
||||
+4
-4
@@ -343,12 +343,12 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
vector<float> heuristics;
|
||||
Pathfinder *pf = Pathfinder::getSingleton();
|
||||
vector<float> heuristics = pf->calcHeuristics(cells, dest);
|
||||
vector<int> path = pf->findPath(cells, heuristics, source, dest, this);
|
||||
|
||||
for(Map::Cell &cell : cells)
|
||||
heuristics.push_back(145 * (cells[dest].pos.getDistanceFrom(cell.pos)));
|
||||
if(path.empty()) return;
|
||||
|
||||
vector<int> path = Pathfinder::getSingleton()->findPath(cells, heuristics, source, dest, this);
|
||||
path.erase(path.begin());
|
||||
bool pathTruncated = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user