Пример #1
0
        /*Creates and array of int which will represent the world of game, it will return false if init will fail
         * height - should be not greater than 1000
         * width -should be not greater than 1000
         * aliveProb - how probable that considered pixel will be alive - IDEA: create it as object, in future pixel can havemore than dead/alive stage
         * IDEA new param: populateMethod - populate array in other ways tahn rand, maybe create alive guys in some patterns
         * isWrappable - set the parameter dfining is world wrapped or not*/
        //https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmappalette(v=vs.110).aspx
        //http://www.i-programmer.info/programming/wpf-workings/527-writeablebitmap.html?start=1

        public bool InitTheworld(int height, int width, int aliveProb, bool isWrappable)
        {
            /*DIAGNOSTIC*/
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            /*DIAGNOSTIC*/

            /*check the arguments*/
            if (height > MAX_WORLD_HEIGHT | width > MAX_WORLD_WIDTH)
            {
                Console.WriteLine("Zainicjalizowno za duży świat"); return(false);
            }
            gameWorld = new GameWorld(height, width, isWrappable);
            popParams = new PopulatingParams(aliveProb);
            gameWorld.Populate(GameWorld.MethodsOfPopulation.random, popParams);

            /*DIAGNOSTIC*/
            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);
            /*DIAGNOSTIC*/

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Populate the world array with live members accord. to probability value
        /// </summary>
        /// <param name="popPar">parameters for method</param>
        private void PopulatingMethodRandom(PopulatingParams popPar)
        {
            Random rnd = new Random();

            for (int i = 0; i < world.GetLength(0); i++)
            {
                for (int j = 0; j < world.GetLength(1); j++)
                {
                    if (rnd.Next(0, 100) > popPar.aliveProbability)
                    {
                        world[i, j] = 0;
                    }
                    else
                    {
                        world[i, j] = 1;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Populates the world maintaining rules of populating
        /// </summary>
        /// <param name="method">set of rules describing how to populate the world</param>
        /// <param name="popPar">parameters for method</param>
        /// <returns></returns>
        public bool Populate(MethodsOfPopulation method, PopulatingParams popPar)
        {
            switch (method)
            {
            case MethodsOfPopulation.random:
                PopulatingMethodRandom(popPar);
                age++;
                return(true);

            case MethodsOfPopulation.other:
                return(true);

            case MethodsOfPopulation.test:
                return(true);

            default:
                return(false);
            }
        }