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


C# PriorityQueue.isVisited方法代码示例

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


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

示例1: findPath

    //This is the method that will do A*. It returns a vector of locations to follow
    public LinkedList<Vector3> findPath(Vector3 start, Vector3 end)
    {
        LinkedList<Vector3> result = new LinkedList<Vector3> ();
        Node startNode = currentGraph.getNodeByLocation ((int)start.y, (int)start.x);
        startNode.rawCost = 0.0f;
        queue = new PriorityQueue (startNode);
        while (!queue.isEmpty()) {
            //The A* magic happens here
            Node minNode = queue.pop ();
            //if this is our ending node, stop pathfinding and form our full path on the graph
            if (minNode == currentGraph.getNodeByLocation ((int) end.y, (int) end.x)) {
                //Here we form the path depending
                Node currentNode = minNode;

                while (currentNode != null) {
                    result.AddFirst(new Vector3(currentNode.widthPos, currentNode.heightPos));
                    currentNode = currentNode.parent;
                }
                resetGraph();
                return result;
            }
            //else, we need to update our priority queue, etc.
            else {
                float currentRaw = minNode.rawCost;
                foreach (Node neighbor in minNode.edges.Values) {
                    if (queue.isVisited(neighbor)) {
                        float oldRaw = neighbor.rawCost;
                        float newRaw = currentRaw + Vector2.Distance(new Vector2(minNode.widthPos, minNode.heightPos), new Vector2(neighbor.widthPos, neighbor.heightPos));
                        if (newRaw < oldRaw) {
                            neighbor.rawCost = newRaw;
                            neighbor.parent = minNode;
                        }
                    } else {
                        neighbor.rawCost = currentRaw + Vector2.Distance(new Vector2(minNode.widthPos, minNode.heightPos), new Vector2(neighbor.widthPos, neighbor.heightPos));
                        neighbor.parent = minNode;
                        queue.insert(neighbor);
                    }
                }
            }
        }
        resetGraph ();
        return result;
    }
开发者ID:charder,项目名称:GameAIUnity,代码行数:44,代码来源:WorldCreator.cs


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