public override void reroll(DieSet dieSet, int rerollsLeft, ScoreSheet scoreSheet)
        {
            calcFinalDice(scoreSheet);
            rerollOptions = new Hashtable();
            calcReroll(2, finalDice);
            diceOptionsScores = new Hashtable();
            diceOptionsReroll = new Hashtable();
            calcDiceOptions(2, (Hashtable)rerollOptions[2]);

            string dice = "";
            foreach (Die die in dieSet.Dice)
                dice += die.Value.ToString();
            dice = resortDice(dice);
            string rerollChoice;

            if (rerollsLeft == 2)
            {
                calcReroll(1, (Hashtable)diceOptionsScores[2]);
                calcDiceOptions(1, (Hashtable)rerollOptions[1]);
                rerollChoice = (String)((Hashtable)diceOptionsReroll[1])[dice];
            }
            else
                rerollChoice = (String)((Hashtable)diceOptionsReroll[2])[dice];

            int[] count = convertToCount(rerollChoice);
            freezeDice(dieSet, count);
        }
 public void testGetLowerScore()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     scoreSheet.Score("Aces", new DieSet(1, 1, 1, 1, 6));
     Assert.AreEqual(0, scoreSheet.getLowerScore());
     scoreSheet.Score("Chance", new DieSet(1, 1, 1, 1, 6));
     Assert.AreEqual(10, scoreSheet.getLowerScore());
     scoreSheet.Score("Twos", new DieSet(2, 2, 3, 4, 5));
     Assert.AreEqual(10, scoreSheet.getLowerScore());
     scoreSheet.Score("Three of a Kind", new DieSet(1, 1, 1, 6, 6));
     Assert.AreEqual(25, scoreSheet.getLowerScore());
     scoreSheet.Score("Threes", new DieSet(3, 3, 3, 3, 4));
     Assert.AreEqual(25, scoreSheet.getLowerScore());
     scoreSheet.Score("Four of a Kind", new DieSet(1, 1, 1, 1, 6));
     Assert.AreEqual(35, scoreSheet.getLowerScore());
     scoreSheet.Score("Fours", new DieSet(4, 4, 4, 6, 1));
     Assert.AreEqual(35, scoreSheet.getLowerScore());
     scoreSheet.Score("Full House", new DieSet(1, 1, 1, 3, 3));
     Assert.AreEqual(60, scoreSheet.getLowerScore());
     scoreSheet.Score("Fives", new DieSet(5, 5, 2, 4, 5));
     Assert.AreEqual(60, scoreSheet.getLowerScore());
     scoreSheet.Score("Small Straight", new DieSet(1, 2, 3, 4, 5));
     Assert.AreEqual(90, scoreSheet.getLowerScore());
     scoreSheet.Score("Sixes", new DieSet(6, 6, 1, 3, 6));
     Assert.AreEqual(90, scoreSheet.getLowerScore());
     scoreSheet.Score("Yahtzee", new DieSet(4, 4, 4, 4, 4));
     Assert.AreEqual(140, scoreSheet.getLowerScore());
     scoreSheet.Score("Large Straight", new DieSet(1, 2, 3, 4, 5));
     Assert.AreEqual(180, scoreSheet.getLowerScore());
 }
Beispiel #3
0
 public Player(string name)
 {
     this.Name = name;
     IsActive = false;
     ScoreSheet = new ScoreSheet();
     ScoreSheet.setupGame("Yahtzee");
 }
 public void testAlreadyBeenScored()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     scoreSheet.Score("Aces", new DieSet(1, 1, 1, 1, 1));
     scoreSheet.Score("Aces", new DieSet(1, 1, 1, 1, 1));
 }
