Beispiel #1
0
        static void Main(string[] args)
        {
            //en glider
              var firstrow =  new[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 };
              var secondrow = new[] { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
              var thirdrow =  new[] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
              var nullrow =   new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

              GameOfLife game = new GameOfLife(10);
              game.PopulateRow(10, firstrow);
              game.PopulateRow(9, secondrow);
              game.PopulateRow(8, thirdrow);
              game.PopulateRow(7, nullrow);
              game.PopulateRow(6, nullrow);
              game.PopulateRow(5, nullrow);
              game.PopulateRow(4, nullrow);
              game.PopulateRow(3, nullrow);
              game.PopulateRow(2, nullrow);
              game.PopulateRow(1, nullrow);

              Console.WriteLine(game.ToString());

              while (true)
              {
            Thread.Sleep(1000);
            game.EvaluateLife();

            Console.WriteLine(game.ToString());
              }
        }
Beispiel #2
0
        public void TestTostring()
        {
            GameOfLife g = new GameOfLife(3);
              g.PopulateRow(1, new[] { 0, 1, 1 });
              g.PopulateRow(2, new[] { 0, 0, 1 });
              g.PopulateRow(3, new[] { 0, 1, 1 });

              StringBuilder result = new StringBuilder();
              result.AppendLine("------");
              result.AppendLine(" **");
              result.AppendLine("  *");
              result.AppendLine(" **");
              result.AppendLine("------");

              Assert.AreEqual(result.ToString(), g.ToString());
        }
Beispiel #3
0
        public void TestTostringLength()
        {
            GameOfLife g = new GameOfLife(2);
              g.PopulateRow(2, new[] { 0, 0 });
              g.PopulateRow(1, new[] { 0, 1 });

              StringBuilder expectedResult = new StringBuilder();
              expectedResult.AppendLine("----");
              expectedResult.AppendLine("  ");
              expectedResult.AppendLine(" *");
              expectedResult.AppendLine("----");
              Assert.AreEqual(expectedResult.ToString(), g.ToString());
        }