本文整理汇总了C++中Hexagon::neighbors方法的典型用法代码示例。如果您正苦于以下问题:C++ Hexagon::neighbors方法的具体用法?C++ Hexagon::neighbors怎么用?C++ Hexagon::neighbors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hexagon
的用法示例。
在下文中一共展示了Hexagon::neighbors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
std::vector<Hexagon*> HexagonGrid::findPath(Hexagon* from, Hexagon* to)
{
Hexagon* current = 0;
std::vector<Hexagon*> result;
std::priority_queue<Hexagon*, std::vector<Hexagon*>, HeuristicComparsion> unvisited;
unsigned int cameFrom[200*200] = {};
unsigned int costSoFar[200*200] = {};
// if we can't go to the location
// @todo remove when path will have lenght restriction
if (!to->canWalkThru()) return result;
unvisited.push(from);
cameFrom[from->number()] = 0;
costSoFar[from->number()] = 0;
while (!unvisited.empty())
{
current = unvisited.top(); unvisited.pop();
if (current == to) break;
// search limit
if (costSoFar[current->number()] >= 100) break;
for (Hexagon* neighbor : *current->neighbors())
{
if (!neighbor->canWalkThru()) continue;
unsigned int newCost = costSoFar[current->number()] + 1;
if (!costSoFar[neighbor->number()] || newCost < costSoFar[neighbor->number()])
{
costSoFar[neighbor->number()] = newCost;
neighbor->setHeuristic(distance(neighbor, to) + newCost);
unvisited.push(neighbor);
cameFrom[neighbor->number()] = current->number();
}
}
}
// found nothing
if (current != to) return result;
while (current->number() != from->number())
{
result.push_back(current);
current = _hexagons.at(cameFrom[current->number()]);
}
return result;
}