本文整理汇总了C++中GraphNode::GetF方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphNode::GetF方法的具体用法?C++ GraphNode::GetF怎么用?C++ GraphNode::GetF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphNode
的用法示例。
在下文中一共展示了GraphNode::GetF方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GraphNode
std::list<Vect3f> CWayPointManager::GetPath(CWayPoint* startPos, CWayPoint* destPos)
{
std::list<Vect3f> vecPath;
GraphNodeList openList;
GraphNodeList closeList;
GraphNode* gn = new GraphNode();
gn->SetWP(startPos);
openList.PushBack(gn);
GraphNode* endNode = new GraphNode();
endNode->SetWP(destPos);
while (!openList.IsEmpty())
{
GraphNode* current = openList.PopFront();
if(endNode->CompareNode(current))
{
endNode->SetParentNode(current->GetParentNode());
CHECKED_DELETE(current);
break;
}
//Add To close List
closeList.PushBack(current);
//Iterate around brothers
WayPointList& brothers = current->GetWP()->GetBrothers();
WayPointListIt it = brothers.begin();
WayPointListIt itEnd = brothers.end();
for (; it != itEnd; ++it)
{
CWayPoint* wp = *it;
//Set the cost of node_successor to be the cost of node_current plus
//the cost to get to node_successor from node_current
//Set h to be the estimated distance to node_goal (Using heuristic function)
GraphNode* successor = new GraphNode();
successor->SetWP(wp);
successor->SetG(current->GetG() + (current->GetWP()->GetPosition().Distance(wp->GetPosition())));
successor->SetH(wp->GetPosition().Distance(destPos->GetPosition()));
//find node_successor on the OPEN list
int32 ofound = openList.IndexOf(successor);
//if node_successor is on the OPEN list but the existing one is as good
//or better then discard this successor and continue
if (ofound>=0)
{
GraphNode* temp = openList.At(ofound);
if(temp->GetF() < current->GetF())
{
CHECKED_DELETE(successor);
continue;
}
}
//find node_successor on the CLOSED list
int32 cFound = closeList.IndexOf(successor);
//if node_successor is on the CLOSED list but the existing one is as good
//or better then discard this successor and continue;
if (cFound>=0)
{
GraphNode* temp = closeList.At(cFound);
if(temp->GetF() < current->GetF())
{
CHECKED_DELETE(successor);
continue;
}
}
//Remove occurences of node_successor from OPEN and CLOSED
if (ofound != -1)
{
openList.RemoveAt(ofound);
}
if (cFound!=-1)
{
closeList.RemoveAt(cFound);
}
//Set the parent of node_successor to node_current;
successor->SetParentNode(current);
//Add node_successor to the OPEN list
openList.PushBack(successor);
}
openList.Sort();
}
if(endNode->GetParentNode() == NULL)
{
//.........这里部分代码省略.........