I'm working on pathfinding for a 2D tile game. I've found this similar answer, but I'm not sure how to do create the comparison operator when heap compares i <> i+i
, when i need manhattan(i) <> manhattan(i+1)?
I'm insanely rusty with cpp so go easy on me.
typedef std::tuple<int, int> coord;
int manhattan(coord start, coord goal){
return (std::abs(start.get<0> - goal.get<0>) + \
std::abs(start.get<1> - goal.get<1>) )
}
bool operator()((const coord& left, const coord& right){
return manhattan(left, ???) < manhattan(right, ???);
}
vector pathfinding(coord start, coord goal){
//using A* format
vector<coord> open;
while(open){
//how can I compare indexes to goal parameter?
std::sort_heap(open.begin(), open.end());
current = open.front();
}
}