本文整理汇总了C++中PathNode::getGScore方法的典型用法代码示例。如果您正苦于以下问题:C++ PathNode::getGScore方法的具体用法?C++ PathNode::getGScore怎么用?C++ PathNode::getGScore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode::getGScore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clock
vector<D3DXVECTOR3> AStar::findPath(PathNode* _start, PathNode* _end)
{
//time it for debugging
clock_t clockStart = clock();
//empty the closed set vector
vector<PathNode*>().swap(mClosedSet);
//empty the open set and put in only the start node
vector<PathNode*>().swap(mOpenSet);
mOpenSet.push_back(_start);
//set all node gScores to max
for (PathNode* PN : mPathNodes)
PN->setGScore(INT_MAX);
//set start node properties
_start->setGScore(0);
_start->setFScore(findHeuristic(_start, _end));
//while the open set is not empty
while (mOpenSet.size() > 0)
{
//the node in open set having the lowest f score
PathNode* current;
findLowestFScore(current);
//if we found the goal, return the path
if (current == _end || ((clock() - clockStart) / (float)CLOCKS_PER_SEC) > MAX_PATH_TIME_LOW)
{
vector<D3DXVECTOR3> rePath;
reconstructPath(rePath, _start, current);
return rePath;
}
//save current to closed set
mClosedSet.push_back(current);
//remove current from open set
for (vector<PathNode*>::iterator iter = mOpenSet.begin(); iter != mOpenSet.end(); ++iter)
{
if (*iter == current)
{
mOpenSet.erase(iter);
break;
}
}
//for each linked node in the current node
for (PathNode* PN : current->getLinks())
{
//if it is already in the closed set, continue
if (inClosedSet(PN))
continue;
//find tentative gScore
int tempGScore = current->getGScore() + findHeuristic(current, _end);
//if link node is not in open set or tempGScore < present GScore
if (!inOpenSet(PN) || tempGScore < PN->getGScore())
{
//set the came from of the link to the current node
PN->setCameFrom(current);
//set g score
PN->setGScore(tempGScore);
PN->setFScore(PN->getGScore() + findHeuristic(PN, _end));
//if link is not in open set, add to it
if (!inOpenSet(PN))
mOpenSet.push_back(PN);
}
}
}
//finished loop without finding goal
OutputDebugString(L"ERROR: No path found.");
return vector<D3DXVECTOR3>();
}