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


C# PriorityQueue.Any方法代码示例

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


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

示例1: Search

        public static int Search(List<State> states, List<Action> actions, State start, Tile target)
        {
            var found = 0;

            PriorityQueue<BFNode> frontier = new PriorityQueue<BFNode>();
            List<State> explored = new List<State>();

            frontier.Add(new BFNode(start));

            while (frontier.Count > 0)
            {
            // Chooses the lowest-cost node in the frontier
            BFNode currentBFNode = frontier.Pop();

            // Win condition
            if (currentBFNode.State.Type.Equals(target))
            found++;

            explored.Add(currentBFNode.State);

            // Filter actions to the ones connected to the current node
            foreach (Action action in actions.Where(a => a.StateA.Equals(currentBFNode.State)))
            {
            // One of A or B will be the currentBFNode's action
            // but it won't be added to the frontier since it
            // is already in explored
            var childA = new BFNode(currentBFNode, action, action.StateA);
            var childB = new BFNode(currentBFNode, action, action.StateB);

            if (!explored.Contains(childA.State) && !frontier.Any(n => n.State == childA.State))
            frontier.Add(childA);

            if (!explored.Contains(childB.State) && !frontier.Any(n => n.State == childB.State))
            frontier.Add(childB);
            }
            }
            return found;
        }
开发者ID:altschuler,项目名称:skattejagt,代码行数:38,代码来源:FullSearch.cs

示例2: GetPath

        public List<MapTile> GetPath(Point start, Point goal) {
            var startTile = GetTile(start);
            var goalTile = GetTile(goal);

            // check that the start and goal positions are valid, and are not the same
            if (!Within(start) || !Within(goal) || start == goal || startTile == null || goalTile == null) {
                return new List<MapTile>();
            }
            // Check that start and goal are walkable and that a path can exist between them
            if (startTile.Set != goalTile.Set) {
                return new List<MapTile>();
            }


            // reset costs
            foreach (var t in _tiles) {
                t.F = t.G = float.MaxValue;
            }
            var open = new PriorityQueue<MapTile>(_tiles.Length);
            var closed = new HashSet<MapTile>();

            startTile.G = 0;
            startTile.F = h(start, goal);

            open.Enqueue(startTile, startTile.F);

            MapTile current = null;
            while (open.Any() && current != goalTile) {
                current = open.Dequeue();
                closed.Add(current);
                for (var i = 0; i < 8; i++) {
                    var edge = current.Edges[i];

                    if (edge == null) {
                        continue;
                    }
                    var neighbor = edge.Node2;
                    var cost = current.G + edge.Cost;



                    if (open.Contains(neighbor) && cost < neighbor.G) {
                        open.Remove(neighbor);
                    }
                    if (closed.Contains(neighbor) && cost < neighbor.G) {
                        closed.Remove(neighbor);
                    }
                    if (!open.Contains(neighbor) && !closed.Contains(neighbor)) {
                        neighbor.G = cost;
                        var f = cost + h(neighbor.MapPosition, goal);
                        open.Enqueue(neighbor, f);
                        neighbor.Parent = current;

                    }
                }
            }
            System.Diagnostics.Debug.Assert(current == goalTile);
            var path = new List<MapTile>();


            while (current != startTile) {
                path.Add(current);
                current = current.Parent;
            }
            path.Reverse();
            return path;
        }
开发者ID:amitprakash07,项目名称:dx11,代码行数:67,代码来源:Terrain.cs


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