Exemplo n.º 1
0
        public static void RunV2(ILifePattern pattern, int displayOffset)
        {
            Console.Clear();
            int runs = 0;
            var sim  = new Core.V2.GameSimulation();

            sim.SetPattern(pattern);

            var sw = new Stopwatch();

            sw.Start();
            while (runs++ < (pattern.MaxGeneration ?? (long.MaxValue - 1)))
            {
                GenerationDraw.DrawGame(pattern.Height, pattern.Width, sim.CurrentGeneration);
                // Give the user a chance to view the game in a more reasonable speed.
                if (displayOffset > 0)
                {
                    System.Threading.Thread.Sleep(displayOffset);
                }

                sim.SimulateGeneration();
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Exemplo n.º 2
0
        public static IGameSimulation ChooseAndCreateVersion()
        {
            Console.WriteLine("Available game implementations:");
            Console.WriteLine("1: V1 version based on List");
            Console.WriteLine("2: V2 version based on Dictionary");
            Console.WriteLine("3: V3 version based on HashSet");

            string choosen        = Console.ReadLine();
            int    versionChoosen = 0;

            if (!string.IsNullOrWhiteSpace(choosen))
            {
                versionChoosen = Convert.ToInt32(choosen);
            }

            IGameSimulation gameSimulation;

            switch (versionChoosen)
            {
            case 1:
                gameSimulation = new Core.V1.GameSimulation();
                break;

            case 2:
                gameSimulation = new Core.V2.GameSimulation();
                break;

            case 3:
                gameSimulation = new Core.V3.GameSimulation();
                break;

            default:
                gameSimulation = new Core.V3.GameSimulation();
                break;
            }

            return(gameSimulation);
        }