本文整理汇总了C++中AStarNode::GetCost方法的典型用法代码示例。如果您正苦于以下问题:C++ AStarNode::GetCost方法的具体用法?C++ AStarNode::GetCost怎么用?C++ AStarNode::GetCost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AStarNode
的用法示例。
在下文中一共展示了AStarNode::GetCost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Step
AStar::StepStatus AStar::Step()
{
if (mOpenList.Num() == 0) return Err_NoPath;
// Open List is sorted by F, so simply take the lowest F node (first on list) and expand it
AStarNode *pNode = mOpenList[0];
// remove the first node off the open list (lowest F)
mOpenList.RemoveAt(0, 1, false);
// add to closed list
mClosedList.Add(pNode);
// if we have reached our target (endx,endy) with the current node.. then work backwards along its parent chain until we get to the start
if (pNode->x == endx && pNode->y == endy)
{
// found our path! create the path nodes list and return success!
// step backwards through our nodes from pNode until we reach our start node.. adding each to our final path
while (pNode != NULL && (pNode->x != startx || pNode->y != starty))
{
mFinalPath.Insert(pNode,0);
// node walking potential disaster :)
pNode = pNode->pParentNode;
// PC: TODO find the ASSERT macro for UE4!!
//assert(pNode != NULL);
}
return PathComplete;
}
TArray<AStarNode *> tempNodes;
// haven't reached our end goal, so lets expand our nodes
pNode->GetConnectedNodes(pGen, tempNodes);
for(AStarNode * node : tempNodes)
{
// Make the "current" node the parent of this new node
// Record the F, G, and H costs of the new node
node->pParentNode = pNode;
node->G = pNode->G + pNode->GetCost(node);
node->H = node->GetHCost(endx, endy);
node->F = node->G + node->H;
// find node in closed list if we find a node and it has a lower F value, then discard the new node as unimportant
//int32 closedindex = mClosedList.IndexOfByKey(node);
int32 closedindex = mClosedList.IndexOfByPredicate([&](AStarNode * n) { return (*n == *node); });
if (closedindex != INDEX_NONE)
{
if (mClosedList[closedindex]->F < node->F)
continue;
}
// find node in open list if we find a node and it has a lower F value, then discard the new node as unimportant
//int32 index = mOpenList.IndexOfByKey(node);
int32 index = mOpenList.IndexOfByPredicate([&](AStarNode * n) { return (*n == *node); });
if (index != INDEX_NONE)
{
//If it is on the open list already, check to see if this path to that square is better, using F cost as the measure.
if (mOpenList[index]->F < node->F)
continue;
}
// remove nodes from closed or open lists if they weren't "better" but still existed..
if (closedindex != INDEX_NONE)
{
mClosedList.RemoveAt(closedindex, 1, false);
}
if (index != INDEX_NONE)
{
mOpenList.RemoveAt(index, 1, false);
}
// finally, add our node to the open list
mOpenList.Add(node);
}
// puke memory BAD! :)
tempNodes.Empty();
mOpenList.Sort(AStar::AStarNodePredicate);
return PathContinue;
}