Beispiel #1
0
        private AtomicCollection <IAtomic> CanChemistDoCompound(Compound compound, AtomicCollection <IAtomic> experimentCollection)
        {
            var compoundAtoms           = compound.GetAtoms();
            var neededIatomicCollection = new AtomicCollection <IAtomic>();

            foreach (var iatomic in experimentCollection)
            {
                if (compound.Count == 0)
                {
                    return(neededIatomicCollection.Count == 0 ? null : neededIatomicCollection);
                }
                if (iatomic is Isotope)
                {
                    return(null);
                }
                if (iatomic is Compound)
                {
                    if (_fullCompoundNeeded(iatomic as Compound, compoundAtoms))
                    {
                        neededIatomicCollection.Add(iatomic);
                        foreach (var atom in (iatomic as Compound).GetAtoms())
                        {
                            compoundAtoms.Remove(atom);
                        }
                    }
                }
                if (iatomic is Atom && compoundAtoms.Contains(iatomic as Atom))
                {
                    compoundAtoms.Remove(iatomic as Atom);
                    neededIatomicCollection.Add(iatomic);
                }
            }
            return(neededIatomicCollection.Count > 0 && compoundAtoms.Count == 0 ? neededIatomicCollection : null);
        }
Beispiel #2
0
        public AtomicCollection <Atom> GetAtoms()
        {
            var atomicCollection = new AtomicCollection <Atom>();

            foreach (var atomstack in this)
            {
                for (int i = 0; i < atomstack.Size; i++)
                {
                    atomicCollection.AddRange(atomstack.GetAtoms());
                }
            }

            return(atomicCollection);
        }
Beispiel #3
0
        private bool _fullCompoundNeeded(Compound compound, AtomicCollection <Atom> collection)
        {
            var compoundAtoms       = compound.GetAtoms();
            var compoundAtomsLength = compoundAtoms.Count;
            var count = 0;

            foreach (var atom in collection)
            {
                if (!compoundAtoms.Contains(atom))
                {
                    continue;
                }
                count++;
                compoundAtoms.Remove(atom);
            }

            return(count == compoundAtomsLength);
        }
Beispiel #4
0
 private AtomicCollection <IAtomic> CheckCompounds(AtomicCollection <IAtomic> experimentCollection)
 {
     foreach (var compound in Knowledge.KnownCompounds)
     {
         var result = CanChemistDoCompound(compound, experimentCollection);
         if (result != null)
         {
             var atomStack = new List <AtomStack>();
             foreach (var iatomic in result)
             {
                 atomStack.Add(new AtomStack(iatomic));
                 experimentCollection.Remove(iatomic);
             }
             Compound newCompound = new Compound(atomStack);
             LogEvents.CompoundGot(compound);
             CheckCompounds(experimentCollection);
         }
     }
     return(experimentCollection);
 }
Beispiel #5
0
 private List <Ion> CheckIonCompounds(AtomicCollection <IAtomic> experimentCollection)
 {
     foreach (var compound in Knowledge.KnownIonCompounds.Keys)
     {
         var result = CanChemistDoCompound(compound, experimentCollection);
         if (result != null)
         {
             foreach (var atom in result)
             {
                 experimentCollection.Remove(atom);
             }
             result.First().Electrons -= Knowledge.KnownIonCompounds[compound].Item1;
             result.Last().Electrons  += Knowledge.KnownIonCompounds[compound].Item2;
             return(new List <Ion>(new Ion[]
             {
                 new Ion(result.First()),
                 new Ion(result.Last())
             }));
         }
     }
     return(null);
 }
