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


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

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


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

示例1: ExpandNode

inline bool AStar::ExpandNode()
{
    // Get the min-weight element off the fringe.
    std::pop_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());
    CurrentNode = FringeNodes.back();
    FringeNodes.pop_back();

    MapCoordinates TestCoordinates = CurrentNode->LocationCoordinates;

    if (VisitedCoordinates.find(TestCoordinates) != VisitedCoordinates.end())
    {
        return false;
    }

    if (TestCoordinates == GoalCoordinates)
    {
        return true; //GenerateBestPath();
    }

    // mark as VisitedCoordinates if not already VisitedCoordinates
    VisitedCoordinates.insert(TestCoordinates);

    MapCoordinates NeiboringCoordinates;
    DirectionFlags TestDirections = SearchGraph->getDirectionFlags(TestCoordinates);

    // Check all Neibors
	for (uint8_t i = 0, DirectionType = Direction::ANGULAR_DIRECTIONS[i]; i < NUM_ANGULAR_DIRECTIONS; ++i, DirectionType = Direction::ANGULAR_DIRECTIONS[i])
    {
        if (TestDirections & (1 << i))  // Connectivity is valid for this direction
        {
            NeiboringCoordinates = TestCoordinates;
            NeiboringCoordinates.TranslateMapCoordinates(DirectionType);

            // If Coordinate is not already on the VisitedCoordinates list
            if (VisitedCoordinates.find(NeiboringCoordinates) == VisitedCoordinates.end())
            {
                float EdgeCost = SearchGraph->getEdgeCost(TestCoordinates, DirectionType);
                GraphReads++;

                AStarNode* NewNode = NodePool->ProvideObject();
                NewNode->Set(NeiboringCoordinates, CurrentNode, DirectionType, CurrentNode->PathLengthFromStart + EdgeCost, MainHeuristic->Estimate(NeiboringCoordinates, GoalCoordinates), TieBreakerHeuristic->Estimate(NeiboringCoordinates, GoalCoordinates));

                // Add the new Node to the Fringe
                FringeNodes.push_back(NewNode);
                std::push_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());
            }
        }
    }

    return false; // Goal was not found
}
开发者ID:Ackak,项目名称:Khazad,代码行数:51,代码来源:Astar.cpp

示例2: setEndPoints

void AStar::setEndPoints(const MapCoordinates &StartCoords, const MapCoordinates &GoalCoords)
{
    StartCoordinates = StartCoords;
    GoalCoordinates = GoalCoords;
    GraphReads = ExpandedNodes = 0;
    FinalPath = NULL;
    FringeExausted = false;

    FringeNodes.clear();
    VisitedCoordinates.clear();

    NodePool->Wipe();

    AStarNode* StartNode = NodePool->ProvideObject();
    StartNode->Set(StartCoordinates, NULL, DIRECTION_NONE, 0, MainHeuristic->Estimate(StartCoords, GoalCoords), TieBreakerHeuristic->Estimate(StartCoords, GoalCoords));

    FringeNodes.push_back(StartNode);
    std::make_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());

    //VisitedCoordinates.insert(StartCoordinates);
};
开发者ID:Ackak,项目名称:Khazad,代码行数:21,代码来源:Astar.cpp


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