本文整理汇总了C#中IHand.HighestCard方法的典型用法代码示例。如果您正苦于以下问题:C# IHand.HighestCard方法的具体用法?C# IHand.HighestCard怎么用?C# IHand.HighestCard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHand
的用法示例。
在下文中一共展示了IHand.HighestCard方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareHands
public int CompareHands(IHand firstHand, IHand secondHand)
{
// "null is smaller than a non-null object by definition"
if (firstHand == null)
{
if (secondHand == null)
return 0;
return -1;
}
if (secondHand == null)
{
return 1;
}
if (!IsValidHand(firstHand))
{
if (!IsValidHand(secondHand))
return 0;
return -1;
}
if (!IsValidHand(secondHand))
{
return 1;
}
// we could also map each hand type to an integer
foreach (var predicate in this.PredicatesList)
{
var isFirst = predicate(firstHand);
var isSecond = predicate(secondHand);
if (isFirst && isSecond)
{
if (predicate == this.IsStraightFlush ||
predicate == this.IsStraight ||
predicate == this.IsFlush ||
predicate == this.IsHighCard)
{
return firstHand.HighestCard().Face.CompareTo(
secondHand.HighestCard().Face);
}
// x of kind
var x = 0;
if (predicate == this.IsFourOfAKind)
x = 4;
if (predicate == this.IsThreeOfAKind)
x = 3;
if (predicate == this.IsTwoPair ||
predicate == this.IsOnePair)
x = 2;
var seq1 = firstHand.GetXOfKind(x).OrderByDescending(g => g.Key).SelectMany(g => g);
var seq2 = secondHand.GetXOfKind(x).OrderByDescending(g => g.Key).SelectMany(g => g);
return Utils.CompareSequences(seq1, seq2, c => (int)c.Suit);
}
if (isFirst)
{
return 1;
}
if (isSecond)
{
return -1;
}
}
Debug.Assert(false, "should not happen");
throw new ApplicationException("assertion failed");
}