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


C# PriorityQueue.TrimToSize方法代码示例

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


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

示例1: GetBestPathFrom

        private static Path GetBestPathFrom(Board b, Options o, int y, int x, BoardScorer.Options bso)
        {
            Path bestPath = new Path();
            PriorityQueue<Tuple<Board, Path>, double> paths = new PriorityQueue<Tuple<Board, Path>, double>();
            paths.Enqueue(new Tuple<Board, Path>(b, new Path
            {
                Start = new Tuple<int, int>(y, x),
                Current = new Tuple<int, int>(y, x),
                Depth = 1,
                Score = b.Score(bso)
            }));
            int depth = 0;
            while (depth++ < o.MaxDepth)
            {
               // Console.WriteLine("currently at depth {0}...", depth);
                PriorityQueue<Tuple<Board, Path>, double> newPaths = new PriorityQueue<Tuple<Board, Path>, double>();
                while (paths.Count != 0)
                {
                    var cur = paths.Dequeue();
                    var curPath = cur.Item2;
                    var curBoard = cur.Item1;
                    if (curPath.Score > bestPath.Score)
                        bestPath = curPath;

                    //if (paths.Count() > o.WhenToPrune)
                    //{
                    //    var newPaths = new Stack<Tuple<Board, Path>>();
                    //    foreach (var path in paths.OrderByDescending(p => p.Item2.Score).Take(o.NumToKeep).Reverse())
                    //        newPaths.Push(path);
                    //    paths = newPaths;
                    //}

                    foreach (var direction in Board.MoveDirections)
                    {
                        if (curPath.Length != 0 &&
                            curPath.Actions.Last()[0] == -direction[0] &&
                            curPath.Actions.Last()[1] == -direction[1])
                            continue;
                        var newY = curPath.Current.Item1 + direction[0];
                        var newX = curPath.Current.Item2 + direction[1];
                        if (newY < 0 || newY >= b.Height ||
                            newX < 0 || newX >= b.Width)
                            continue;
                        Board newBoard = new Board(curBoard);
                        Orb tempOrb = newBoard.Orbs[newY, newX];
                        newBoard.Orbs[newY, newX] = newBoard.Orbs[curPath.Current.Item1, curPath.Current.Item2];
                        newBoard.Orbs[curPath.Current.Item1, curPath.Current.Item2] = tempOrb;
                        var newPath = new List<int[]>(curPath.Actions);
                        newPath.Add(direction);
                        double score = newBoard.Score(bso) - curPath.Depth / 100;
                        newPaths.Enqueue(new Tuple<Board, Path>(newBoard, new Path
                        {
                            Start = curPath.Start,
                            Current = new Tuple<int, int>(newY, newX),
                            Depth = curPath.Depth + 1,
                            Score = score,
                            Actions = newPath
                        }), score);
                    }
                }
                paths = newPaths.TrimToSize(o.BeamWidth);
            }
            return bestPath;
        }
开发者ID:toraora,项目名称:PadPlayer,代码行数:64,代码来源:BeamDfs.cs


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