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 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();
            }
        }
Esempio n. 3
0
        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();
        }
        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;
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        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"));
        }
Esempio n. 7
0
 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());
 }
Esempio n. 8
0
 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());
 }
Esempio n. 9
0
 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);
 }