示例#1
0
        public static int LargeStraight(this YatzyDice dice)
        {
            var groupDice = dice.GroupDice();

            return(groupDice.Count == 5 && groupDice.First().Key == 6
                ? 20
                : 0);
        }
示例#2
0
        public static int ThreeOfAKind(this YatzyDice dice)
        {
            var threeOfAKind = dice.GroupDice().WhereCountIsAtLeast(3);

            return(threeOfAKind.Any()
                ? threeOfAKind[0].Key * 3
                : 0);
        }
示例#3
0
        public static int TwoPair(this YatzyDice dice)
        {
            var pairs = dice.GroupDice().WhereCountIsAtLeast(2);

            return(pairs.Length == 2
                ? pairs[0].Key * 2 + pairs[1].Key * 2
                : 0);
        }
示例#4
0
        public static int FullHouse(this YatzyDice dice)
        {
            var groups = dice.GroupDice();

            return(groups.Count == 2
                ? groups.Sum(g => g.Key * g.Value)
                : 0);
        }
示例#5
0
        public static int OnePair(this YatzyDice dice)
        {
            var pairs = dice.GroupDice().WhereCountIsAtLeast(2);

            return(pairs.Any()
                ? pairs.First().Key * 2
                : 0);
        }
示例#6
0
 public static int SmallStraight(this YatzyDice dice)
 {
     return(dice.GroupDice().Count == 5
         ? 15
          : 0);
 }
示例#7
0
 public static int Chance(this YatzyDice dice)
 {
     return(dice.Sum());
 }
示例#8
0
 public static int Sixes(this YatzyDice dice)
 {
     return(dice.FilteredSumBy(6));
 }
示例#9
0
 public static int Fives(this YatzyDice dice)
 {
     return(dice.FilteredSumBy(5));
 }
示例#10
0
 public static int Fours(this YatzyDice dice)
 {
     return(dice.FilteredSumBy(4));
 }
示例#11
0
 public static int Threes(this YatzyDice dice)
 {
     return(dice.FilteredSumBy(3));
 }
示例#12
0
 public static int Twos(this YatzyDice dice)
 {
     return(dice.FilteredSumBy(2));
 }
示例#13
0
 public static int Ones(this YatzyDice dice)
 {
     return(dice.FilteredSumBy(1));
 }
示例#14
0
 private static IDictionary <int, int> GroupDice(this YatzyDice dice)
 {
     return(dice.GroupBy(i => i).OrderByDescending(pair => pair.Key).ToDictionary(g => g.Key, g => g.Count()));
 }
示例#15
0
 public static int Yatzy(this YatzyDice dice)
 {
     return(dice.GroupDice().Count == 1
         ? 50
         : 0);
 }
示例#16
0
 private static int FilteredSumBy(this YatzyDice dice, int by)
 {
     return(dice.Where(i => i == by).Sum());
 }