calculating heuristics in a function

ending pathpoint generation early for empty paths
This commit is contained in:
devZoGok
2026-03-15 15:21:11 +02:00
parent 4709581fcd
commit 03f9f9cc2e
3 changed files with 14 additions and 4 deletions
+9
View File
@@ -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];
+1
View File
@@ -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
View File
@@ -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;