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; }
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 testGetYahtzeeScoredException() { ScoreSheet scoreSheet = new ScoreSheet(); scoreSheet.getYahtzeeScore(); }