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


C# Dictionary.OrderByDescending方法代码示例

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


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

示例1: ChooseColor

 public override SuggestedMoves ChooseColor(Color[,] board)
 {
     IDictionary<Color, int> count = new Dictionary<Color, int>();
     foreach(MapNode edgeNode in MapBuilder.BuildMap(board).GetNeighbors())
     {
         if (!count.ContainsKey(edgeNode.Color))
         {
             count[edgeNode.Color] = 1;
         }
         else
         {
             count[edgeNode.Color] = count[edgeNode.Color] + 1;
         }
     }
     return new SuggestedMoves(count.OrderByDescending(keyValuePair => keyValuePair.Value).First().Key);
 }
开发者ID:glenwatson,项目名称:Flood-It-Solver,代码行数:16,代码来源:HighestCount.cs

示例2: GetPath

        public SuggestedMoves GetPath(Color[,] board)
        {
            //Get the farthest nodes
            TreeNode head = MapBuilder.BuildTree(board);
            ISet<TreeNode> farthestNodes = new HashSet<TreeNode>();
            int highestDepth = 0;
            foreach (TreeNode node in head.BFS()) //DFS would be better
            {
                int depth = GetDepth(node);
                if (depth > highestDepth)
                {
                    highestDepth = depth;
                    farthestNodes.Clear();
                    farthestNodes.Add(node);
                }
                else if (depth == highestDepth)
                {
                    farthestNodes.Add(node);
                }
            }

            Console.Write("Farthest nodes are ");
            farthestNodes.Select(n => n.Color).ToList().ForEach(c => Console.Write(c + ", "));
            Console.WriteLine("\r\nFarthest node is " + GetDepth(farthestNodes.First()) + " away from the current");

            //get the color that would step towards each color
            IDictionary<Color, int> tally = new Dictionary<Color, int>();
            foreach (TreeNode farthestNode in farthestNodes)
            {
                TreeNode currentNode = farthestNode;
                while (currentNode.Parent != head)
                {
                    currentNode = currentNode.Parent;
                }
                if (!tally.ContainsKey(currentNode.Color))
                {
                    tally.Add(currentNode.Color, 1);
                }
                else
                {
                    tally[currentNode.Color]++;
                }
            }
            SuggestedMoves suggestedMoves = new SuggestedMoves();
            suggestedMoves.AddFirst(new SuggestedMove(tally.OrderByDescending(kvp => kvp.Value).Select(n => n.Key)));
            return suggestedMoves;
        }
开发者ID:glenwatson,项目名称:Flood-It-Solver,代码行数:47,代码来源:MoveTowardsFarthestNodeLogic.cs

示例3: DisposerInfo

		public static string DisposerInfo()
		{
			var info = new Dictionary<string, int>();
			foreach (Disposer disposer in Disposers)
			{
				if (info.ContainsKey(disposer.GetType().Name))
				{
					info[disposer.GetType().Name] += 1;
				}
				else
				{
					info[disposer.GetType().Name] = 1;
				}
			}
			info = info.OrderByDescending(s => s.Value).ToDictionary(p => p.Key, p => p.Value);
			StringBuilder sb = new StringBuilder();
			sb.Append("\r\n");
			foreach (string key in info.Keys)
			{
				sb.Append($"{info[key],10} {key}\r\n");
			}
			
			return sb.ToString();
		}
开发者ID:egametang,项目名称:Egametang,代码行数:24,代码来源:Game.cs

示例4: QueryMultipleLogics

        /// <summary>
        /// Asks each AILogic for it's vote of color for the next move and chooses the highest vote
        /// </summary>
        private void QueryMultipleLogics()
        {
            Controller controller = GetController();
            Dictionary<Color, int> colorVote = new Dictionary<Color, int>();
            foreach (AILogicWeight logic in _logics)
            {
                SuggestedMoves colorsChosen = logic.Logic.ChooseColor(controller.GetUpdate()); //reaches across other thread to get the current Board

                if (colorsChosen.BestMoves.Any()) //if there are any moves returned
                {
                    Color color = colorsChosen.BestMoves.First();
                    if (!colorVote.ContainsKey(color))
                    {
                        colorVote.Add(color, 0);
                    }
                    colorVote[color] += logic.Weight;
                }
            }

            if (colorVote.Count > 0)
            {
                Color highestVote = colorVote.OrderByDescending(keyValuePair => keyValuePair.Value).First().Key;
                Console.WriteLine(highestVote);
                controller.PickColor(highestVote);
            }
            else
            {
                Console.WriteLine("No colors were suggested!");
            }
        }
开发者ID:glenwatson,项目名称:Flood-It-Solver,代码行数:33,代码来源:AIInput.cs


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