当前位置: 首页>>代码示例>>C++>>正文


C++ AStarNode::GetScoreG方法代码示例

本文整理汇总了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);
//.........这里部分代码省略.........
开发者ID:Spacetech,项目名称:gmodmodules,代码行数:101,代码来源:astar.cpp


注:本文中的AStarNode::GetScoreG方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。