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


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

本文整理汇总了C++中AStarNode::hasVisited方法的典型用法代码示例。如果您正苦于以下问题:C++ AStarNode::hasVisited方法的具体用法?C++ AStarNode::hasVisited怎么用?C++ AStarNode::hasVisited使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AStarNode的用法示例。


在下文中一共展示了AStarNode::hasVisited方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateAction


//.........这里部分代码省略.........
						i_goal = ii;
						j_goal = jj;
					}
				}
			}
		}

		// variables needed in A* search
		Fringe fringe;
		unsigned int step = 0;
		AStarNode *node = new AStarNode(0.0f, aimDist, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, AI_VIEW_DISTANCE, true, NULL);
		int i, j;
		bool fieldVisible;

		// add initial state to fringe
		fringe.push(node);

		// do actual A* search
		while (step < AI_MAX_STEPS && !fringe.empty())
		{
			node = fringe.top();
			fringe.pop();
			i = node->i;
			j = node->j;

			if (DEBUG_ENEMY)
				_AStarFields.push_back((z + j - AI_VIEW_DISTANCE) * FIELD_SIZE + (x + i - AI_VIEW_DISTANCE));

			// goal test (stop iteration when goal is reached)
			if (i == i_goal && j == j_goal)
				break;

			// expand node
			if (0 <= i - 1 && surroundings[i - 1][j] != BUILDING && !node->hasVisited(i - 1, j))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i - 1, j, x, z, surroundings);
				else
					fieldVisible = false;
				//fringe.push(AStarNode(node.cost_so_far + 1.0f, dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
				//	i - 1, j, fieldVisible ? i - 1 : node.i_aim, fieldVisible ? j : node.j_aim, fieldVisible));
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
					i - 1, j, fieldVisible ? i - 1 : node->i_aim, fieldVisible ? j : node->j_aim, fieldVisible, node));
			}
			if (i + 1 < 2 * AI_VIEW_DISTANCE + 1 && surroundings[i + 1][j] != BUILDING && !node->hasVisited(i + 1, j))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i + 1, j, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i + 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i + 1 - AI_VIEW_DISTANCE, z + j - AI_VIEW_DISTANCE, playerPosition),
					i + 1, j, fieldVisible ? i + 1 : node->i_aim, fieldVisible ? j : node->j_aim, fieldVisible, node));
			}
			if (0 <= j - 1 && surroundings[i][j - 1] != BUILDING && !node->hasVisited(i, j - 1))
			{
				if (node->isVisible)
					fieldVisible = isFieldVisible(_position.x, _position.z, i, j - 1, x, z, surroundings);
				else
					fieldVisible = false;
				fringe.push(new AStarNode(fieldVisible ? dist(x + i - AI_VIEW_DISTANCE, z + j - 1 - AI_VIEW_DISTANCE, _position) : node->cost_so_far + 1.0f,
					dist(x + i - AI_VIEW_DISTANCE, z + j - 1 - AI_VIEW_DISTANCE, playerPosition),
					i, j - 1, fieldVisible ? i : node->i_aim, fieldVisible ? j - 1 : node->j_aim, fieldVisible, node));
			}
			if (j + 1 < 2 * AI_VIEW_DISTANCE + 1 && surroundings[i][j + 1] != BUILDING && !node->hasVisited(i, j + 1))
开发者ID:RafiKueng,项目名称:TankGame,代码行数:67,代码来源:enemy.cpp


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