private static void Main(string[] args) { var totalGen = 50; var rows = 31; var columns = 31; var lifeBoard = new LifeBoard(rows, columns); for (int i = 0; i < rows; i++) { lifeBoard.ToggleCell(i, 15); for (int j = 0; j < columns; j++) { lifeBoard.ToggleCell(15, j); } } var done = false; while (!done) { PrintCells(lifeBoard); lifeBoard.ProcessNext(); var key = System.Console.ReadLine(); if (key == "e" || key == "E") { done = true; } } }
public void AliveCellWithMoreThan3NeighboursShouldBeDead() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 0); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(0, 2); lifeBoard.ToggleCell(1, 0); lifeBoard.ToggleCell(1, 1); lifeBoard.ToggleCell(1, 2); lifeBoard.ToggleCell(2, 0); lifeBoard.ToggleCell(2, 1); lifeBoard.ToggleCell(2, 2); lifeBoard.ProcessNext(); Assert.That(true, Is.EqualTo(lifeBoard[0, 0].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[0, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[0, 2].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[1, 0].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[1, 1].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[1, 2].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 0].IsAlive)); Assert.That(false, Is.EqualTo(lifeBoard[2, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 2].IsAlive)); Assert.That(2, Is.EqualTo(lifeBoard.Generation)); }
public void AliveCellWith2Or3NeiboursShouldBeAliveInNextGeneration() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(1, 0); lifeBoard.ToggleCell(1, 1); lifeBoard.ToggleCell(1, 2); lifeBoard.ProcessNext(); Assert.That(true, Is.EqualTo(lifeBoard[0, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[1, 0].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[1, 1].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[1, 2].IsAlive)); Assert.That(2, Is.EqualTo(lifeBoard.Generation)); }
public void DeadCellWithExact3AliveNeiboursShouldBecomeAlive() { var lifeBoard = new LifeBoard(3, 3); lifeBoard.ToggleCell(0, 1); lifeBoard.ToggleCell(1, 0); lifeBoard.ToggleCell(1, 1); lifeBoard.ToggleCell(1, 2); lifeBoard.ToggleCell(2, 1); lifeBoard.ProcessNext(); Assert.That(true, Is.EqualTo(lifeBoard[0, 0].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[0, 2].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 0].IsAlive)); Assert.That(true, Is.EqualTo(lifeBoard[2, 2].IsAlive)); Assert.That(2, Is.EqualTo(lifeBoard.Generation)); }