Example #1
0
        private double EvaluateDiscards(int cards)
        {
            Debug.Assert(BitwiseCardHelper.GetCardCount(cards) == 12);

            var values = new List <double>();

            var enumerator = new TwoCardsEnumerator(cards);

            while (enumerator.MoveNext())
            {
                int    cardsAfterDiscarding = cards & ~enumerator.Current;
                double value = EvaluateCards(cardsAfterDiscarding, enumerator.Current);
                values.Add(value);
            }

            return(values.Max());
        }
        protected override double EvaluateCards(int cards, int discards)
        {
            Debug.Assert(BitwiseCardHelper.GetCardCount(cards) == 10);

            int trumpCount = BitwiseCardHelper.GetSuitCount(cards, mTrumpSuit);

            // Don't consider trump game if the number of trumps is less than 4.
            // TODO Consider 3-3-3-1.
            if (trumpCount < 4)
            {
                return(double.MinValue);
            }

            IEnumerable <TrickProbability> totalProbabilities = Enumerable.Empty <TrickProbability>();

            // Calculate sum of tricks with corresponding probabilities in all suits.
            for (var suit = CardSuit.Spades; suit <= CardSuit.Hearts; suit++)
            {
                int cardSet = BitwiseCardHelper.GetCardSet(cards, suit);
                IEnumerable <TrickProbability> probabilities = TrickPlayProbabilities.GetTrickProbabilities(cardSet);

                // Combine probabilities..
                totalProbabilities = totalProbabilities.Combine(probabilities);
            }

            bool isEasyLevel = (Game.Options.DifficultyLevel == GameDifficultyLevel.Beginner) ||
                               (Game.Options.DifficultyLevel == GameDifficultyLevel.Amateur);

            // The following stuff is too complex for weak players.
            if (!isEasyLevel)
            {
                totalProbabilities = ConsiderTrumpAdvancing(totalProbabilities);
                totalProbabilities = ConsiderTrickTaking(totalProbabilities);
            }

            return(totalProbabilities.Expectation(
                       tricks => Game.Rules.GetGameCost(
                           GameType.TrickPlay,
                           Game.Options.NumberOfPlayers,
                           DeclaredTricks,
                           tricks)));
        }
Example #3
0
        /// <summary>
        /// Calculates a mathematical expectation of the active hand for a certain game type.
        /// Uses the expecti-max algorithm to compute the value among all possible widow cards and further discards.
        /// Updates the <see cref="Expectation"/> property.
        /// </summary>
        /// <returns></returns>
        internal void Evaluate()
        {
            int ownCards     = BitwiseCardHelper.CardCollectionToBits(mGame.ActiveHand.Cards);
            int unknownCards = ~ownCards;

            Debug.Assert(BitwiseCardHelper.GetCardCount(unknownCards) == 22);

            var values = new List <double>();

            var enumerator = new TwoCardsEnumerator(unknownCards);

            while (enumerator.MoveNext())
            {
                int    ownCardsWithWidow = ownCards | enumerator.Current;
                double value             = EvaluateDiscards(ownCardsWithWidow);
                values.Add(value);
            }

            Expectation = values.Average();
        }
Example #4
0
 internal void RemoveCards(int cards)
 {
     mCards &= ~cards;
     mCount  = BitwiseCardHelper.GetCardCount(mCards);
 }
Example #5
0
 internal CardSet(int cards)
 {
     mCards = cards;
     mCount = BitwiseCardHelper.GetCardCount(cards);
 }