Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.Clear();
                if (!InputHandler.TryProcessInput(out var result))
                {
                    Console.WriteLine("잘못된 입력입니다.");
                    continue;
                }

                var cellGrid   = CellGridStringConverter.ConvertFrom(result.Width, result.Height, result.CellGridLines);
                var simulator  = new GameOfLifeSimulater(cellGrid);
                var outputLeft = Console.CursorLeft;
                var outputTop  = Console.CursorTop;

                while (true)
                {
                    Console.SetCursorPosition(outputLeft, outputTop);
                    Console.WriteLine();

                    var snapshot      = simulator.Simulate();
                    var cellGridLines = CellGridStringConverter.ConvertTo(snapshot.CellGrid);
                    Console.WriteLine($"# Generation {snapshot.Generation}                ");
                    Array.ForEach(cellGridLines, Console.WriteLine);
                    Console.ReadKey();
                }
            }
        }
Ejemplo n.º 2
0
        void TestGameOfLife(int width, int height, string[] input, string[] output)
        {
            var cellGrid  = CellGridStringConverter.ConvertFrom(width, height, input);
            var simulator = new GameOfLifeSimulater(cellGrid);
            var snapshot  = simulator.Simulate();

            Assert.AreEqual(1, snapshot.Generation);

            var outputCellGridLines = CellGridStringConverter.ConvertTo(snapshot.CellGrid);

            CollectionAssert.AreEqual(output, outputCellGridLines);
        }