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


C# Heap.GetEqual方法代码示例

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


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

示例1: FindPath

    /// <summary>
    /// Finds the shortest path from the start node to the goal node
    /// </summary>
    /// <param name="startPosition">Start position</param>
    /// <param name="goalPosition">Goal position</param>
    /// <param name="startMeshNode">Start mesh node</param>
    /// <param name="goalMeshNode">Goal mesh node</param>
    public List<NavmeshPolygon> FindPath(Vector3 startPosition, Vector3 goalPosition, NavmeshPolygon startPolygon, NavmeshPolygon goalPolygon)
    {
        //Debug.Log("AStar.FindPath");
        //Debug.Log("startPosition == " + startPosition);
        //Debug.Log("goalPosition == " + goalPosition);
        StartPosition = startPosition;
        GoalPosition = goalPosition;

        GoalNode = new AStarNode(this, null, goalPolygon, 0);
        StartNode = new AStarNode(this, null, startPolygon, 0);

        Heap openList = new Heap();
        Heap closedList = new Heap();
        List<AStarNode> solution = new List<AStarNode>();
        List<AStarNode> successors = new List<AStarNode>();

        int printed = 0;
        openList.Add(StartNode);
        while (openList.Count > 0) {
            //Debug.Log("AStar:main loop");
            // Get the node with the lowest TotalSum
            AStarNode nodeCurrent = (AStarNode)openList.Pop();
            if (printed < 1000){
                //Debug.Log("Current polygon: " + nodeCurrent.NavmeshPolygon.name + " - " + nodeCurrent.TotalCost);
                printed++;
            }

            // If the node is the goal copy the path to the solution array
            if (GoalNode.Equals(nodeCurrent)) {
                //Debug.Log("AStar:finish loop");
                while (nodeCurrent != null) {
                    solution.Insert(0, nodeCurrent);
                    nodeCurrent = nodeCurrent.Parent;
                }

                //convert solution
                //Debug.Log("Path found");
                return solution.ConvertAll(an => an.NavmeshPolygon);
            }

            // Get successors to the current node
            successors.Clear();
            nodeCurrent.GetSuccessors(successors);
            foreach (AStarNode nodeSuccessor in successors) {
                //Debug.Log("AStar:successor loop");
                // Test if the currect successor node is on the open list, if it is and
                // the TotalSum is higher, we will throw away the current successor.
                //Debug.Log("AStarNode nodeOpen");
                AStarNode nodeOpen;
                if (openList.Contains(nodeSuccessor)) {
                    //Debug.Log("openList check: nodeSuccessor (" + nodeSuccessor.NavmeshPolygon.name + ") - " + nodeSuccessor.TotalCost);
                    //Debug.Log("openList contains nodeSuccessor");
                    //Debug.Log("nodeOpen = (AStarNode)openList[openList.IndexOf(nodeSuccessor)];");
                    nodeOpen = (AStarNode)openList.GetEqual(nodeSuccessor);
                    //Debug.Log("openList check: nodeOpen (" + nodeOpen.NavmeshPolygon.name + ") - " + nodeOpen.TotalCost);
                    //Debug.Log("if ((nodeOpen != null) && (nodeSuccessor.TotalCost > nodeOpen.TotalCost))");
                    if ((nodeOpen != null) && (nodeSuccessor.TotalCost > nodeOpen.TotalCost)){
                        //Debug.Log("continue;");
                        //Debug.Log("openList check: continued");
                        continue;
                    } else {
                        //Debug.Log("openList check: not continued");
                    }

                }

                // Test if the currect successor node is on the closed list, if it is and
                // the TotalSum is higher, we will throw away the current successor.
                //Debug.Log("AStarNode nodeClosed;");
                AStarNode nodeClosed;
                //Debug.Log("if (closedList.Contains(nodeSuccessor)) {");
                if (closedList.Contains(nodeSuccessor)) {
                    //Debug.Log("closedList check: nodeSuccessor (" + nodeSuccessor.NavmeshPolygon.name + ") - " + nodeSuccessor.TotalCost);
                    //Debug.Log("closedList contains nodeSuccessor");
                    //Debug.Log("nodeClosed = (AStarNode)closedList[closedList.IndexOf(nodeSuccessor)];");
                    nodeClosed = (AStarNode)closedList.GetEqual(nodeSuccessor);
                    //Debug.Log("closedList check: nodeClosed (" + nodeClosed.NavmeshPolygon.name + ") - " + nodeClosed.TotalCost);
                    //Debug.Log("if ((nodeClosed != null) && (nodeSuccessor.TotalCost > nodeClosed.TotalCost))");
                    if ((nodeClosed != null) && (nodeSuccessor.TotalCost > nodeClosed.TotalCost)){
                        //Debug.Log("continue;");
                        continue;
                    }
                }

                // Remove the old successor from the open list
                //Debug.Log("openList.Remove(nodeSuccessor);");
                openList.Remove(nodeSuccessor);

                // Remove the old successor from the closed list
                //Debug.Log("closedList.Remove(nodeSuccessor);");
                closedList.Remove(nodeSuccessor);

                // Add the current successor to the open list
//.........这里部分代码省略.........
开发者ID:kiichi7,项目名称:Lies_and_Seductions,代码行数:101,代码来源:AStar.cs


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