Ejemplo n.º 1
0
        private static void DoBreeding()
        {
            Lifeform parentA = null;

            foreach (Lifeform lifeform in BROTHEL)
            {
                if (parentA == null)
                {
                    parentA = lifeform;
                    continue;
                }

                if (lifeform.Species != parentA.Species)
                {
                    continue;
                }

                Lifeform child = Lifeform.Breed(parentA, lifeform);
                parentA = null;

                if (child != null)
                {
                    LIFEFORMS.Add(child);
                }
            }
        }
Ejemplo n.º 2
0
        private void Run()
        {
            int    cycles      = CYCLES;
            long   updates     = 0;
            double oldProgress = 0;

            SW.Start();

            for (int i = 0; i < CYCLES; ++i)
            {
                foreach (Lifeform lifeform in LIFEFORMS)
                {
                    if (!lifeform.Alive)
                    {
                        LIMBO.Add(lifeform);
                        continue;
                    }

                    lock (LOCKER) {
                        // breeding conditions
                        if (lifeform.Age > 20 &&
                            (lifeform.MM.Mood == Mood.Great || lifeform.MM.Mood == Mood.Good) &&
                            lifeform.MM.Urge == Urge.Reproduce &&
                            2 * INIT_COUNT[(int)lifeform.Species] > Count[(int)lifeform.Species])
                        {
                            lifeform.Breeding = true;
                            BROTHEL.Add(lifeform);
                        }
                    }

                    lifeform.Update();
                    ++updates;
                }

                foreach (Lifeform lifeform in LIMBO)
                {
                    GRAVEYARD.Add(new Ghost(lifeform));
                }

                LIFEFORMS.ExceptWith(LIMBO);
                LIMBO.Clear();
                DoBreeding();
                BROTHEL.Clear();

                if (LIFEFORMS.Count == 0)
                {
                    cycles = i;
                    break;
                }

                if (LIFEFORMS.Count > _maxLifeforms)
                {
                    _maxLifeforms = LIFEFORMS.Count;
                }

                if (i % PSTAT_CYCLE == 0)
                {
                    PartialStatistics();
                }

                Recount();

                double progress = (i + 1.0) / CYCLES * 100;

                if (_doEndCycles)
                {
                    _worker.ReportProgress(100);
                    Thread.Sleep(50);
                    break;
                }

                if (SW.ElapsedMilliseconds > 100 && progress > oldProgress + 0.5)
                {
                    oldProgress = progress;

                    _worker.ReportProgress((int)progress);
                    Thread.Sleep(50);

                    SW.Restart();
                }
            }
        }
Ejemplo n.º 3
0
        private static List <object[]> TopAndBottom(int best, int worst, bool data)
        {
            List <object[]> itemsSource = new List <object[]>();

            if (LIFEFORMS.Count == 0)
            {
                return(itemsSource);
            }

            Lifeform[] lifeforms = LIFEFORMS
                                   .OrderByDescending(c => c.BreedCount)
                                   .ThenByDescending(c => c.Age)
                                   .ToArray();

            if (lifeforms.Length < best + worst)
            {
                foreach (Lifeform lifeform in lifeforms)
                {
                    itemsSource.Add(lifeform.ToObjectArray());
                }

                if (!data)
                {
                    return(itemsSource);
                }

                Console.WriteLine();
                Console.WriteLine(MoodManager.ToStringHeader());

                foreach (Lifeform lifeform in lifeforms)
                {
                    Console.WriteLine(lifeform.MM.ToString());
                }

                return(itemsSource);
            }

            for (int i = 0; i < best; ++i)
            {
                itemsSource.Add(lifeforms[i].ToObjectArray());
            }

            for (int i = worst + 1; i > 1; --i)
            {
                itemsSource.Add(lifeforms[lifeforms.Length - i].ToObjectArray());
            }

            if (!data)
            {
                return(itemsSource);
            }

            Console.WriteLine($"\n{"Urges",-29}||{"Emotions",-39}");
            Console.WriteLine(MoodManager.ToStringHeader());

            for (int i = 0; i < best; ++i)
            {
                Console.WriteLine(lifeforms[i].MM.ToString());
            }

            for (int i = worst + 1; i > 1; --i)
            {
                Console.WriteLine(lifeforms[lifeforms.Length - i].MM.ToString());
            }

            return(itemsSource);
        }