Exemple #1
0
        public IEnumerable <Assembly> SafeChipGeneratorCombinations()
        {
            var singleChips      = Chips.Select(c => new Assembly().WithChip(c));
            var singleGenerators = Generators.Select(g => new Assembly().WithGenerator(g));
            IEnumerable <Assembly> chipCombinations = new List <Assembly>();

            if (Chips.Count > 1)
            {
                chipCombinations = new Combinations <Element>(Chips.ToList(), 2)
                                   .Select(pair => new Assembly()
                                           .WithChip(pair.First())
                                           .WithChip(pair.Last()));
            }

            IEnumerable <Assembly> generatorCombinations = new List <Assembly>();

            if (Generators.Count > 1)
            {
                generatorCombinations = new Combinations <Element>(Generators.ToList(), 2)
                                        .Select(pair => new Assembly()
                                                .WithGenerator(pair.First())
                                                .WithGenerator(pair.Last()));
            }

            var chipGeneratorPairs = Chips
                                     .Where(chip => Generators.Contains(chip))
                                     .Select(c => new Assembly().WithMatchingChipAndGenerator(c));

            return(singleChips
                   .Concat(singleGenerators)
                   .Concat(chipCombinations)
                   .Concat(chipGeneratorPairs)
                   .Concat(generatorCombinations));
        }
Exemple #2
0
        public override void Delete()
        {
            base.Delete();

            if (Generators.Contains(this))
            {
                Generators.Remove(this);
            }
        }
Exemple #3
0
 public bool IsSafe()
 {
     if (!Chips.Any())
     {
         return(true);
     }
     if (!Generators.Any())
     {
         return(true);
     }
     return(Chips.All(c => Generators.Contains(c)));
 }