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


C# PriorityQueue.RemoveMin方法代码示例

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


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

示例1: AStarSearch

        public void AStarSearch(Vector2 sourcePoint, Vector2 destinationPoint, out Vector2 nextNode)
        {
            //Console.WriteLine("Going from (" + sourcePoint.X + ", " + sourcePoint.Y + ") to (" + destinationPoint.X + ", " + destinationPoint.Y + ")");
            Node source = adjacencyList[(int)(columns * sourcePoint.X + sourcePoint.Y)];
            Node destination = adjacencyList[(int)(columns * destinationPoint.X + destinationPoint.Y)];

            PriorityQueue <Node> Q = new PriorityQueue<Node>();
            source.Distance = 0;
            Q.Add(source.Priority, source);

            while (Q.Count > 0)
            {
                Node current = Q.RemoveMin();

                if (current == destination)
                {
                    Node pathParent = current.Parent;
                    Stack<Node> path = new Stack<Node>();
                    path.Push(current);
                    while (pathParent != null)
                    {
                        path.Push(pathParent);
                        pathParent = pathParent.Parent;
                    }

                    Thread t = new Thread(new ParameterizedThreadStart(DrawPath));
                    t.Start(path);

                    path.Pop();
                    nextNode = new Vector2(path.Peek().X * 32, path.Peek().Y * 32);

                    return;
                }

                List<Node> allAdjacent = new List<Node>();
                allAdjacent.AddRange(current.AdjacentNodes);
                allAdjacent.AddRange(current.CornerNodes);
                foreach (Node n in allAdjacent)
                {
                    Node node = adjacencyList[columns * n.X + n.Y];
                    if (node.Distance == int.MaxValue)
                    {
                        node.Distance = current.Distance + 1;
                        node.Parent = current;
                        node.Visited = true;
                        node.Priority = (int)(destinationPoint - sourcePoint).Length() + node.Distance;
                        Q.Add(node.Priority, node);
                    }
                }
            }
            nextNode = new Vector2(-1);
        }
开发者ID:abatilo,项目名称:GDD3400CatAndMouse,代码行数:52,代码来源:Graph.cs

示例2: findPath

        public static Path findPath(Node startNode, Node destination)
        {
            List<Node> closedList = new List<Node>();
            PriorityQueue<Node> openList = new PriorityQueue<Node>();

            Dictionary<Node, int> gScore = new Dictionary<Node,int>();
            gScore[startNode] = 0;

            Dictionary<Node, int> fScore = new Dictionary<Node,int>();
            fScore[startNode] = startNode.HeuristicDistance(destination);

            Dictionary<Node, Node> prevNode = new Dictionary<Node, Node>();

            openList.Add(fScore[startNode], startNode);

            while (openList.Count > 0)
            {
                Node current = openList.RemoveMin();
                if (current.Equals(destination))
                {
                    return getPath(prevNode, destination);
                }
                else
                {
                    closedList.Add(current);
                    Node[] neighbours = current.GetNeighbours();
                    foreach (Node next in neighbours)
                    {
                        if (closedList.Contains(next))
                            continue;

                        int newGScore = gScore[current] + current.distanceBetween(next);

                        if (!openList.Contains(next) || newGScore < gScore[next])
                        {
                            prevNode[next] = current;
                            gScore[next] = newGScore;
                            fScore[next] = gScore[next] + next.HeuristicDistance(destination);
                            if (!openList.Contains(next))
                                openList.Add(fScore[next], next);
                        }
                    }
                }
            }

            return null;
        }
开发者ID:cedwards145,项目名称:ld33,代码行数:47,代码来源:AStarPathfinder.cs


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