本文整理汇总了C++中PriorityQueue::is_empty方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::is_empty方法的具体用法?C++ PriorityQueue::is_empty怎么用?C++ PriorityQueue::is_empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue::is_empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find_path
void find_path(NavGridLocation from, NavGridLocation to)
{
int grid_size = gs.grid.get_width() * gs.grid.get_height();
int from_id = hash_location(from);
std::vector<AiNode> nodes (grid_size);
for (int i = 0; i < nodes.size(); i++) {
AiNode& node = nodes[i];
node.id = i;
node.visited = false;
node.prev_node = nullptr;
node.true_score = std::numeric_limits<float>::max();
node.guess_score = std::numeric_limits<float>::max();
node.pq_node = nullptr;
}
nodes[from_id].true_score = 0.f;
nodes[from_id].guess_score = heuristic_cost(unhash_location(from_id), to);
PriorityQueue<AiNode*> pq;
nodes[from_id].pq_node = pq.enqueue(&nodes[from_id], -nodes[from_id].guess_score);
update_prev(nodes);
while (!pq.is_empty()) {
AiNode* current = pq.get_front();
pq.dequeue();
current->pq_node = nullptr;
current->visited = true;
if (current->id == hash_location(to)) {
break;
}
for (const NavGridLocation& adj : gs.grid.get_adjacent(unhash_location(current->id))) {
AiNode* adj_node = &nodes[hash_location(adj)];
if (adj_node->visited)
continue;
float new_score = current->true_score + 1;
if (new_score >= adj_node->true_score)
continue;
adj_node->prev_node = current;
adj_node->true_score = new_score;
adj_node->guess_score = new_score + heuristic_cost(unhash_location(adj_node->id), to);
if (adj_node->pq_node) {
pq.update(adj_node->pq_node, -adj_node->guess_score);
} else {
adj_node->pq_node = pq.enqueue(adj_node, -adj_node->guess_score);
}
}
}
update_prev(nodes);
update_path(nodes, to);
}