Beispiel #5
0
 public Player(string name, PlayerStrategy strategy)
 {
     this.Strategy = strategy;
     this.Name = name;
     IsActive = false;
     ScoreSheet = new ScoreSheet();
     ScoreSheet.setupGame("Yahtzee");
     this.StrategyDescription = strategy.ToString();
 }
        protected override string getBest(DieSet dieSet, ScoreSheet scoreSheet)
        {
            string maxCat = "";
            double maxScore = -1;
            int scoreForCat = 0;
            string[] tokens;
            string cat;
            int score;
            int myState = convertScoredToKey(scoreSheet.GetScored());
            int upperScore = scoreSheet.getUpperScore();
            int newUpperScore;
            int newState;
            double futureExp;

            Hashtable tableToUse;
            if (scoreSheet.isYahtzeeScored() & scoreSheet.getYahtzeeScore() > 0)
                tableToUse = allStatesWithYahtzee;
            else
                tableToUse = allStatesNoYahtzee;

            Hashtable tempTableToUse;

            List<String> avail = scoreSheet.GetAvailable(dieSet);

            foreach (string str in avail)
            {
                tokens = str.Split(':');
                cat = tokens[0];
                score = Int32.Parse(tokens[1]);

                if (cat == "Yahtzee" & score > 0)
                    tempTableToUse = allStatesWithYahtzee;
                else
                    tempTableToUse = tableToUse;

                newState = myState + (int)catConversion[cat];
                newUpperScore = upperScore;
                if (scoreSheet.isUpper(cat))
                    newUpperScore += score;

                newUpperScore = Math.Min(63, newUpperScore);

                if (scoreSheet.getYahtzeeScore() > 0 & scoreSheet.isYahtzee(dieSet.getCount()))
                    score += 100;

                futureExp = (double)((Hashtable)tempTableToUse[newUpperScore])[newState];
                if (futureExp + score > maxScore)
                {
                    maxScore = futureExp + score;
                    maxCat = cat;
                    scoreForCat = score;
                }
            }

            return maxCat+":"+scoreForCat.ToString()+":"+maxScore;
        }
        public void testGREEDY2()
        {
            GreedyAIStrategy greedy = new GreedyAIStrategy();
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yahtzee");

            DieSet dieSet = new DieSet(6, 6, 6, 6, 6);
            string cat = greedy.chooseCategory(dieSet, scoreSheet);
            Assert.AreEqual("Yahtzee", cat);
            scoreSheet.Score(cat, dieSet);
            Assert.AreEqual(50, scoreSheet.CurrentScore());
        }
 public string chooseCategory(DieSet dieSet, ScoreSheet scoreSheet)
 {
     Console.WriteLine("Your dice are:");
     for (int i = 0; i < dieSet.Dice.Count; i++)
     {
         Console.WriteLine("Die " + i + ": " + dieSet.Dice[i].Value);
     }
     Console.WriteLine("Here's how these dice score:");
     List<String> avail = scoreSheet.GetAvailable(dieSet);
     for (int i = 0; i < avail.Count; i++)
     {
         Console.WriteLine(avail[i]);
     }
     Console.Write("What category would you like to score against?");
     return Console.ReadLine();
 }
 public void testBonus()
 {
     // bonus of 35 points if 63 points are scored in the upper categories (corresponds to 3 each of the numbers)
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     Assert.IsTrue(scoreSheet.Bonus == 0);
     scoreSheet.Score("Aces", new DieSet(1, 1, 1, 2, 3));
     Assert.IsTrue(scoreSheet.Bonus == 0);
     scoreSheet.Score("Twos", new DieSet(2, 2, 2, 3, 4));
     Assert.IsTrue(scoreSheet.Bonus == 0);
     scoreSheet.Score("Threes", new DieSet(3, 3, 3, 4, 5));
     Assert.IsTrue(scoreSheet.Bonus == 0);
     scoreSheet.Score("Fours", new DieSet(4, 4, 4, 5, 6));
     Assert.IsTrue(scoreSheet.Bonus == 0);
     scoreSheet.Score("Fives", new DieSet(5, 5, 5, 6, 1));
     Assert.IsTrue(scoreSheet.Bonus == 0);
     scoreSheet.Score("Sixes", new DieSet(6, 6, 6, 1, 2));
     Assert.IsTrue(scoreSheet.Bonus == 35);
     Assert.IsTrue(scoreSheet.CurrentScore() == 98);
 }
        public void reroll(DieSet dieSet, int rerollsLeft, ScoreSheet scoreSheet)
        {
            Console.WriteLine("Your dice are:");
            for (int i = 0; i < dieSet.Dice.Count; i++)
            {
                Console.WriteLine("Die " + i + ": " + dieSet.Dice[i].Value);
            }
            Console.WriteLine("Here's how these dice score:");
            List<String> avail = scoreSheet.GetAvailable(dieSet);
            for (int i = 0; i < avail.Count; i++)
            {
                Console.WriteLine(avail[i]);
            }
            Console.Write("What dice would you like to reroll?  Please enter die number seperated by a space.  I.e., if you want to reroll dice 2 and 5, enter '2 5'.");
            String rerollDice = Console.ReadLine();

            for (int i = 0; i < dieSet.Dice.Count; i++)
            {
                if (!rerollDice.Contains(i.ToString()))
                    dieSet.Dice[i].Freeze();
            }
        }
        public void testGREEDY4()
        {
            // GREEDY2
            GreedyAIStrategy greedy = new GreedyAIStrategy();
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yahtzee");

            DieSet dieSet = new DieSet(6, 6, 6, 6, 6);
            string cat = greedy.chooseCategory(dieSet, scoreSheet);
            scoreSheet.Score(cat, dieSet);

            // GREEDY3
            dieSet = new DieSet(2, 2, 2, 2, 4);
            cat = greedy.chooseCategory(dieSet, scoreSheet);
            scoreSheet.Score(cat, dieSet);

            // GREEDY4
            dieSet = new DieSet(6, 6, 6, 6, 5);
            cat = greedy.chooseCategory(dieSet, scoreSheet);
            Assert.AreEqual("Sixes", cat);
            scoreSheet.Score(cat, dieSet);
            Assert.AreEqual(82, scoreSheet.CurrentScore());
        }
        public override void reroll(DieSet dieSet, int rerollsLeft, ScoreSheet scoreSheet)
        {
            int[] count = dieSet.getCount();

            allScores = new Hashtable();
            keptDice = new Hashtable();
            allOptions = new Hashtable();
            calcAllOptions(scoreSheet, new List<int>(count), new List<int>());

            double bestScore = chooseScore(dieSet, scoreSheet);
            string bestCount = convertCountToString(count);
            ICollection keys = allOptions.Keys;
            foreach (Object key in keys)
            {
                if ((double)allOptions[key] > bestScore)
                {
                    bestScore = (double)allOptions[key];
                    bestCount = key.ToString();
                }
            }

            freezeDice(dieSet, convertStringToCount(bestCount));
        }
 public void testJokerRulesLowerCats()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     scoreSheet.Score("Yahtzee", new DieSet(6, 6, 6, 6, 6));
     Assert.IsTrue(scoreSheet.CurrentScore() == 50);
     scoreSheet.Score("Sixes", new DieSet(6, 1, 1, 1, 1));
     Assert.IsTrue(scoreSheet.CurrentScore() == 56);
     List<String> avail = scoreSheet.GetAvailable(new DieSet(6, 6, 6, 6, 6));
     Assert.IsTrue(avail.Count == 6);
     Assert.Contains("Three of a Kind:30", avail);
     Assert.Contains("Four of a Kind:30", avail);
     Assert.Contains("Full House:25", avail);
     Assert.Contains("Small Straight:30", avail);
     Assert.Contains("Large Straight:40", avail);
     Assert.Contains("Chance:30", avail);
     scoreSheet.Score("Large Straight", new DieSet(6, 6, 6, 6, 6));
     Assert.AreEqual(196, scoreSheet.CurrentScore());
 }
        public void testRulesBonus()
        {
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yatzy");
            List<String> rules = scoreSheet.getRules();

            Assert.AreEqual("If you score at least 63 points in the upper categories, you gain a bonus 50 points.", rules[19]);
        }
 public void testJokerRulesNoLowerAvail()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     scoreSheet.Score("Yahtzee", new DieSet(6, 6, 6, 6, 6));
     Assert.IsTrue(scoreSheet.CurrentScore() == 50);
     scoreSheet.Score("Sixes", new DieSet(6, 1, 1, 1, 1));
     Assert.IsTrue(scoreSheet.CurrentScore() == 56);
     scoreSheet.Score("Three of a Kind", new DieSet(1, 1, 1, 4, 5));
     Assert.IsTrue(scoreSheet.CurrentScore() == 68);
     scoreSheet.Score("Four of a Kind", new DieSet(2, 2, 2, 2, 6));
     Assert.AreEqual(82, scoreSheet.CurrentScore());
     scoreSheet.Score("Full House", new DieSet(1, 1, 1, 2, 2));
     Assert.AreEqual(107, scoreSheet.CurrentScore());
     scoreSheet.Score("Small Straight", new DieSet(1, 2, 3, 4, 6));
     Assert.AreEqual(137, scoreSheet.CurrentScore());
     scoreSheet.Score("Large Straight", new DieSet(1, 2, 3, 4, 5));
     Assert.AreEqual(177, scoreSheet.CurrentScore());
     scoreSheet.Score("Chance", new DieSet(5, 5, 5, 2, 3));
     Assert.AreEqual(197, scoreSheet.CurrentScore());
     List<String> avail = scoreSheet.GetAvailable(new DieSet(6, 6, 6, 6, 6));
     Assert.IsTrue(avail.Count == 5);
     Assert.Contains("Aces:0", avail);
     Assert.Contains("Twos:0", avail);
     Assert.Contains("Threes:0", avail);
     Assert.Contains("Fours:0", avail);
     Assert.Contains("Fives:0", avail);
     scoreSheet.Score("Aces", new DieSet(6, 6, 6, 6, 6));
     Assert.AreEqual(297, scoreSheet.CurrentScore());
 }
 public void testScoreSheetPrintCategories()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     List<ScoringCategory> cats = scoreSheet.printScoreSheet();
     Assert.AreEqual("Aces", cats[0].Name);
     Assert.AreEqual("Twos", cats[1].Name);
     Assert.AreEqual("Threes", cats[2].Name);
     Assert.AreEqual("Fours", cats[3].Name);
     Assert.AreEqual("Fives", cats[4].Name);
     Assert.AreEqual("Sixes", cats[5].Name);
     Assert.AreEqual("Upper Total", cats[6].Name);
     Assert.AreEqual("Upper Bonus", cats[7].Name);
     Assert.AreEqual("Three of a Kind", cats[8].Name);
     Assert.AreEqual("Four of a Kind", cats[9].Name);
     Assert.AreEqual("Full House", cats[10].Name);
     Assert.AreEqual("Small Straight", cats[11].Name);
     Assert.AreEqual("Large Straight", cats[12].Name);
     Assert.AreEqual("Yahtzee", cats[13].Name);
     Assert.AreEqual("Chance", cats[14].Name);
     Assert.AreEqual("Lower Total", cats[15].Name);
     Assert.AreEqual("Bonus Yahtzee Total", cats[16].Name);
     Assert.AreEqual("Total", cats[17].Name);
 }
 public void testBadSetup()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Bad Setup");
 }
 public void testSetupYatzy()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     //scoreSheet.SetupYatzy();
     scoreSheet.setupGame("Yatzy");
     // confirm 0 score
     Assert.IsTrue(scoreSheet.CurrentScore() == 0);
     // confirm nothing is scored
     List<String> scored = scoreSheet.GetScored();
     Assert.IsEmpty(scored);
     // confirm what is available
     List<String> available = scoreSheet.GetAvailable();
     Assert.Contains("Ones", available);
     Assert.Contains("Twos", available);
     Assert.Contains("Threes", available);
     Assert.Contains("Fours", available);
     Assert.Contains("Fives", available);
     Assert.Contains("Sixes", available);
     Assert.Contains("One Pair", available);
     Assert.Contains("Two Pairs", available);
     Assert.Contains("Three of a Kind", available);
     Assert.Contains("Four of a Kind", available);
     Assert.Contains("Full House", available);
     Assert.Contains("Small Straight", available);
     Assert.Contains("Large Straight", available);
     Assert.Contains("Yahtzee", available);
     Assert.Contains("Chance", available);
     Assert.IsTrue(available.Count == 15);
     // confirm available + score
     available = scoreSheet.GetAvailable(new DieSet(1, 2, 3, 4, 5));
     Assert.Contains("Ones:1", available);
     Assert.Contains("Twos:2", available);
     Assert.Contains("Threes:3", available);
     Assert.Contains("Fours:4", available);
     Assert.Contains("Fives:5", available);
     Assert.Contains("Sixes:0", available);
     Assert.Contains("One Pair:0", available);
     Assert.Contains("Two Pairs:0", available);
     Assert.Contains("Three of a Kind:0", available);
     Assert.Contains("Four of a Kind:0", available);
     Assert.Contains("Full House:0", available);
     Assert.Contains("Small Straight:30", available);
     Assert.Contains("Large Straight:40", available);
     Assert.Contains("Yahtzee:0", available);
     Assert.Contains("Chance:15", available);
     Assert.IsTrue(available.Count == 15);
 }
 public void testJokerRulesForceNumberCat()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     scoreSheet.Score("Yahtzee", new DieSet(6, 6, 6, 6, 6));
     List<String> avail = scoreSheet.GetAvailable(new DieSet(6, 6, 6, 6, 6));
     Assert.IsTrue(avail.Count == 1);
     Assert.Contains("Sixes:30", avail);
 }
        public void testRulesNoRules()
        {
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yacht");
            List<String> rules = scoreSheet.getRules();

            foreach (string str in rules)
            {
                Assert.AreNotEqual("If you score at least 63 points in the upper categories, you gain a bonus 35 points.", str);
                Assert.AreNotEqual("For each additional Yahtzee you roll with a non-zero score in the Yahtzee category, you gain an additional 100 points.", str);
                Assert.AreNotEqual("If you roll a Yahtzee but the Yahztzee category is already scored, then Joker Rules go into effect.  If you can get a nonzero score in an upper category, you must score there.  Otherwise, you must score in a lower category.  The normal scoring restrictions do not apply.  If all lower categories are filled, you must take a 0 in an upper category.", str);
            }
        }
 public void testSetupTwice()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yacht");
     scoreSheet.setupGame("Yahtzee");
     Assert.AreEqual(13, scoreSheet.ScoringCategories.Count);
 }
        public void testRulesStandard()
        {
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yahtzee");
            List<String> rules = scoreSheet.getRules();

            Assert.AreEqual("Welcome to Yahtzee!  Here are the scoring rules for you game.", rules[0]);
            Assert.AreEqual("", rules[1]);
            Assert.AreEqual("How to each category scores:", rules[2]);
            Assert.AreEqual("Aces: Scores the sum of all dice showing 1.", rules[3]);
            Assert.AreEqual("Twos: Scores the sum of all dice showing 2.", rules[4]);
            Assert.AreEqual("Threes: Scores the sum of all dice showing 3.", rules[5]);
            Assert.AreEqual("Fours: Scores the sum of all dice showing 4.", rules[6]);
            Assert.AreEqual("Fives: Scores the sum of all dice showing 5.", rules[7]);
            Assert.AreEqual("Sixes: Scores the sum of all dice showing 6.", rules[8]);
            Assert.AreEqual("Three of a Kind: If there are three matching dice, score the total of all dice.  Otherwise, score 0.", rules[9]);
            Assert.AreEqual("Four of a Kind: If there are four matching dice, score the total of all dice.  Otherwise, score 0.", rules[10]);
            Assert.AreEqual("Full House: If there are three of one value and two of a different value, score 25.  Otherwise, score 0.", rules[11]);
            Assert.AreEqual("Small Straight: If the dice show four consecutive values, score 30.  Otherwise, score 0.", rules[12]);
            Assert.AreEqual("Large Straight: If the dice show five consecutive numbers, score 40.  Otherwise, score 0.", rules[13]);
            Assert.AreEqual("Yahtzee: If all dice show the same value, score 50.  Otherwise, score 0.", rules[14]);
            Assert.AreEqual("Chance: Score total of all dice.", rules[15]);
            Assert.AreEqual("", rules[16]);
            Assert.AreEqual("If you score at least 63 points in the upper categories, you gain a bonus 35 points.", rules[17]);
            Assert.AreEqual("", rules[18]);
            Assert.AreEqual("For each additional Yahtzee you roll with a non-zero score in the Yahtzee category, you gain an additional 100 points.", rules[19]);
            Assert.AreEqual("", rules[20]);
            Assert.AreEqual("If you roll a Yahtzee but the Yahztzee category is already scored, then Joker Rules go into effect.  If you can get a nonzero score in an upper category, you must score there.  Otherwise, you must score in a lower category.  The normal scoring restrictions do not apply.  If all lower categories are filled, you must take a 0 in an upper category.", rules[21]);
        }
        public void testScoreSheetPrintTotals()
        {
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yahtzee");
            List<ScoringCategory> cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(0, cats[6].FinalScore);
            Assert.AreEqual(0, cats[7].FinalScore);
            Assert.AreEqual(0, cats[15].FinalScore);
            Assert.AreEqual(0, cats[16].FinalScore);
            Assert.AreEqual(0, cats[17].FinalScore);

            scoreSheet.Score("Sixes", new DieSet(6, 6, 6, 6, 5));
            cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(24, cats[6].FinalScore);
            Assert.AreEqual(0, cats[7].FinalScore);
            Assert.AreEqual(0, cats[15].FinalScore);
            Assert.AreEqual(0, cats[16].FinalScore);
            Assert.AreEqual(24, cats[17].FinalScore);

            scoreSheet.Score("Fives", new DieSet(5, 5, 5, 5, 6));
            cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(44, cats[6].FinalScore);
            Assert.AreEqual(0, cats[7].FinalScore);
            Assert.AreEqual(0, cats[15].FinalScore);
            Assert.AreEqual(0, cats[16].FinalScore);
            Assert.AreEqual(44, cats[17].FinalScore);

            scoreSheet.Score("Fours", new DieSet(4, 4, 4, 4, 6));
            cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(60, cats[6].FinalScore);
            Assert.AreEqual(0, cats[7].FinalScore);
            Assert.AreEqual(0, cats[15].FinalScore);
            Assert.AreEqual(0, cats[16].FinalScore);
            Assert.AreEqual(60, cats[17].FinalScore);

            scoreSheet.Score("Threes", new DieSet(3, 3, 3, 3, 6));
            cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(72, cats[6].FinalScore);
            Assert.AreEqual(35, cats[7].FinalScore);
            Assert.AreEqual(0, cats[15].FinalScore);
            Assert.AreEqual(0, cats[16].FinalScore);
            Assert.AreEqual(107, cats[17].FinalScore);

            scoreSheet.Score("Yahtzee", new DieSet(1, 1, 1, 1, 1));
            cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(72, cats[6].FinalScore);
            Assert.AreEqual(35, cats[7].FinalScore);
            Assert.AreEqual(50, cats[15].FinalScore);
            Assert.AreEqual(0, cats[16].FinalScore);
            Assert.AreEqual(157, cats[17].FinalScore);

            scoreSheet.Score("Large Straight", new DieSet(6, 6, 6, 6, 6));
            cats = scoreSheet.printScoreSheet();
            Assert.AreEqual(72, cats[6].FinalScore);
            Assert.AreEqual(35, cats[7].FinalScore);
            Assert.AreEqual(90, cats[15].FinalScore);
            Assert.AreEqual(100, cats[16].FinalScore);
            Assert.AreEqual(297, cats[17].FinalScore);
        }
 public void testScoreSheetPrintNoTotals()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yacht");
     List<ScoringCategory> cats = scoreSheet.printScoreSheet();
     foreach (ScoringCategory cat in cats)
     {
         Assert.AreNotEqual("Upper Bonus", cat.Name);
         Assert.AreNotEqual("Bonus Yahtzee Total", cat.Name);
     }
 }
        protected override string getBest(DieSet dieSet, ScoreSheet scoreSheet)
        {
            List<String> available = scoreSheet.GetAvailable(dieSet);
            string bestChoice = "";
            int bestScore = -1;
            int bonus = 0;
            int myscore = 0;
            int max;
            string[] tokens;

            // go through all available scoring categories and choose the one with the highest score for these dice
            if (available.Count == 0) throw new YahtzeeException("No Available Categories.");

            // if it's a yahtzee, special rules
            if (scoreSheet.isYahtzee(dieSet.getCount()))
            {
                if (!scoreSheet.isYahtzeeScored())
                {
                    return "Yahtzee:" + maxScores["Yahtzee"].ToString();
                }
                else if (scoreSheet.getYahtzeeScore() > 0)
                {
                    // get the best one that's available
                    for (int i = 0; i < available.Count; i++)
                    {
                        tokens = available[i].Split(':');
                        myscore = Int32.Parse(tokens[1]);
                        if (myscore > bestScore)
                        {
                            bestScore = myscore;
                            bestChoice = available[i];
                        }
                        else if (myscore == bestScore & tokens[0] != "Chance" & bestScore > 0)
                        {
                            bestScore = myscore;
                            bestChoice = available[i];
                        }
                    }
                    return bestChoice;
                }
            }
            // if this is a full house, score the full house rather than the upper categories
            if (available.Contains("Full House:" + maxScores["Full House"].ToString()))
            {
                return "Full House:" + maxScores["Full House"].ToString();
            }

            foreach (ScoringCategory cat in scoreSheet.ScoringCategories)
            {
                if (!cat.HasBeenUsed)
                {
                    if (cat.Upper)
                    {
                        myscore = cat.CalculateScoreForRoll(dieSet.getCount());
                        max = (int)maxScores[cat.Name];
                        bonus = 0;
                        if ((double)myscore / (double)max >= 0.60)
                        {
                            if (scoreSheet.Bonus == 0)
                                bonus = 13;
                        }
                        myscore += bonus;
                    }
                    else
                    {
                        myscore = cat.CalculateScoreForRoll(dieSet.getCount());
                    }

                    if (myscore > bestScore)
                    {
                        bestScore = myscore;
                        bestChoice = cat.Name;
                    }
                    else if (myscore == bestScore & cat.Name != "Chance" & bestScore > 0)
                    {
                        bestScore = myscore;
                        bestChoice = cat.Name;
                    }
                }

            }
            return bestChoice + ":" + bestScore.ToString();
        }
 public void testGetScore()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     Assert.AreEqual(0, scoreSheet.getScore("Aces"));
     scoreSheet.Score("Aces", new DieSet(1, 1, 1, 1, 1));
     Assert.AreEqual(5, scoreSheet.getScore("Aces"));
 }
 public void testNoAvailCats()
 {
     GreedyAIStrategy greedy = new GreedyAIStrategy();
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     scoreSheet.Score("Aces", new DieSet(1, 1, 1, 1, 2));
     scoreSheet.Score("Twos", new DieSet(2, 2, 2, 2, 3));
     scoreSheet.Score("Threes", new DieSet(3, 3, 3, 3, 4));
     scoreSheet.Score("Fours", new DieSet(4, 4, 4, 4, 5));
     scoreSheet.Score("Fives", new DieSet(5, 5, 5, 5, 6));
     scoreSheet.Score("Sixes", new DieSet(6, 6, 6, 6, 1));
     scoreSheet.Score("Three of a Kind", new DieSet(6, 6, 6, 5, 4));
     scoreSheet.Score("Four of a Kind", new DieSet(5, 6, 6, 6, 6));
     scoreSheet.Score("Full House", new DieSet(1, 1, 1, 2, 2));
     scoreSheet.Score("Small Straight", new DieSet(1, 2, 3, 4, 6));
     scoreSheet.Score("Large Straight", new DieSet(1, 2, 3, 4, 5));
     scoreSheet.Score("Yahtzee", new DieSet(1, 1, 1, 1, 1));
     scoreSheet.Score("Chance", new DieSet(6, 6, 5, 5, 4));
     greedy.chooseCategory(new DieSet(1, 2, 2, 3, 4), scoreSheet);
 }
 private void calcFinalDice(ScoreSheet scoreSheet)
 {
     finalDice = new Hashtable();
     double score;
     string[] tokens;
     foreach (string str in allDice)
     {
         tokens = getBest(getDieSet(str), scoreSheet).Split(':');
         score = Double.Parse(tokens[2]);
         finalDice.Add(str, score);
     }
 }
 public void testSecondYahtzeeNoBonus()
 {
     ScoreSheet scoreSheet = new ScoreSheet();
     scoreSheet.setupGame("Yahtzee");
     Assert.IsTrue(scoreSheet.ExtraYahtzees == 0);
     scoreSheet.Score("Yahtzee", new DieSet(6, 6, 6, 6, 5));
     Assert.IsTrue(scoreSheet.ExtraYahtzees == 0);
     Assert.IsTrue(scoreSheet.CurrentScore() == 00);
     scoreSheet.Score("Sixes", new DieSet(6, 6, 6, 6, 6));
     Assert.IsTrue(scoreSheet.ExtraYahtzees == 0);
     Assert.IsTrue(scoreSheet.CurrentScore() == 30);
 }
        public void testScore()
        {
            ScoreSheet scoreSheet = new ScoreSheet();
            scoreSheet.setupGame("Yahtzee");
            int score;

            // score ones
            DieSet dieSet = new DieSet(1, 1, 1, 1, 1);
            score = scoreSheet.Score("Aces", dieSet);
            Assert.IsTrue(score == 5);
            Assert.IsTrue(scoreSheet.CurrentScore() == 5);
            // confirm Ones are scored
            List<String> scored = scoreSheet.GetScored();
            Assert.IsTrue(scored.Count == 1);
            Assert.Contains("Aces:5", scored);
            // confirm Ones are no longer available
            List<String> available = scoreSheet.GetAvailable();
            Assert.IsTrue(available.Count == 12);
            Assert.IsFalse(available.Contains("Aces"));

            // score twos
            dieSet = new DieSet(2, 2, 2, 2, 2);
            score = scoreSheet.Score("Twos", dieSet);
            Assert.IsTrue(score == 10);
            Assert.IsTrue(scoreSheet.CurrentScore() == 15);
            // confirm Ones, Twos are scored
            scored = scoreSheet.GetScored();
            Assert.IsTrue(scored.Count == 2);
            Assert.Contains("Aces:5", scored);
            Assert.Contains("Twos:10", scored);
            // confirm Ones, Twos are no longer available
            available = scoreSheet.GetAvailable();
            Assert.IsTrue(available.Count == 11);
            Assert.IsFalse(available.Contains("Aces"));
            Assert.IsFalse(available.Contains("Twos"));

            // score threes
            dieSet = new DieSet(3, 3, 3, 3, 3);
            score = scoreSheet.Score("Threes", dieSet);
            Assert.IsTrue(score == 15);
            Assert.IsTrue(scoreSheet.CurrentScore() == 30);
            // confirm Ones, Twos, Threes are scored
            scored = scoreSheet.GetScored();
            Assert.IsTrue(scored.Count == 3);
            Assert.Contains("Aces:5", scored);
            Assert.Contains("Twos:10", scored);
            Assert.Contains("Threes:15", scored);
            // confirm Ones, Twos, Thress are no longer available
            available = scoreSheet.GetAvailable();
            Assert.IsTrue(available.Count == 10);
            Assert.IsFalse(available.Contains("Aces"));
            Assert.IsFalse(available.Contains("Twos"));
            Assert.IsFalse(available.Contains("Threes"));
        }