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


C# IHand.Sort方法代码示例

本文整理汇总了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;
 }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:7,代码来源:PokerHandsChecker.cs

示例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);
         }
     }
 }
开发者ID:NikolaNikushev,项目名称:Lectures,代码行数:48,代码来源:PokerHandsChecker.cs

示例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;
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:23,代码来源:HandEvaluator.cs

示例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);
                    }
            }
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:74,代码来源:HandEvaluator.cs

示例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();
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:18,代码来源:PokerHandsChecker.cs

示例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;
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:16,代码来源:PokerHandsChecker.cs

示例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;
        }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:21,代码来源:PokerHandsChecker.cs


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