Solution to bugged pathfinder
#include <queue> | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using std::cout; | |
using std::vector; | |
using std::priority_queue; | |
using std::find; | |
struct PathfinderNode | |
{ | |
PathfinderNode* pParent; | |
unsigned G, H; | |
}; | |
struct CompareNode : public std::binary_function<PathfinderNode*, PathfinderNode*, bool> | |
{ | |
bool operator()(const PathfinderNode* first, const PathfinderNode* second) const | |
{ | |
return((first->G + first->H) > (second->G + second->H)); | |
} | |
}; | |
template<typename _Tp, typename _Sequence = vector<_Tp>, | |
typename _Compare = std::less<typename _Sequence::value_type> > | |
class my_priority_queue : public priority_queue<_Tp, _Sequence, _Compare> | |
{ | |
public: | |
void erase(_Tp what) | |
{ | |
this->c.erase(find(this->c.begin(), this->c.end(), what)); | |
} | |
}; | |
int main() | |
{ | |
std::priority_queue<PathfinderNode*, std::vector<PathfinderNode*>, CompareNode> OpenList; | |
PathfinderNode* p = new PathfinderNode, *q = new PathfinderNode; | |
p->G = p->H = 10; | |
q->G = q->H = 20; | |
OpenList.push(p); | |
OpenList.push(q); | |
while(!OpenList.empty()) | |
{ | |
cout << OpenList.top()->G << " "; | |
OpenList.pop(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment