저는 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/pop을 피할 수 없는지에 대한 이유는 없습니다. – Tony
현재 힙에서 값을 밀어 넣거나 튕기는 방법은 무엇입니까? – qxz
나는 내 대답의 마지막 부분을 편집했습니다. – qxz