/// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 2)
            {
                foreach (Card card1 in SeenCards)
                {
                    foreach (Card card2 in SeenCards)
                    {
                        if (!card1.Equals(card2))
                        {
                            if (card1.Weight == card2.Weight)
                            {
                                // Pair reached
                                CombinationCards.Add(card1);
                                CombinationCards.Add(card2);
                                result = true;
                                break;
                            }
                        }
                    }
                    if (result)
                    {
                        break;
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 5)
            {
                FlushCombination flush = new FlushCombination();
                flush.Compute(SeenCards, true);
                if (flush.Reached)
                {
                    // A flush is found, check for a straight of the flush family
                    CardFamilies family = flush.CombinationCards[0].Family;
                    // Get all the card of the flush family
                    List <Card> seenCardsClone = new List <Card>();
                    foreach (Card card in SeenCards)
                    {
                        if (card.Family == family)
                        {
                            seenCardsClone.Add(card);
                        }
                    }
                    // Look for a straight in this sub set
                    StraightCombination straight = new StraightCombination();
                    straight.Compute(seenCardsClone, true);
                    if (straight.Reached)
                    {
                        // Straight flush found
                        CombinationCards.AddRange(straight.CombinationCards);
                        result = true;
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Сравнивает две руки с одинаковыми комбинациями. Сравнение происходит по
        /// самому большому достоинству
        /// </summary>
        /// <param name="otherHand">Рука с которой происходит сравнение</param>
        /// <returns>1, если эта рука больше сравниваемой. 0, если они имеют одинаковое значение.
        /// -1, если сравниваемая рука больше этой</returns>
        private int CompareSameCombination(PokerHand otherHand)
        {
            int valueMax     = CombinationCards.Max(i => i.Value);
            int otherHandMax = otherHand.CombinationCards.Max(i => i.Value);

            return(valueMax.CompareTo(otherHandMax));
        }
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 4)
            {
                List <Card>     seenCardsClone = new List <Card>(SeenCards);
                PairCombination pair1          = new PairCombination();
                pair1.Compute(seenCardsClone, true);
                if (pair1.Reached)
                {
                    // First pair found, look for a pair in remaining cards
                    // Remove first pair cards
                    foreach (Card card in pair1.CombinationCards)
                    {
                        CombinationCards.Add(card);
                        seenCardsClone.Remove(card);
                    }
                    PairCombination pair2 = new PairCombination();
                    pair2.Compute(seenCardsClone, true);
                    if (pair2.Reached)
                    {
                        // Two pairs reached
                        CombinationCards.AddRange(pair2.CombinationCards);
                        result = true;
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 5)
            {
                // List cards by families
                Dictionary <CardFamilies, List <Card> > cards = new Dictionary <CardFamilies, List <Card> >();
                foreach (Card card in SeenCards)
                {
                    if (!cards.ContainsKey(card.Family))
                    {
                        // First card of this family
                        cards.Add(card.Family, new List <Card>());
                    }
                    cards[card.Family].Add(card);
                }
                // Look for 5 or more cards of the same family
                foreach (CardFamilies cardFamily in cards.Keys)
                {
                    if (cards[cardFamily].Count >= 5)
                    {
                        // Flush reached
                        for (int i = 0; i < 5; i++)
                        {
                            // Get the 5 greater for the flush
                            CombinationCards.Add(cards[cardFamily][cards[cardFamily].Count - 1 - i]);
                        }
                        result = true;
                        break;
                    }
                }
            }
            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 5)
            {
                StraightFlushCombination straightFlush = new StraightFlushCombination();
                straightFlush.Compute(SeenCards, true);
                if (straightFlush.Reached)
                {
                    bool aceFound  = false;
                    bool kingFound = false;
                    // Straight flush reached, look for an ace and a king
                    foreach (Card card in straightFlush.CombinationCards)
                    {
                        if (card.Weight == 0)
                        {
                            aceFound = true;
                        }
                        else if (card.Weight == CardSet.CardsPerFamilyCount - 1)
                        {
                            kingFound = true;
                        }
                        if (aceFound && kingFound)
                        {
                            // Royal flush reached
                            CombinationCards.AddRange(straightFlush.CombinationCards);
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 5)
            {
                List <Card>         seenCardsClone = new List <Card>(SeenCards);
                TripletsCombination triplet        = new TripletsCombination();
                triplet.Compute(seenCardsClone, true);
                if (triplet.Reached)
                {
                    // Triplet found, look for a pair in remaining cards
                    // Remove triplet cards
                    foreach (Card card in triplet.CombinationCards)
                    {
                        CombinationCards.Add(card);
                        seenCardsClone.Remove(card);
                    }
                    PairCombination pair = new PairCombination();
                    pair.Compute(seenCardsClone, true);
                    if (pair.Reached)
                    {
                        // Full reached
                        CombinationCards.AddRange(pair.CombinationCards);
                        result = true;
                    }
                }
            }
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 5)
            {
                SortedList <byte, Card> sortedCards = new SortedList <byte, Card>();
                foreach (Card card in SeenCards)
                {
                    // Get the list of ordered weights
                    if (!sortedCards.ContainsKey(card.Weight))
                    {
                        sortedCards.Add(card.Weight, card);
                        if (card.Weight == 0)
                        {
                            // If card is an ace, consider it as the minimum and max weight
                            sortedCards.Add(CardSet.CardsPerFamilyCount, card);
                        }
                    }
                }
                if (sortedCards.Count >= 5)
                {
                    // Look for 5 following weights
                    int  followingWeight = 1;
                    byte previousWeight  = sortedCards.Keys[0];
                    for (int i = sortedCards.Keys.Count - 1; i >= 0; i--)
                    {
                        if (sortedCards.Keys[i] == previousWeight - 1)
                        {
                            followingWeight++;
                            if (followingWeight >= 5)
                            {
                                // Straight reached
                                for (int j = 0; j < 5; j++)
                                {
                                    // Get the 5 better weight
                                    CombinationCards.Add(sortedCards.Values[(byte)(i + j)]);
                                }
                                result = true;
                                break;
                            }
                        }
                        else
                        {
                            followingWeight = 1;
                        }
                        previousWeight = sortedCards.Keys[i];
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Check if the combination is reached.
        /// </summary>
        /// <returns><c>true</c> if combination is reached, <c>false</c> otherwise.</returns>
        protected override bool ComputeReached()
        {
            bool result = false;

            if (SeenCards != null && SeenCards.Count >= 4)
            {
                List <Card>            seenCardsClone = new List <Card>(SeenCards);
                DoublePairsCombination doublePairs    = new DoublePairsCombination();
                doublePairs.Compute(seenCardsClone, true);
                if (doublePairs.Reached)
                {
                    // Double pair found, check if it is a quads
                    if (doublePairs.CombinationCards[0].Weight == doublePairs.CombinationCards[2].Weight)
                    {
                        // Quads reached
                        CombinationCards.AddRange(doublePairs.CombinationCards);
                        result = true;
                    }
                    else
                    {
                        // Look for a possible third pair
                        foreach (Card card in doublePairs.CombinationCards)
                        {
                            seenCardsClone.Remove(card);
                        }
                        PairCombination pair = new PairCombination();
                        pair.Compute(seenCardsClone, true);
                        if (pair.Reached)
                        {
                            if (pair.CombinationCards[0].Weight == doublePairs.CombinationCards[0].Weight)
                            {
                                // Quads reached
                                CombinationCards.Add(doublePairs.CombinationCards[0]);
                                CombinationCards.Add(doublePairs.CombinationCards[1]);
                                CombinationCards.AddRange(pair.CombinationCards);
                                result = true;
                            }
                            else if (pair.CombinationCards[0].Weight == doublePairs.CombinationCards[2].Weight)
                            {
                                // Quads reached
                                CombinationCards.Add(doublePairs.CombinationCards[2]);
                                CombinationCards.Add(doublePairs.CombinationCards[3]);
                                CombinationCards.AddRange(pair.CombinationCards);
                                result = true;
                            }
                        }
                    }
                }
            }
            return(result);
        }