Example #1
0
        protected int[] GetOptimalThrow(ThrowingStrategy strategy)
        {
            //This is the AI, automatically chooses which cards to throw away
            //DESCRIPTION:
            //THERE ARE TWO THINGS THE AI NEEDS TO CONSIDER:
            //1) Having the statistically best hand possible (given random cut-up card)
            //2) Giving the opponent the statistically best/worst cards possible (given 3 random cards)

            //What Optimal means depends on your strategy

            //This array will hold the best 4 indices to keep
            var best = new int[4];

            //Stores the best score so far to find max with
            double score = double.MinValue, bestScore = 0;

            //Looks at every possible throwing possible (there should be 15, since 6C4 is 15)
            foreach (var combo in HelperFunctions.GetKCombination(_size, FinalHandSize))
            {
                //Finds hand that best satisfies chosen strategy
                score = AnalyzeThrow(combo, strategy);
                {
                    //Better hand found, replace original
                    if (score > bestScore)
                    {
                        bestScore = score;
                        best      = combo;
                    }
                }
            }
            return(best);
        }
Example #2
0
        protected double AnalyzeCrib(int[] keep)
        {
            var deck = HandComplement;

            //value is the weighted average of all possible hands
            double value = 0.0;

            var fullCrib = new Card[FullHandSize];
            //Holds the 0-2 cards that the user has thrown away
            var thrownCards = GetRest(keep);

            //Generates first initial crib cards from keep array
            thrownCards.CopyTo(fullCrib, 0);

            //How many ways are there to finish the crib?
            //In other words, how many ways are there to choose 3 cards from a deck of 46?
            //In other words, a lot!
            var combos        = HelperFunctions.GetKCombination(deck.Count() - _size, FullHandSize - thrownCards.Count());
            int possibilities = combos.Count();

            foreach (var combo in combos)
            {
                //There are cases where the cutIndex is NOT needed (no Jacks, two different suits in hand)
                //For now we will ignore that, but it may be able to squeeze out a little performance
                for (int cutCard = thrownCards.Count(); cutCard < FullHandSize; cutCard++)
                {
                    //For each possible combo, finish the crib and evaluate
                    for (int i = 0; i < combo.Count(); i++)
                    {
                        fullCrib[i + thrownCards.Count()] = HandComplement[combo[i]];
                    }
                    value += ((Evaluation.EvaluateFullHand(fullCrib, cutCard) / (possibilities)));
                }
            }

            return(value);
        }