本文整理汇总了C++中AStarNode::GetScoreG方法的典型用法代码示例。如果您正苦于以下问题:C++ AStarNode::GetScoreG方法的具体用法?C++ AStarNode::GetScoreG怎么用?C++ AStarNode::GetScoreG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AStarNode
的用法示例。
在下文中一共展示了AStarNode::GetScoreG方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalcPath
NodeList_t& AStar::FindPath()
{
Reset();
FoundPath = false;
//Msg("Reset Variables: %i, %i, %i\n", Path.Count(), Opened.Count(), Closed.Count());
if(GetStart() == GetEnd())
{
//Msg("Start Is End\n");
return Path;
}
// 1) Add the starting node to the open list.
AddOpenedNode(Start);
Start->SetStatus(NULL, 0, 0, 0);
float CurrentScoreG;
float ScoreF, ScoreG, ScoreH;
NodeList_t Links;
AStarNode *Current = NULL, *LastNode = NULL, *Link = NULL;
//Msg("Added Node\n");
// 2) Repeat the following:
while(true)
{
// a) Look for the lowest F cost square on the open list. We refer to this as the current square.
Current = FindLowestF();
if(Current != NULL)
{
LastNode = Current;
if(Current->GetPos() == End->GetPos())
{
FoundPath = true;
break;
}
else
{
CurrentScoreG = Current->GetScoreG();
// b) Switch it to the closed list.
AddClosedNode(Current);
// c) For each of the nodes linked to this node...
Links = Current->GetLinks();
ScoreH = HeuristicDistance(Current->GetPos(), End->GetPos());
//Msg("Found Lowest F: %i | %f, %f, %f\n", Links.Count(), Current->GetPos().x, Current->GetPos().y, Current->GetPos().z);
for(int i = 0; i < Links.Count(); i++)
{
Link = Links[i];
if(Link != NULL)
{
// If it is not walkable or if it is on the closed list, ignore it.
if(!Link->IsClosed())
{
// If it isn’t on the open list, add it to the open list. Make the current node the parent of this node. Record the F, G, and H costs of the node.
if(!Link->IsOpened())
{
//Msg("SetStatus\n");
AddOpenedNode(Link);
ScoreG = CurrentScoreG + HeuristicDistance(Current->GetPos(), Link->GetPos());
ScoreF = ScoreG + ScoreH;
Link->SetStatus(Current, ScoreF, ScoreG, ScoreH);
}
//if(Link->Opened()) Always true?
//{
if(CurrentScoreG > ScoreG)
{
Link->SetParent(Current);
//Msg("Set Parent\n");
}
else
{
//Msg("%f | %f\n", CurrentScoreG, ScoreG);
}
//}
}
}
}
}
}
else
{
//Msg("Failed to find Lowest F\n");
break;
}
}
return CalcPath(LastNode);
//.........这里部分代码省略.........