Add Life as a sequence of Gneerations

This commit is contained in:
Andrew Cooper
2022-09-13 07:56:27 +10:00
parent db186bb86e
commit a9ec4e3eb1
3 changed files with 53 additions and 22 deletions

View File

@@ -11,34 +11,16 @@ internal class Game
{
_io.Write(Streams.Title);
var generation = Generation.Create(_io);
var life = new Life(_io);
_io.Write(generation);
_io.Write(life.FirstGeneration);
while(true)
foreach (var generation in life)
{
generation = generation.CalculateNextGeneration();
_io.WriteLine();
_io.Write(generation);
if (generation.Result is not null) { break; }
var player1Coordinate = _io.ReadCoordinates(1, generation.Board);
var player2Coordinate = _io.ReadCoordinates(2, generation.Board);
if (player1Coordinate == player2Coordinate)
{
_io.Write(Streams.SameCoords);
// This is a bug existing in the original code. The line should be _board[_coordinates[_player]] = 0;
generation.Board.ClearCell(player1Coordinate + 1);
}
else
{
generation.Board.AddPlayer1Piece(player1Coordinate);
generation.Board.AddPlayer2Piece(player2Coordinate);
}
}
_io.WriteLine(generation.Result);
_io.WriteLine(life.Result ?? "No result");
}
}