本文整理汇总了C++中LinkList::At方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkList::At方法的具体用法?C++ LinkList::At怎么用?C++ LinkList::At使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkList
的用法示例。
在下文中一共展示了LinkList::At方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetPath
void Graph::GetPath(Graph_Node* StartNode, Graph_Node* EndNode, LinkList<Graph_Node* > *Path, bool Advanced)
{
LinkList<PathNode*> OpenList;
LinkList<PathNode*> ClosedList;
bool Found = false;
/**< Create our first Node on OpenList made From the start Node */
OpenList.Push_Front(new PathNode(StartNode,0,0,(StartNode->GetPosition() - EndNode->GetPosition()).length()));
/**< If we haven't found our goal Node yet */
while(!Found)
{
/**< If there are no more Nodes to expand from then there is no way to get to the goal Node so exit the Method */
if(OpenList.GetSize() == 0)
{
return;
}
/**< Get and remove first node on the OpenList and push onto ClosedList */
PathNode* Currentnode = OpenList.Pop_Front();
ClosedList.Push_Front(Currentnode);
/**< If Current Node is the goal Node then we have found the Goal Node so exit loop */
if(Currentnode->mNode == EndNode)
{
Found = true;
}
/**< Iterate through each Edge in the Node creating a new PathNode push on the OpenList */
for(int i = 0;i < Currentnode->mNode->GetEdgeCount();i++)
{
float cost, Heuristic;
/**< The current Node being pushed on the OpenList */
Graph_Node* node = Currentnode->mNode->GetTo(i);
/**< Create new PathNode if Node isn't used or Edge to Node isn't hidden */
if(!node->GetUsed() && !Currentnode->mNode->GetHidden(i))
{
/**< If advanced search get advanced cost and Heuristic*/
if(!Advanced)
{
cost = Currentnode->mKnownCost + (Currentnode->mNode->GetWeight(i)); /**< Add up how much it took to get to this Node */
Heuristic = (node->GetPosition() - EndNode->GetPosition()).length(); /**< Guess how much it would take to get to the Goal Node */
}/**< Else get normal cost and Heuristic*/
else
{
cost = Currentnode->mKnownCost + (Currentnode->mNode->GetWeight(i) * Currentnode->mNode->GetAdvancedWeight(i)); /**< Add up how much it took to get to this Node */
Heuristic = (node->GetPosition() - EndNode->GetPosition()).length(); /**< Guess how much it would take to get to the Goal Node */
}
PathNode* newnode = new PathNode(node,Currentnode,cost, cost + Heuristic); /**< Create New Path Node */
int iter = 0;
/**< Get the position in the OpenList that has a bigger cost than the new Nodes cost. */
/**< Push new node infront of that position */
if(OpenList.GetSize() != 0)
{
while(newnode->mGuess > OpenList.At(iter)->mGuess && iter != OpenList.GetSize())
{
iter++;
}
}
/**< Set the Edge we just Used To Used */
/**< Insert the New Node into the OpenList */
node->SetUsed(true);
OpenList.Insert(newnode,iter);
}
}
}
/**< Reset all Nodes in the OpenList */
for(ListIterator<PathNode*> iter(&OpenList); !iter.IsNuLL();iter++)
{
iter.Value()->mNode->SetUsed(false);
}
/**< Reset all Nodes in the ClosedList */
for(ListIterator<PathNode*> iter(&ClosedList); !iter.IsNuLL();iter++)
{
iter.Value()->mNode->SetUsed(false);
}
/**< Set the first Node on the ClosedList */
/**< (Which is the last Node added so will be the Goal Node) */
/**< to the Node we will use to iterate through the Closed List */
PathNode* CreatePathNode = ClosedList.At(0);
/**< While the PathNode isnt 0. */
/**< (The start Node was added to the ClosedList, with a previous that is set to 0) */
/**< Add the GraphNode to the Path then set the created PathNode to the previous Node */
/**<(Which is the PathNode Used to expand The current Node) */
while(CreatePathNode != 0)
{
Path->Push_Front(CreatePathNode->mNode);
CreatePathNode = CreatePathNode->mPrevious;
}
}