Beispiel #6
0
        private List <Isotope> GetIsotopes(AtomicCollection <IAtomic> experimentCollection)
        {
            List <Isotope> isotopes = new List <Isotope>();

            foreach (var iAtomic in experimentCollection)
            {
                if (iAtomic is Isotope)
                {
                    continue;
                }

                if (iAtomic is Compound)
                {
                    Random random = new Random();
                    var    atoms  = (iAtomic as Compound).GetAtoms();
                    var    atom   = atoms[random.Next(atoms.Count)];
                    if (random.Next(101) > 50)
                    {
                        if (atom.GetElements().ToArray()[0].PrincipalIsotope != null)
                        {
                            isotopes.Add(atom.GetElements().ToArray()[0].PrincipalIsotope);
                        }
                        //LogEvents.IsotopeGot(atom.GetElements().ToArray()[0].PrincipalIsotope);
                    }
                }

                if (iAtomic is Atom)
                {
                    var isotope = iAtomic.GetElements().ToArray()[0].PrincipalIsotope;
                    if (isotope != null)
                    {
                        isotopes.Add(isotope);
                    }
                    //LogEvents.IsotopeGot(isotope);
                }
            }
            return(isotopes.Count > 0 ? isotopes : null);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Configuration.Load();
            Chemist chemist = new Chemist("Антон");
            var     h       = new Atom(PeriodicTable.GetElement("H"));
            var     o       = new Atom(PeriodicTable.GetElement("O"));
            var     c       = new Atom(PeriodicTable.GetElement("C"));
            //Позволяет использовать тип с большей глубиной наследования, чем задано изначально.
            //Экземпляр IEnumerable<Derived> (IEnumerable(Of Derived) в Visual Basic) можно присвоить переменной типа IEnumerable<Base>
            AtomicCollection <IAtomic> iAtomics = new AtomicCollection <IAtomic>()
            {
                h, o, c
            };
            AtomicCollection <Atom> atoms = new AtomicCollection <Atom>()
            {
                h, o, c
            };

            void DoSomething(IEnumerable <IAtomic> ienumerable)
            {
                foreach (var element in ienumerable)
                {
                    Console.WriteLine(element);
                }
            }

            DoSomething(iAtomics.Concat(atoms));

            //Позволяет использовать более универсальный тип (с меньшей глубиной наследования), чем заданный изначально.
            //Экземпляр Action<Base> (Action(Of Base) в Visual Basic) можно присвоить переменной типа Action<Derived>.
            Action <IAtomic> action      = Console.WriteLine;
            Action <Atom>    atom_action = action;

            action(h);
            atom_action(h);


            CompoundExperiment compoundExperiment = new CompoundExperiment(1);
            Compound           ho = new Compound(new AtomStack[]
            {
                PeriodicTable.GetElement("H"),
                PeriodicTable.GetElement("O")
            });

//            AtomicCollection<IAtomic> collection = new AtomicCollection<IAtomic>(){ho};
//            Console.WriteLine(collection.Contains(new Atom(PeriodicTable.GetElement("H"))));
            compoundExperiment.AtomicCollection.Add(ho);
            compoundExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("C")));
            compoundExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("H")));
            compoundExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("O")));
            compoundExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("O")));
            IonExperiment ionExperiment = new IonExperiment(1);

            //ionExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("Na")));
            //ionExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("O")));
            //ionExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("H")));
            ionExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("Ca")));
            ionExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("F")));
            ionExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("F")));
            IsotopeExperiment isotopeExperiment = new IsotopeExperiment(1);

            isotopeExperiment.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("Na")));
            chemist.DoExperiment(compoundExperiment);
            chemist.DoExperiment(ionExperiment);
            chemist.DoExperiment(isotopeExperiment);
            var      compoundExperiment2 = new CompoundExperiment(2);
            Compound h3 = new Compound(new AtomStack[]
            {
                new AtomStack(PeriodicTable.GetElement("H"), 3),
            });

            compoundExperiment2.AtomicCollection.Add(h3);
            compoundExperiment2.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("N")));
            compoundExperiment2.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("O")));
            compoundExperiment2.AtomicCollection.Add(new Atom(PeriodicTable.GetElement("Si")));
            chemist.DoExperiment(compoundExperiment2);
        }
Beispiel #8
0
 public AtomicCollection(AtomicCollection <T> collection)
 {
     _collection = new List <T>(collection);
 }