mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Add Life as a sequence of Gneerations
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user