Пример #1
0
 public bool Equals(Roll other)
 {
     return(this.OrderBy(x => x).SequenceEqual(other.OrderBy(x => x)));
 }
Пример #2
0
        public static List <Roll> RollCombinations(int dice, Roll roll)
        {
            Tuple <int, Roll> key = new Tuple <int, Roll>(dice, roll);
            List <Roll>       combos;

            if (RollComboCache.TryGetValue(key, out combos))
            {
                return(combos);
            }

            if (dice == roll.Count())
            {
                combos = new List <Roll> {
                    new Roll(roll.OrderBy(x => x))
                };
                RollComboCache.Add(key, combos);
                return(combos);
            }

            combos = new List <Roll>();
            for (int a = 0; a < roll.Count; a++)
            {
                if (dice == 1)
                {
                    combos.Add(new Roll {
                        roll[a]
                    }); continue;
                }
                for (int b = a + 1; b < roll.Count; b++)
                {
                    if (dice == 2)
                    {
                        combos.Add(new Roll {
                            roll[a], roll[b]
                        }); continue;
                    }
                    for (int c = b + 1; c < roll.Count; c++)
                    {
                        if (dice == 3)
                        {
                            combos.Add(new Roll {
                                roll[a], roll[b], roll[c]
                            }); continue;
                        }
                        for (int d = c + 1; d < roll.Count; d++)
                        {
                            if (dice == 4)
                            {
                                combos.Add(new Roll {
                                    roll[a], roll[b], roll[c], roll[d]
                                }); continue;
                            }
                            for (int e = d + 1; e < roll.Count; e++)
                            {
                                if (dice == 5)
                                {
                                    combos.Add(new Roll {
                                        roll[a], roll[b], roll[c], roll[d], roll[e]
                                    }); continue;
                                }
                                for (int f = e + 1; f < roll.Count; f++)
                                {
                                    combos.Add(new Roll {
                                        roll[a], roll[b], roll[c], roll[d], roll[e], roll[f]
                                    });
                                }
                            }
                        }
                    }
                }
            }
            combos = combos.Distinct().ToList();
            RollComboCache.Add(key, combos);
            return(combos);
        }