Esempio n. 1
0
        public Combination ImproveIfPossible(Card c1)
        {
            Combination buffer = new Combination(cards);

            for (int i = cards.Count - 1; i >= 0; i++)
            {
                if (cards[i] != c1)
                {
                    cards.Remove(cards[i]);
                    cards.Insert(i, c1);
                    break;
                }
            }
            this.CountCombination();
            if (Combination.Compare(this, buffer) < 0)
            {
                this.CleanCombination();
                this.InsertCard(buffer.GetCards());
            }
            return(this);
        }
Esempio n. 2
0
        public void TakeBestCards(List <Card> tablecards)
        {
            List <Card> allcards = new List <Card>(7);

            allcards.AddRange(tablecards);
            allcards.AddRange(hand);

            if (tablecards.Count > 3)
            {
                Combination buffer;

                if (allcards.Count == 6)
                {
                    buffer = new Combination();
                    for (int i = 0; i < 5; i++)
                    {
                        buffer.InsertCard(allcards[i]);
                    }
                    buffer = buffer.ImproveIfPossible(allcards[5]);
                    cards.CleanCombination();
                    cards.InsertCard(buffer.GetCards());
                    buffer = null;
                }
                else
                {
                    Combination strongest = new Combination(cards.GetCards());
                    int         j         = 1;
                    for (int i = 0; i < allcards.Count - 1; i++)
                    {
                        while (i + j < allcards.Count)
                        {
                            buffer = new Combination();
                            for (int k = 0; k < allcards.Count; k++)
                            {
                                if ((k != i) && (k != j))
                                {
                                    buffer.InsertCard(allcards[k]);
                                }
                            }
                            if (Combination.Compare(buffer, strongest) > 0)
                            {
                                strongest.CleanCombination();
                                strongest.InsertCard(buffer.GetCards());
                            }
                            buffer = null;
                            j++;
                        }
                    }
                    List <Card> leftcards = new List <Card>();
                    foreach (Card c in allcards)
                    {
                        if (!strongest.GetCards().Contains(c))
                        {
                            leftcards.Add(c);
                        }
                    }
                    strongest = strongest.ImproveIfPossible(leftcards[0]);
                    strongest = strongest.ImproveIfPossible(leftcards[1]);
                    cards.InsertCard(strongest.GetCards());
                }
            }
            else
            {
                List <Card> buffer = new List <Card>(5);
                buffer = cards.GetCards();
                for (int i = 0; i < allcards.Count; i++)
                {
                    if (!buffer.Contains(allcards[i]))
                    {
                        cards.InsertCard(allcards[i]);
                    }
                }
            }
        }