/// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compute outs to reach the combination.
        /// </summary>
        /// <returns>Outs to reach the combination.</returns>
        protected override int ComputeOuts()
        {
            int result = 0;

            if (SeenCards.Count >= 4)
            {
                List <byte>             missingWeights = new List <byte>();
                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 >= 4)
                {
                    for (byte i = 0; i < CardSet.CardsPerFamilyCount; i++)
                    {
                        if (!sortedCards.ContainsKey(i))
                        {
                            // Try to add one by one missing weight
                            List <Card> temp = new List <Card>(sortedCards.Values);
                            temp.Add(new Card(i, CardFamilies.Clubs));
                            StraightCombination straight = new StraightCombination();
                            straight.Compute(temp, true);
                            if (straight.Reached)
                            {
                                // Adding this weight allow to reach the combination, remember this weight
                                missingWeights.Add(i);
                            }
                        }
                    }
                    if (missingWeights.Count > 0)
                    {
                        foreach (byte missingWeight in missingWeights)
                        {
                            // For each remembered weights, compute outs
                            result += 4;
                            foreach (Card card in SeenCards)
                            {
                                if (card.Weight == missingWeight)
                                {
                                    // Card is part of seen cards, can not be an out
                                    result--;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }