コード例 #1
0
        internal static List <Ameba> IterateNumberOfLifeCylces(List <Ameba> listOfAmebas, int numberOfYears)
        {
            List <Ameba> listOfAmebasToAdd = new List <Ameba>();

            for (int i = 0; i < numberOfYears; i++)
            {
                List <Ameba> tempList = LifeCycleIterator.TryToProcreate(listOfAmebas[i]);
                if (tempList.Count > 1) //get rid of this dead Ameba
                {
                    //listOfAmebas.RemoveAt(i); //can't remove it just yet. need to make sure it's dead and then at the end before adding them, remove the dead ones
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        listOfAmebasToAdd.Add(tempList[j]);
                    }
                }
            }
            for (int y = 0; y < listOfAmebas.Count; y++)
            {
                if (listOfAmebas[y].getLifeStatus() == false)
                {
                    listOfAmebas.RemoveAt(y);
                }
            }
            for (int x = 0; x < listOfAmebasToAdd.Count; x++)
            {
                listOfAmebas.Add(listOfAmebasToAdd[x]);
            }
            return(listOfAmebas);
        }
コード例 #2
0
        public static void runMain()
        {
            Console.WriteLine("Running Main Method");

            List <Ameba> initialAmebaList = new List <Ameba>();

            for (int i = 0; i < 1000; i++)
            {
                Ameba ameba = new Ameba();
                initialAmebaList.Add(ameba);
            }
            Console.WriteLine("The Number of Amebas in this list is: " + initialAmebaList.Count);
            Console.WriteLine("Starting the iterations of life cycles");

            List <Ameba> listAfterLifeCycles = LifeCycleIterator.IterateNumberOfLifeCylces(initialAmebaList, 1000);

            Console.WriteLine("The number of Amebas after 1000 life cycles is: " + listAfterLifeCycles.Count);
        }