Beispiel #1
0
 public ScoreResult Eval(Dictionary <int, int> dieCounts)
 {
     if (dieCounts[_dieValue] >= _setSize)
     {
         var diceUsed = new Dictionary <int, int>();
         diceUsed.Add(_dieValue, _setSize);
         var scoreResult = new ScoreResult(_score, diceUsed);
         return(scoreResult);
     }
     return(new ScoreResult(0, new Dictionary <int, int>()));
 }
Beispiel #2
0
        public ScoreResult Eval(Dictionary <int, int> dieCounts)
        {
            int numberOfPairs = 0;

            var diceUsed = new Dictionary <int, int>();

            for (int i = 1; i <= 6; i++)
            {
                if (dieCounts[i] == 2)
                {
                    numberOfPairs++;
                    diceUsed.Add(i, 2);
                }
            }
            if (numberOfPairs == 3)
            {
                var scoreResult = new ScoreResult(_score, diceUsed);
                return(scoreResult);
            }

            return(new ScoreResult(0, new Dictionary <int, int>()));
        }
Beispiel #3
0
        public int CalculateScore(params int[] dieValues)
        {
            if (dieValues.Length > 6 || dieValues.Length < 1)
            {
                throw new System.Exception("You may only throw between 1 and 6 dice.");
            }
            var score = 0;

            PopulateDieCounts(dieValues);
            AddRules();

            while (_dieCounts.Any(x => x.Value > 0))
            {
                ScoreResult bestResult = new ScoreResult();
                foreach (var rule in _rules)
                {
                    ScoreResult scoreResult = rule.Eval(_dieCounts);
                    if (scoreResult.Score > bestResult.Score)
                    {
                        bestResult = scoreResult;
                    }
                }

                score += bestResult.Score;

                if (bestResult.DiceUsed == null)
                {
                    return(score);
                }

                foreach (var dieUsed in bestResult.DiceUsed)
                {
                    _dieCounts[dieUsed.Key] -= dieUsed.Value;
                }
            }

            return(score);
        }