本文整理汇总了C++中AStarNode::setDistanceToGoal方法的典型用法代码示例。如果您正苦于以下问题:C++ AStarNode::setDistanceToGoal方法的具体用法?C++ AStarNode::setDistanceToGoal怎么用?C++ AStarNode::setDistanceToGoal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AStarNode
的用法示例。
在下文中一共展示了AStarNode::setDistanceToGoal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::vector<AStarNode*>* AStarAlgorithm::startAlgorithm2(AStarNode* startNode, AStarNode* endNode, std::vector<AStarNode*> &path)
{
path.clear();
std::vector<AStarNode*> pathList;
pathList.push_back(startNode);
std::vector<AStarNode*> wastedList;
AStarNode* tmp;
bool wasIn = false;
bool shorterPathFound = false;
int distanceTraveled = 0;
bool secondOut = false;
AStarNode* returnNode;
returnNode = startNode;
while (pathList.size() != 0 && pathList.back()->getName() != endNode->getName() && !pathList.empty())
{
tmp = pathList.back();
wastedList.push_back(pathList.back());
pathList.pop_back();
if (secondOut)
{
returnNode = tmp;
secondOut = false;
}
if (tmp->getName() == startNode->getName())
{
secondOut = true;
}
//adding new paths
for (int i = 0; i < tmp->getPaths()->size(); i++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() != tmp->getVisitor()->getName() && tmp->getPaths()->at(i)->getEndNode()->getName() != startNode->getName())
{
AStarNode* copyNode = new AStarNode();
for (int j = 0; j < pathList.size(); j++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() == pathList.at(j)->getName())
{
wasIn = true;
copyNode->setPathList(*pathList.at(j)->getPaths());
copyNode->setName(pathList.at(j)->getName());
copyNode->setDistanceToGoal(pathList.at(j)->getDistanceToGoal());
//copyNode->setPosition(wastedList.at(j)->getPosition());
break;
}
}
for (int m = 0; m < wastedList.size(); m++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() == wastedList.at(m)->getName())
{
wasIn = true;
copyNode->setPathList(*wastedList.at(m)->getPaths());
copyNode->setName(wastedList.at(m)->getName());
copyNode->setDistanceToGoal(wastedList.at(m)->getDistanceToGoal());
copyNode->setPosition(wastedList.at(m)->getPosition());
break;
}
}
if (!wasIn){
tmp->getPaths()->at(i)->getEndNode()->setDistanceTravelled(tmp->getPaths()->at(i)->getTimeToTravel() + tmp->getDistanceTravelled());
tmp->getPaths()->at(i)->getEndNode()->setTemporary(tmp->getPaths()->at(i)->getEndNode()->getDistanceToGoal() + tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled());
for (int n = 0; n < pathList.size(); n++)
{
if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() < tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled())
{
shorterPathFound = true;
}
else if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() >= tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled()){
pathList.erase(pathList.begin() + n);
}
}
if (!shorterPathFound)
{
pathList.push_back(tmp->getPaths()->at(i)->getEndNode());
tmp->getPaths()->at(i)->getEndNode()->setVisitor(tmp);
}
else{
shorterPathFound = false;
}
}
else{
copyNode->setDistanceTravelled(-(copyNode->getDistanceTravelled()));
copyNode->setDistanceTravelled(tmp->getPaths()->at(i)->getTimeToTravel() + tmp->getDistanceTravelled());
copyNode->setTemporary(tmp->getPaths()->at(i)->getEndNode()->getDistanceToGoal() + copyNode->getDistanceTravelled());
for (int n = 0; n < pathList.size(); n++)
{
if (pathList.at(n)->getName() == copyNode->getName() && pathList.at(n)->getDistanceTravelled() < copyNode->getDistanceTravelled())
{
shorterPathFound = true;
}
else if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() >= tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled()){
pathList.at(n)->setDistanceTravelled(copyNode->getDistanceTravelled());
//.........这里部分代码省略.........