本文整理汇总了C#中IHand.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# IHand.Sort方法的具体用法?C# IHand.Sort怎么用?C# IHand.Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHand
的用法示例。
在下文中一共展示了IHand.Sort方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsRoyalFlush
public bool IsRoyalFlush(IHand hand)
{
hand.Sort();
bool isRoyalFlush = IsValidHand(hand) && AreAllCardsSequence(hand) &&
AreAllCardsSameSuit(hand) && hand.Cards[0].Face == CardFace.Ten;
return isRoyalFlush;
}
示例2: CheckHand
public void CheckHand(IHand hand)
{
if (IsValidHand(hand))
{
hand.Sort();
bool foundPower = false;
if (!foundPower)
{
foundPower = IsRoyalFlush(hand);
}
if (!foundPower)
{
foundPower = IsStraightFlush(hand);
}
if (!foundPower)
{
foundPower = IsFourOfAKind(hand);
}
if (!foundPower)
{
foundPower = IsFullHouse(hand);
}
if (!foundPower)
{
foundPower = IsStraight(hand);
}
if (!foundPower)
{
foundPower = IsFlush(hand);
}
if (!foundPower)
{
foundPower = IsThreeOfAKind(hand);
}
if (!foundPower)
{
foundPower = IsTwoPair(hand);
}
if (!foundPower)
{
foundPower = IsOnePair(hand);
}
if (!foundPower)
{
foundPower = IsHighCard(hand);
}
}
}
示例3: CheckStraight
/// <summary>
/// Checks if the hand contains five cards of sequential rank.
/// </summary>
/// <param name="hand">The hand to check.</param>
/// <returns>True if straight, otherwise - false.</returns>
private bool CheckStraight(IHand hand)
{
hand.Sort();
if ((hand.Cards[4].Rank - hand.Cards[0].Rank) == 4)
{
return true;
}
if (hand.Cards[4].Rank == CardRank.Ace &&
hand.Cards[3].Rank == CardRank.Five)
{
// a wheel: A, 2, 3, 4, 5
return true;
}
return false;
}
示例4: CompareHands
/// <summary>
/// Compares two poker hands.
/// </summary>
/// <param name="hand1">The first hand.</param>
/// <param name="hand2">The second hand.</param>
/// <returns>Less than zero if <paramref name="hand1"/> ranks lower than
/// <paramref name="hand2"/>, zero if the hands are of equal value,
/// greater than zero if <paramref name="hand1"/> ranks higher than
/// <paramref name="hand2"/>.</returns>
public int CompareHands(IHand hand1, IHand hand2)
{
HandCategory category1 = this.GetCategory(hand1);
HandCategory category2 = this.GetCategory(hand2);
if (category1 < category2)
{
// hand1 ranks lower than hand2
return -1;
}
if (category1 > category2)
{
// hand1 ranks above hand2
return 1;
}
hand1.Sort();
hand2.Sort();
// hand1 and hand2 are of the same type
switch (category1)
{
case HandCategory.StraightFlush:
case HandCategory.Straight:
{
return this.CompareStraightHands(hand1, hand2);
}
case HandCategory.FourOfAKind:
{
return this.CompareFourOfAKindHands(hand1, hand2);
}
case HandCategory.FullHouse:
{
return this.CompareFullHouseHands(hand1, hand2);
}
case HandCategory.Flush:
{
return this.CompareHighCardHands(hand1, hand2);
}
case HandCategory.ThreeOfAKind:
{
return this.CompareThreeOfAKindHands(hand1, hand2);
}
case HandCategory.TwoPair:
{
return this.CompareTwoPairHands(hand1, hand2);
}
case HandCategory.OnePair:
{
return this.CompareOnePairHands(hand1, hand2);
}
default:
{
return this.CompareHighCardHands(hand1, hand2);
}
}
}
示例5: OrderCards
private KeyValuePair<CardFace, int>[] OrderCards(IHand hand)
{
hand.Sort();
Dictionary<CardFace, int> arrangedCards = new Dictionary<CardFace, int>();
foreach (CardFace face in Enum.GetValues(typeof(CardFace)))
{
arrangedCards[face] = 0;
}
foreach (ICard card in hand.Cards)
{
arrangedCards[card.Face]++;
}
return arrangedCards.OrderByDescending(x => x.Value).ToArray();
}
示例6: IsStraight
public bool IsStraight(IHand hand)
{
hand.Sort();
if ((hand.Cards[4].Face - hand.Cards[0].Face) == 4)
{
return true;
}
if (hand.Cards[4].Face == CardFace.Ace && hand.Cards[3].Face == CardFace.Five)
{
return true;
}
return false;
}
示例7: AreAllCardsSequence
private bool AreAllCardsSequence(IHand hand)
{
hand.Sort();
for (int i = 0; i < hand.Cards.Count - 1; i++)
{
int previousCardPower = (int)hand.Cards[i].Face;
int nextCardPower = (int)hand.Cards[i + 1].Face;
if (previousCardPower != nextCardPower - 1)
{
// A 2 3 4 5 is also valid sequence
bool isStraightWIthAceAsMin = i == 3 && previousCardPower == 5 && nextCardPower == 14;
if (!isStraightWIthAceAsMin)
{
return false;
}
}
}
return true;
}