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


C++ TileSet::begin方法代码示例

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


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

示例1: FindPath

TileVector PathFinder::FindPath() const
{
	TileSet closed = {};
	TileSet open = { &m_source };

	CostMap g_score; // Cost from start to this node.
	CostMap f_score; // Cost to get to this node + estimated cost to dest.
	CameFromMap cameFrom;

	g_score[&m_source] = 0;
	f_score[&m_source] = _Heuristic(m_source, m_dest);

	while (!open.empty())
	{
		// Take the element in the open set with least total estimated cost.
		Tile* curr = *std::min_element(open.begin(), open.end(),
			[&f_score](Tile* a, Tile* b)
			{
				return (f_score[a] < f_score[b]);
			});

		if (curr == &m_dest)
		{
			// We've found the best path.
			return _Reconstruct(cameFrom, m_dest);
		}

		open.erase(curr);
		closed.insert(curr);
		for (Tile* neighbour : _Neighbours(m_map, *curr))
		{
			if (closed.find(neighbour) != closed.end())
				continue;

			int tentative_g_score = g_score[curr] + neighbour->MoveCost();

			// If neighbour isn't in the open set, or we have found a better path to neighbour, update it.
			if ((open.find(neighbour) == open.end()) || (tentative_g_score < g_score[neighbour]))
			{
				// This could be done without recalculating the heuristic, if desired.
				cameFrom[neighbour] = curr;
				g_score[neighbour] = tentative_g_score;
				f_score[neighbour] = tentative_g_score + _Heuristic(*neighbour, m_dest);
				open.insert(neighbour);
			}
		}
	}

	// Failure
	printf("No path\n");
	return{};
}
开发者ID:tomrosling,项目名称:tile,代码行数:52,代码来源:PathFinder.cpp

示例2: ForEachReachableTile

void Map::ForEachReachableTile( const Unit* unit, ForEachReachableTileCallback callback )
{
    assertion( unit, "Cannot find reachable tiles for null Unit!" );
    assertion( callback.IsValid(), "Cannot call invalid callback on reachable tiles!" );

    // Find all reachable tiles for the Unit.
    TileSet reachableTiles;
    FindReachableTiles( unit, reachableTiles );

    for( auto it = reachableTiles.begin(); it != reachableTiles.end(); ++it )
    {
        // Invoke the callback on all reachable tiles.
        callback.Invoke( *it, unit );
    }
}
开发者ID:hydraskillz,项目名称:AndroidWars,代码行数:15,代码来源:Map.cpp


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