public static bool ValidateTypeFromRoll(Roll gameroll, ScoreType type) { if (gameroll == null) { return(false); } int[] roll = gameroll.ToArray(); switch (type) { default: case ScoreType.Aces: return(roll.Where(i => i == 1).Count() > 0); case ScoreType.Twos: return(roll.Where(i => i == 2).Count() > 0); case ScoreType.Threes: return(roll.Where(i => i == 3).Count() > 0); case ScoreType.Fours: return(roll.Where(i => i == 4).Count() > 0); case ScoreType.Fives: return(roll.Where(i => i == 5).Count() > 0); case ScoreType.Sixes: return(roll.Where(i => i == 6).Count() > 0); case ScoreType.ThreeOfAKind: Array.Sort(roll); return((roll[0] == roll[1] && roll[0] == roll[2]) || (roll[1] == roll[2] && roll[1] == roll[3]) || (roll[2] == roll[3] && roll[2] == roll[4])); case ScoreType.FourOfAKind: Array.Sort(roll); return((roll[0] == roll[1] && roll[0] == roll[2] && roll[0] == roll[3]) || (roll[1] == roll[2] && roll[1] == roll[3] && roll[1] == roll[4])); case ScoreType.FullHouse: Array.Sort(roll); return((roll[0] == roll[1] && roll[2] == roll[3] && roll[2] == roll[4]) || (roll[0] == roll[1] && roll[0] == roll[2] && roll[3] == roll[4])); case ScoreType.SmallStraight: return((gameroll.HasRolled(1) && gameroll.HasRolled(2) && gameroll.HasRolled(3) && gameroll.HasRolled(4)) || (gameroll.HasRolled(2) && gameroll.HasRolled(3) && gameroll.HasRolled(4) && gameroll.HasRolled(5)) || (gameroll.HasRolled(3) && gameroll.HasRolled(4) && gameroll.HasRolled(5) && gameroll.HasRolled(6))); case ScoreType.LargeStraight: return((gameroll.HasRolled(1) && gameroll.HasRolled(2) && gameroll.HasRolled(3) && gameroll.HasRolled(4) && gameroll.HasRolled(5)) || (gameroll.HasRolled(2) && gameroll.HasRolled(3) && gameroll.HasRolled(4) && gameroll.HasRolled(5) && gameroll.HasRolled(6))); case ScoreType.Yahtzee: return(roll[0] == roll[1] && roll[0] == roll[2] && roll[0] == roll[3] && roll[0] == roll[4]); case ScoreType.Chance: return(true); } }
public int CalculateScore(ScoreType type, Roll yRoll, bool joker = false) { if (!joker && !ValidateTypeFromRoll(yRoll, type)) { return(0); } int total = 0; int[] roll = yRoll.ToArray(); switch (type) { default: case ScoreType.Aces: ColUtility.ForEach(roll.Where(i => i == 1 || joker), i => total += i); break; case ScoreType.Twos: ColUtility.ForEach(roll.Where(i => i == 2 || joker), i => total += i); break; case ScoreType.Threes: ColUtility.ForEach(roll.Where(i => i == 3 || joker), i => total += i); break; case ScoreType.Fours: ColUtility.ForEach(roll.Where(i => i == 4 || joker), i => total += i); break; case ScoreType.Fives: ColUtility.ForEach(roll.Where(i => i == 5 || joker), i => total += i); break; case ScoreType.Sixes: ColUtility.ForEach(roll.Where(i => i == 6 || joker), i => total += i); break; case ScoreType.ThreeOfAKind: ColUtility.ForEach(roll, i => total += i); break; case ScoreType.FourOfAKind: ColUtility.ForEach(roll, i => total += i); break; case ScoreType.FullHouse: total = 25; break; case ScoreType.SmallStraight: total = 30; break; case ScoreType.LargeStraight: total = 40; break; case ScoreType.Yahtzee: if (HasScored(ScoreType.Yahtzee) && Yahtzee > 0) { total = 100; } else { total = 50; } break; case ScoreType.Chance: ColUtility.ForEach(roll, i => total += i); break; } return(total); }