Пример #1
0
 public void ToString_returns_a_grid_representing_the_world()
 {
     World world = new World(3, 3);
     Assert.AreEqual("- - -\r\n- - -\r\n- - -", world.ToString());
     world.SetCell(world.GetCoordinate(0, 0), Cell.Alive);
     world.SetCell(world.GetCoordinate(2, 0), Cell.Alive);
     world.SetCell(world.GetCoordinate(1, 1), Cell.Alive);
     world.SetCell(world.GetCoordinate(0, 2), Cell.Alive);
     world.SetCell(world.GetCoordinate(2, 2), Cell.Alive);
     Assert.AreEqual("O - O\r\n- O -\r\nO - O", world.ToString());
 }
Пример #2
0
 public void World_can_be_initialized_by_string()
 {
     World world = new World(5, 5);
     World clone = new World(world.ToString());
     Assert.AreEqual(world.ToString(), clone.ToString());
 }
Пример #3
0
        static void Main(string[] args)
        {
            // [Length(row number), Width(column number)]
            int[,] initialWorld = new int[15, 17] {
                                                    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                                    {0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
                                                    {0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
                                                    {0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
                                                    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0},
                                                    {0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                                                    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
            };

            var world = new World(initialWorld);

            for (var i = 0; i < 500; i++)
            {
                world.Evolve();

                //var tmp = world.ToString();
                Console.SetCursorPosition(0, 0);
                Console.Write(world.ToString());
                System.Threading.Thread.Sleep(200);
            }

            Console.Read();
        }