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()); } }
public void TestEvaluation() { 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}); g.EvaluateLife(); Assert.AreEqual(CellFactory.CreateCells(new[] {0, 1, 1}), g.GetHorizontalLine(3)); Assert.AreEqual(CellFactory.CreateCells(new[] {0, 0, 0}), g.GetHorizontalLine(2)); Assert.AreEqual(CellFactory.CreateCells(new[] {0, 1, 1}), g.GetHorizontalLine(1)); }
public void TestEvaluation1() { GameOfLife g = new GameOfLife(7); g.PopulateRow(7, new[] { 0, 1, 1, 1, 1, 1, 1 }); g.PopulateRow(6, new[] { 0, 0, 1, 0, 1, 0, 1 }); g.PopulateRow(5, new[] { 0, 1, 1, 1, 1, 0, 0 }); g.PopulateRow(4, new[] { 0, 1, 1, 0, 0, 1, 1 }); g.PopulateRow(3, new[] { 0, 0, 1, 1, 1, 0, 0 }); g.PopulateRow(2, new[] { 0, 1, 1, 0, 0, 1, 1 }); g.PopulateRow(1, new[] { 0, 1, 1, 1, 1, 1, 0 }); g.EvaluateLife(); Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 1, 1, 0, 1, 0, 1 }), g.GetHorizontalLine(7), "row 7");//ok Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 0, 0, 1 }), g.GetHorizontalLine(6), "row 6"); //ok Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 1, 0, 1 }), g.GetHorizontalLine(5), "row 5");//ok Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 0, 1, 0 }), g.GetHorizontalLine(4), "row 4");//ok Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 1, 0, 0 }), g.GetHorizontalLine(3), "row 3");//ok Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 0, 0, 1 }), g.GetHorizontalLine(2), "row 2"); //ok Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 1, 0, 1, 1, 1, 1 }), g.GetHorizontalLine(1), "row 1"); //ok }