Exemplo n.º 1
0
        private static void RunNumbers()
        {
            _People = new C5.ArrayList<Person>();
            //_Ages = new List<int>();
            //_ReproStarts = new List<int>();
            //_ReproEnds = new List<int>();

            //var stp = new Stopwatch();
            //stp.Start();

            for (int i = 0; i < _InitialPopulationMale; i++)
            {
                _People.Add(new Person(0, false, false, true));
            }

            for (int i = 0; i < _InitialPopulationFemale; i++)
            {
                _People.Add(new Person(0, true, true, true));
            }

            for (int i = 0; i < _EndYear; i++)
            {
                _CurrentYear = i;
                //Console.Write(".");
                //Console.WriteLine("Year {0}", i);

                _People.RemoveAll(_People.Where(y => !y.IsAlive));
                Console.WriteLine("Year {0}: {1} People", i, _People.Count().ToString("#,##0"));
                long newPeeps = _People.Count(x => x.IsMakinABaby);
                newPeeps = (long)(newPeeps * 1.04); // account for twins, triplets, etc based upon estimate from http://www.cdc.gov/nchs/fastats/multiple.htm (33.1 twins per 1000, 3x or higeher 124.4/100,000)
                _People.AddAll(Enumerable.Range(1, newPeeps).Select(x => new Person(i, null, null, false)));

            }

            //Console.WriteLine("Year {0}: {1} People, Avg age: {2}, Avg Repro Start: {3}, Avg Repro End: {4}", _EndYear, _People.Count(x => x.IsAlive).ToString("#,##0"), _Ages.Average(), _ReproStarts.Average(), _ReproEnds.Average());
            Console.WriteLine("Year {0}: {1} People", _EndYear, _People.Count().ToString("#,##0"));
            Console.WriteLine("-----");
            Console.WriteLine("DONE");
            Console.WriteLine("-----");
            Console.WriteLine("What now? ([R]epeat, [S]tart over, [Q]uit");
            Console.Beep();
            var action = Console.ReadLine();

            if (action.ToUpper() == "REPEAT" || action.ToUpper() == "R")
            {
                RunNumbers();
            }
            else if (action.ToUpper() == "START OVER" || action.ToUpper() == "S")
            {
                InitAndRun();
            }
            else
            {
                // quit
            }
        }