我正在尋找2D瓦片遊戲的路徑查找。我發現this similar answer,但我不知道如何創建比較運算符heap compares i <> i+i
,當i need manhattan(i) <> manhattan(i+1)?
我瘋狂地生鏽與cpp所以容易對我。對象與靜態位置之間的堆比較
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();
}
}
非常感謝,這是一個超級有用的後續解釋。我正在看那個文檔,但是我沒有看到爲什麼我不能使用sort_heap並避免push/pops? – Tony
你現在是如何將數據推入/彈出堆/堆的? – qxz
我編輯了我的答案的最後一部分 – qxz