using System; using System.Linq; public enum Scores { Ones, // Sum of Ones Twos, // Sum of Twos Threes, // Sum of Threes Fours, // Sum of Fours Fives, // Sum of Fives Sixes, // Sum of Sixes ThreeOfAKind, // Sum of all dice FourOfAKind, // Sum of all dice FullHouse, // 25 SmallStraight, // 30 LargeStraight, // 40 Yahtzee, // 50 Chance // Sum of all dice } public class Program { public static void Main (string [] astrArg) { Random rand = new Random (); for (int s = 0; s < 10; s++) { int [] dice = new int [5]; for (int i = 0; i < dice.Length; ++i) { dice [i] = rand.Next (6); // also Werte von einschließlich 0 bis einschließlich 5 } // dice = new int[] { 0, 4, 4, 0, 4 }; int [] points = GetPoints (dice); foreach (var d in dice) Console.Write("{0} ", d + 1); Console.WriteLine(); foreach (Scores score in Enum.GetValues (typeof (Scores))) { Console.WriteLine ("{0,15} {1}", score, points [(int)score]); } } Console.ReadKey(true); } public static int [] GetPoints (int [] dice) { int[] result = new int[Enum.GetValues(typeof(Scores)).Length]; var getCount = new Func((i) => dice.Where((d) => d == dice[i]).Count()); Array.Sort(dice); result[(int)Scores.Ones] = dice.Where((d) => d == 0).Count() * 1; result[(int)Scores.Twos] = dice.Where((d) => d == 1).Count() * 2; result[(int)Scores.Threes] = dice.Where((d) => d == 2).Count() * 3; result[(int)Scores.Fours] = dice.Where((d) => d == 3).Count() * 4; result[(int)Scores.Fives] = dice.Where((d) => d == 4).Count() * 5; result[(int)Scores.Sixes] = dice.Where((d) => d == 5).Count() * 6; result[(int)Scores.ThreeOfAKind] = getCount(0) >= 3 || getCount(2) >= 3 || getCount(4) >= 3 ? dice.Sum((d) => d + 1) : 0; result[(int)Scores.FourOfAKind] = getCount(0) >= 4 || getCount(4) >= 4 ? dice.Sum((d) => d + 1) : 0; result[(int)Scores.FullHouse] = result[(int)Scores.ThreeOfAKind] > 0 ? (getCount(0) == 2 || getCount(4) == 2 ? 25 : 0) : 0; bool largeStraight = true; var num = dice[0]; for (int i = 0; i < 5; i++) { largeStraight = largeStraight && (dice[i] == i + num); } result[(int)Scores.LargeStraight] = largeStraight ? 40 : 0; bool smallStraight = false; var arr = dice.Distinct().ToArray(); if (arr.Length >= 4) { var slice = arr.Take(4).ToArray(); num = slice[0]; smallStraight = true; for (int i = 0; i < 4; i++) { smallStraight = smallStraight && (slice[i] == i + num); } if (!smallStraight && arr.Length == 5) { slice = arr.Skip(1).ToArray(); smallStraight = true; num = slice[0]; for (int i = 0; i < 4; i++) { smallStraight = smallStraight && (slice[i] == i + num); } } } result[(int)Scores.SmallStraight] = smallStraight ? 30 : 0; result[(int)Scores.Yahtzee] = getCount(0) == 5 ? 50 : 0; result[(int)Scores.Chance] = dice.Sum((d) => d + 1); return result; } }