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


C# IHand类代码示例

本文整理汇总了C#中IHand的典型用法代码示例。如果您正苦于以下问题:C# IHand类的具体用法?C# IHand怎么用?C# IHand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: IsFlush

        public bool IsFlush(IHand hand)
        {
            var handCards = hand.Cards;

            if (!IsValidHand(hand))
            {
                return false;
            }

            for (var i = 0; i < handCards.Count; i += 5)
            {
                var firstCard = handCards[i];
                var secondCard = handCards[i + 1];
                var thirdCard = handCards[i + 2];
                var fourthCard = handCards[i + 3];
                var fifthCard = handCards[i + 4];
                if (firstCard.Suit == secondCard.Suit &&
                    secondCard.Suit == thirdCard.Suit &&
                    thirdCard.Suit == fourthCard.Suit &&
                    fourthCard.Suit == fifthCard.Suit)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:darkyto,项目名称:HQC-Course,代码行数:27,代码来源:PokerHandsChecker.cs

示例2: CompareHighCards

        public static int CompareHighCards(IHand firstHand, IHand secondHand)
        {
            List<CardFace> facesFirstHand = GetSortedFaces(firstHand);
            List<CardFace> facesSecondHand = GetSortedFaces(secondHand);

            return CompareFaceListsOfEqualLength(facesFirstHand, facesSecondHand);
        }
开发者ID:PetarPenev,项目名称:Telerik,代码行数:7,代码来源:Compararer.cs

示例3: Compare

        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <returns>
        /// A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>, as shown in the following table.Value Meaning Less than zero<paramref name="x"/> is less than <paramref name="y"/>.Zero<paramref name="x"/> equals <paramref name="y"/>.Greater than zero<paramref name="x"/> is greater than <paramref name="y"/>.
        /// </returns>
        /// <param name="x">The first object to compare.</param><param name="y">The second object to compare.</param>
        public int Compare(IHand x, IHand y)
        {
            Argument.IsNotNull(() => x);
            Argument.IsNotNull(() => y);
            if (x.Count != y.Count)
                throw new InvalidOperationException("Cannot compare hands with a different number of cards");

            if (x.Type != Hands.Straight &&
                y.Type != Hands.Straight)
                throw new InvalidOperationException("Cannot compare hands if neither hand is a Straight.");

            if (x.Type != Hands.Straight &&
                y.Type == Hands.Straight)
                return -1 * Constants.SortDirection;

            if (x.Type == Hands.Straight &&
                y.Type != Hands.Straight)
                return 1 * Constants.SortDirection;

            if (x.HighCard < y.HighCard)
                return -1 * Constants.SortDirection;
            if (x.HighCard > y.HighCard)
                return 1 * Constants.SortDirection;

            return 0;
        }
开发者ID:Trezamere,项目名称:Poker,代码行数:33,代码来源:StraightComparer.cs

示例4: IsStraightFlush

        public bool IsStraightFlush(IHand hand)
        {
            throw new NotImplementedException();
            //var faces = new List<int>(5);
            //if (!this.IsFlush(hand))
            //{
            //    return false;
            //}
            //else
            //{
            //    foreach (var card in hand.Cards)
            //    {
            //        faces.Add((int)card.Suit);
            //    }
            //}

            //faces.Sort();
            //for (int i = 0; i < faces.Count - 1; i++)
            //{
            //    if (faces[i] + 1 != faces[i+1])
            //    {
            //        return false;
            //    }
            //}

            //return true;
        }
开发者ID:abaditsegay,项目名称:SVN,代码行数:27,代码来源:PokerHandsChecker.cs

示例5: Compare

        /// <summary>
        /// Compares the specified hand to determine if it is of the same type as this comparer.
        /// </summary>
        /// <param name="hand">The hand to be compared.</param>
        /// <returns>
        /// a tuple specifying information about the comparison.
        /// <para>The first value returns the type of this comparer if the specified hand matches, otherwise it returns <see cref="Hands.HighCard"/>.</para>
        /// <para>The second value indicates the high card of the hand if there was a match, otherwise it returns <see cref="Rank.Two"/>.</para>
        /// </returns>
        public Tuple<Hands, Rank> Compare(IHand hand)
        {
            Argument.IsNotNull(() => hand);
            if (hand.Count < 5)
                return Tuple.Create<Hands, Rank>(0, 0);

            // create a map of the rank and count for each card in the hand.
            var map = new Dictionary<Rank, int>(hand.Count);
            for (int i = 0; i < hand.Count; i++)
            {
                if (map.ContainsKey(hand[i].Rank))
                    map[hand[i].Rank]++;
                else
                    map[hand[i].Rank] = 1;
            }

            // If count does not have two elements, then we have more than 2 kinds of cards in the hand, can't be full house.
            if (map.Count != 2)
                return Tuple.Create<Hands, Rank>(0, 0);

            // Get the entry with 3
            foreach (var kvp in map)
            {
                if (kvp.Value == 3)
                    return Tuple.Create(Hands.FullHouse, kvp.Key);
            }

            // Should never get here, but compiler.
            return Tuple.Create<Hands, Rank>(0, 0);
        }
开发者ID:Trezamere,项目名称:Poker,代码行数:39,代码来源:FullHouseComparer.cs

示例6: IsFourOfAKind

        public bool IsFourOfAKind(IHand hand)
        {
            if (!this.IsValidHand(hand))
            {
                return false;
            }

            for (int i = 0; i < ValidCardCount; i++)
            {
                int count = 0;
                for (int j = 0; j < ValidCardCount; j++)
                {
                    if (hand.Cards[i].Face == hand.Cards[j].Face)
                    {
                        count++;
                    }

                    if (count == 4)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:dchakov,项目名称:High-Quality-Code-HomeWork,代码行数:26,代码来源:PokerHandsChecker.cs

示例7: Compare

        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <returns>
        /// A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>, as shown in the following table.Value Meaning Less than zero<paramref name="x"/> is less than <paramref name="y"/>.Zero<paramref name="x"/> equals <paramref name="y"/>.Greater than zero<paramref name="x"/> is greater than <paramref name="y"/>.
        /// </returns>
        /// <param name="x">The first object to compare.</param><param name="y">The second object to compare.</param>
        public int Compare(IHand x, IHand y)
        {
            Argument.IsNotNull(() => x);
            Argument.IsNotNull(() => y);
            if (x.Count != y.Count)
                throw new InvalidOperationException("Cannot compare hands with a different number of cards");

            if (x.Type != Hands.ThreeOfAKind &&
                y.Type != Hands.ThreeOfAKind)
                throw new InvalidOperationException("Cannot compare hands if neither hand has Three-of-a-kind.");

            if (x.Type != Hands.ThreeOfAKind &&
                y.Type == Hands.ThreeOfAKind)
                return -1 * Constants.SortDirection;

            if (x.Type == Hands.ThreeOfAKind &&
                y.Type != Hands.ThreeOfAKind)
                return 1 * Constants.SortDirection;

            if (x.HighCard < y.HighCard)
                return -1 * Constants.SortDirection;
            if (x.HighCard > y.HighCard)
                return 1 * Constants.SortDirection;

            // compare kicker cards.
            return _comparer.Compare(x, y);
        }
开发者ID:Trezamere,项目名称:Poker,代码行数:34,代码来源:ThreeOfAKindComparer.cs

示例8: IsFullHouse

        public bool IsFullHouse(IHand hand)
        {
            bool haveThreeOfAKind = this.IsRightTimesOfRepeat(hand, 3);
            bool haveOtherOnePair = false;

            int counter = 0;

            for (int i = 0; i < hand.Cards.Count; i++)
            {
                for (int j = 0; j < hand.Cards.Count; j++)
                {
                    if (hand.Cards[i].Face == hand.Cards[j].Face)
                    {
                        counter++;
                    }
                }

                if (counter == 2)
                {
                    haveOtherOnePair = true;
                    break;
                }

                counter = 0;
            }

            return haveThreeOfAKind && haveOtherOnePair;
        }
开发者ID:DYanis,项目名称:Poker5CardDrawCompareHandsEngine,代码行数:28,代码来源:HandStrengthRecognizer.cs

示例9: IsValid

        /// <summary>
        /// Checks if <paramref name="hand"/> is a valid poker hand.
        /// </summary>
        /// <param name="hand">The hand to check.</param>
        /// <returns>True if the hand is valid, otherwise - false.</returns>
        public bool IsValid(IHand hand)
        {
            if (hand == null)
            {
                return false;
            }

            ICard[] cards = hand.Cards;

            if (cards.Length != HandSize)
            {
                return false;
            }

            for (int i = 0; i < cards.Length - 1; i++)
            {
                for (int j = i + 1; j < cards.Length; j++)
                {
                    if (cards[i].Equals(cards[j]))
                    {
                        return false;
                    }
                }
            }

            return true;
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:32,代码来源:HandEvaluator.cs

示例10: IsFourOfAKind

        public bool IsFourOfAKind(IHand hand)
        {
            bool isHandValid = IsValidHand(hand);
            byte count = 1;
            for (int i = 0; i < hand.Cards.Count; i++)
            {
                for (int j = i+1; j < hand.Cards.Count; j++)
                {
                    if (hand.Cards[i].Face == hand.Cards[j].Face)
                    {
                        count++;
                    }
                }
                if (count == 4)
                {
                    break;
                }
                count = 0;
            }

            bool isFourCardsFromTheSameKind = false;
            if (isHandValid == true && count == 4)
            {
                isFourCardsFromTheSameKind = true;
            }

            return isFourCardsFromTheSameKind;
        }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:28,代码来源:PokerHandsChecker.cs

示例11: IsHand

        public bool IsHand(IHand hand)
        {
            var threeOfAKind = false;
            var pair = false;

            for (var i = Value.Two; i <= Value.Ace; i++)
            {
                IEnumerable<Card> cardsOfSameValue = hand.GetCards().Where(obj => obj.GetCardValue() == i);

                if (cardsOfSameValue.Count() > 2 && !threeOfAKind)
                {
                    threeOfAKind = true;

                }
                else if (cardsOfSameValue.Count() > 1 && !pair)
                {
                    pair = true;

                }
                if (threeOfAKind && pair)
                {
                    hand.SetRank(Rank.FullHouse);
                    return true;
                }
            }
            return false;
        }
开发者ID:rHarris213,项目名称:PokerGame,代码行数:27,代码来源:FullHouseAnalyser.cs

示例12: IsFlush

        public bool IsFlush(IHand hand)
        {
            if (!IsValidHand(hand))
            {
                return false;
            }

            if (hand.Cards.Count != 5)
            {
                return false;
            }

            for (int i = 0; i < 5; i++)
            {
                if (hand.ToString().IndexOf(hand.Cards[i].ToString()) != hand.ToString().LastIndexOf(hand.Cards[i].ToString()))
                {
                    return false;
                }
            }
            CardSuit cardsSuit = hand.Cards[0].Suit;

            for (int j = 0; j < 5; j++)
            {
                if (hand.Cards[j].Suit != cardsSuit)
                {
                    return false;
                }
            }
            return true;
        }
开发者ID:Rostech,项目名称:TelerikAcademyHomeworks,代码行数:30,代码来源:PokerHandsChecker.cs

示例13: IsFourOfAKind

 public bool IsFourOfAKind(IHand hand)
 {
     int counter = 1;
     if (IsValidHand(hand))
     {
         for (int i = 0; i < 2; i++)
         {
             for (int j = i+1; j < 5; j++)
             {
                 if (hand.Cards[i].Face == hand.Cards[j].Face)
                 {
                     counter++;
                 }
                 if (counter == 4)
                 {
                     return true;
                 }
             }
         }
         return false;
     }
     else
     {
         throw new ArgumentException("Hand is invalid", "hand");
     }
 }
开发者ID:smghacker,项目名称:S-M-G,代码行数:26,代码来源:PokerHandsChecker.cs

示例14: IsHighCard

        public bool IsHighCard(IHand hand)
        {
            bool isValidHand = this.IsValidHand(hand);
            bool isHighCard = !this.IsFlush(hand) && !this.IsStraight(hand) && !this.IsStraightFlush(hand) && !this.IsFullHouse(hand) && !this.IsOnePair(hand) && !this.IsTwoPair(hand) && !this.IsThreeOfAKind(hand) && !this.IsFourOfAKind(hand);

            return isValidHand && isHighCard;
        }
开发者ID:AYankova,项目名称:HQC,代码行数:7,代码来源:PokerHandsChecker.cs

示例15: IsFourOfAKind

        public bool IsFourOfAKind(IHand hand)
        {
            if (!IsValidHand(hand))
            {
                return false;
            }

            int faceCounter = 1;
            int maxCounter = 0;
            String[] splitedHand = hand.ToString().Split(' ');

            for (int i = 0, len = splitedHand.Length; i < len; i++)
            {
                for (int j = i + 1; j < len; j++)
                {
                    if (splitedHand[i][0] == splitedHand[j][0])
                    {
                        faceCounter++;
                    }
                }

                if (faceCounter > maxCounter)
                {
                    maxCounter = faceCounter;
                    faceCounter = 1;
                }
            }

            if (maxCounter == 4)
                return true;
            else
                return false;
        }
开发者ID:Bvaptsarov,项目名称:Homework,代码行数:33,代码来源:PokerHandsChecker.cs


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