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


C++ World::GetInky方法代码示例

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


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

示例1: aStar

	//run A* from the closest node to Blinky to the closest node that Pacman is occupying
	Direction::Enum aStar(const World& in_ourWorld, PathNode* currentNode, PathNode* targetNode)
	{
		std::priority_queue<std::shared_ptr<ScoredNode>, std::vector<std::shared_ptr<ScoredNode>>, std::function<bool(std::shared_ptr<ScoredNode>, std::shared_ptr<ScoredNode>)>> frontier(NodeComparer);
		std::map<PathNode*, std::shared_ptr<ScoredNode>> processedNodes;
		std::map<PathNode*, std::shared_ptr<ScoredNode>> frontierMap;

		std::vector<const Pawn* const> ghosts;
		ghosts.push_back(&in_ourWorld.GetBlinky());
		ghosts.push_back(&in_ourWorld.GetInky());
		ghosts.push_back(&in_ourWorld.GetPinky());
		ghosts.push_back(&in_ourWorld.GetClyde());

		std::shared_ptr<ScoredNode> rootNode = std::make_shared<ScoredNode>(currentNode, 0.f, huristic(*currentNode, *targetNode), Direction::Invalid, nullptr);
		frontier.push(rootNode);
		frontierMap.insert(std::pair<PathNode*, std::shared_ptr<ScoredNode>>(currentNode, rootNode));

		while (frontier.size() > 0 && frontier.top()->node != targetNode)
		{
			std::shared_ptr<ScoredNode> topNode = frontier.top();
			frontier.pop();

			auto frontierEntry = frontierMap.find(topNode->node);

			//If we are not in the frontier map then this is just garbage to be collected
			if (frontierEntry == frontierMap.end())
				continue;

			frontierMap.erase(frontierEntry);
			processedNodes.insert(std::pair<PathNode*, std::shared_ptr<ScoredNode>>(topNode->node, topNode));

			Expand(in_ourWorld, topNode, *targetNode, ghosts, frontier, frontierMap, processedNodes);
		}

		if (frontier.size() > 0)
		{
			ScoredNode* rootConnection = frontier.top()->GetRootConnection();
			if (rootConnection)
				return rootConnection->connectionDirection;
		}

		return Direction::Invalid;
	}
开发者ID:Samee-Swartz,项目名称:SuperSecretProject,代码行数:43,代码来源:Pacman3.cpp


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