本文整理汇总了C++中node::Ptr::getScore方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::getScore方法的具体用法?C++ Ptr::getScore怎么用?C++ Ptr::getScore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node::Ptr
的用法示例。
在下文中一共展示了Ptr::getScore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::vector<sf::Vector2f> PathFinder::plotPath(const sf::Vector2u& start, const sf::Vector2u& end) const
{
Node::Ptr currentNode;
std::set<Node::Ptr> openSet;
std::set<Node::Ptr> closedSet;
openSet.insert(std::make_shared<Node>(static_cast<sf::Vector2i>(start)));
while (!openSet.empty())
{
currentNode = *openSet.begin();
for (const auto& node : openSet)
{
if (node->getScore() <= currentNode->getScore())
{
currentNode = node;
}
}
if (currentNode->position == end)
{
break;//we're at the end!
}
closedSet.insert(currentNode);
openSet.erase(std::find(std::begin(openSet), std::end(openSet), currentNode));
for (auto i = 0u; i < directions.size(); ++i)
{
auto coords = currentNode->position + directions[i];
if (collides(coords) || nodeOnList(closedSet, coords))
{
continue;
}
auto cost = currentNode->G + (i < 4u) ? 10u : 14u;
auto nextNode = nodeOnList(openSet, coords);
if (!nextNode)
{
nextNode = std::make_shared<Node>(coords, currentNode);
nextNode->G = cost;
nextNode->H = heuristic(nextNode->position, static_cast<sf::Vector2i>(end));
openSet.insert(nextNode);
}
else if (cost < nextNode->G)
{
nextNode->parent = currentNode;
nextNode->G = cost;
}
}
}
//climb tree to get our path
std::vector<sf::Vector2f> points;
while (currentNode)
{
points.emplace_back(currentNode->position.x * m_tileSize.x, (currentNode->position.y * m_tileSize.y) + m_tileSize.y);
points.back() += m_gridOffset;
currentNode = currentNode->parent;
}
//and update vis for debug
m_path.clear();
for (const auto& p : points)
{
m_path.emplace_back(p, sf::Color::Blue);
}
return std::move(points);
}