本文整理汇总了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);
}
示例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;
}
示例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();
}
示例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!");
}
}