/// <summary>
 /// Passes in the reference to the scoring method defined in the Scoring class to it's delegate and adds it to
 /// a list of delegates.
 /// </summary>
 public static void PopulateScoringMethods()
 {
     numberOnes    = Scoring.NumberOnes;
     numberTwos    = Scoring.NumberTwos;
     numberThrees  = Scoring.NumberThrees;
     numberFours   = Scoring.NumberFours;
     numberFives   = Scoring.NumberFives;
     numberSixes   = Scoring.NumberSixes;
     threeOfAKind  = Scoring.ThreeOfAKind;
     fourOfAKind   = Scoring.FourOfAKind;
     fullHouse     = Scoring.FullHouse;
     smallStraight = Scoring.SmallStraight;
     largeStraight = Scoring.LargeStraight;
     yahtzee       = Scoring.Yahtzee;
     chance        = Scoring.Chance;
     ScoringFunctions.Add(numberOnes);
     ScoringFunctions.Add(numberTwos);
     ScoringFunctions.Add(numberThrees);
     ScoringFunctions.Add(numberFours);
     ScoringFunctions.Add(numberFives);
     ScoringFunctions.Add(numberSixes);
     ScoringFunctions.Add(threeOfAKind);
     ScoringFunctions.Add(fourOfAKind);
     ScoringFunctions.Add(fullHouse);
     ScoringFunctions.Add(smallStraight);
     ScoringFunctions.Add(largeStraight);
     ScoringFunctions.Add(yahtzee);
     ScoringFunctions.Add(chance);
 }
Esempio n. 2
0
        protected int CalculateScore(ScoringDelegate func, SP parameters)
        {
            mHelper.Prime();

            int totalScore = 0;

            int score = 0;

            score = GetCachedScore(func, parameters, mHelper.CachableScoring);
            if (score <= -1000)
            {
                return(score);
            }

            totalScore += score;

            score = PrivateScore(func, parameters, mHelper.NonCachableScoring, " NotCached");
            if (score <= -1000)
            {
                return(score);
            }

            totalScore += score;

            return(totalScore);
        }
        /// <summary>
        /// Conducts a recursive, pre-order search of the Binary Search Tree for the ScoringCategories enum passed in
        /// and retrieves the associated ScoringDelegate.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="currentNode"></param>
        /// <returns></returns>
        public static ScoringDelegate SearchScoringDelegates(ScoringCategories category, ScoreCategoryNode currentNode)
        {
            ScoreCategoryNode traversalNode;

            if (root == null)
            {
                throw new ArgumentException();
            }
            else
            {
                if ((int)currentNode.name == (int)category)
                {
                    calculationMethod = (ScoringDelegate)currentNode.method;
                }
                else if ((int)currentNode.name > (int)category)
                {
                    traversalNode = currentNode.left;
                    SearchScoringDelegates(category, traversalNode);
                }
                else if ((int)currentNode.name < (int)category)
                {
                    traversalNode = currentNode.right;
                    SearchScoringDelegates(category, traversalNode);
                }
            }
            return(calculationMethod);
        }
Esempio n. 4
0
        protected int PrivateScore(ScoringDelegate func, SP parameters, ICollection <IScoring <T, SP> > scoringList, string suffix)
        {
            int totalScore = 0;

            foreach (U scoring in scoringList)
            {
                int score = func(scoring, parameters);

                ScoringLookup.AddStat("Combined " + scoring.ToString() + suffix, score);

                if (score <= -1000)
                {
                    return(score);
                }

                totalScore += score;
            }

            return(totalScore);
        }
Esempio n. 5
0
 protected virtual int GetCachedScore(ScoringDelegate func, SP parameters, ICollection <IScoring <T, SP> > scoringList)
 {
     return(PrivateScore(func, parameters, scoringList, " Cached"));
 }