/// <summary> /// Save game to a text file. /// </summary> /// <param name="game">Game to save.</param> /// <param name="writer">Stream where to write provided game.</param> public void SaveGame(Game game, StreamWriter writer) { writer.Write(game.Rows); writer.Write(' '); writer.Write(game.Columns); writer.Write(' ');; writer.Write(game.Generation); writer.WriteLine(); for (int r = 0; r < game.Rows; r++) { for (int c = 0; c < game.Columns; c++) { writer.Write(game.IsAlive(r, c) ? ALIVE_CELL : DEAD_CELL); } writer.WriteLine(); } }
/// <summary> /// Print game state to the console. /// </summary> /// <param name="game">Game which state to display.</param> public void Print(Game game) { for (int r = 0; r < game.Rows; r++) { for (int c = 0; c < game.Columns; c++) { bool alive = game.IsAlive(r, c); Console.Write(alive ? ALIVE_CELL : DEAD_CELL); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Count of live cells: {0}", game.CountAlive); Console.WriteLine("Step: {0}", game.Generation); Console.WriteLine(); }
/// <summary> /// Print game state to the provided output. /// </summary> /// <param name="output">Destination where to write the game state.</param> public void Print(Game game) { int count = 0; for (int r = 0; r < game.Rows; r++) { for (int c = 0; c < game.Columns; c++) { bool alive = game.IsAlive(r, c); Console.Write(alive ? "+" : " "); if (alive) { count++; } } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Count of live cells: {0}", count); Console.WriteLine("Step: {0}", game.Generation); Console.WriteLine(); }
public void WorstPossibleGameOfLifeEverythingStaysDead() { game.Tick(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { Assert.That(game.IsAlive(x, y), Is.False); } } }