public void ThrowExceptionIfNumberOfCellsIsZero() { Ecosystem ecosystem = new Ecosystem(); GameOfLife gameOfLife = new GameOfLife(ecosystem); Assert.Throws <Exception>(() => gameOfLife.Play()); }
protected bool Equals(Ecosystem other) { if (this._currentGeneration.Count == other._currentGeneration.Count) { foreach (var cell in _currentGeneration) { if (!other._currentGeneration.Contains(cell)) { return(false); } } return(true); } return(false); }
public void KeepRevivedCellsWhenYouIntroduceThreeInARow() { Ecosystem expectedEcosystem = new Ecosystem(); expectedEcosystem.AddCell(1, 0); expectedEcosystem.AddCell(1, 1); expectedEcosystem.AddCell(1, -1); Ecosystem ecosystem = new Ecosystem(); ecosystem.AddCell(0, 0); ecosystem.AddCell(2, 0); ecosystem.AddCell(1, 0); GameOfLife gameOfLife = new GameOfLife(ecosystem); gameOfLife.Play(); Assert.Equal(expectedEcosystem, ecosystem); }
public void KeepAliveAllCellsWhenFirstGenerationIsASquare() { Ecosystem expectedEcosystem = new Ecosystem(); expectedEcosystem.AddCell(0, 0); expectedEcosystem.AddCell(0, 1); expectedEcosystem.AddCell(1, 1); expectedEcosystem.AddCell(1, 0); Ecosystem ecosystem = new Ecosystem(); ecosystem.AddCell(0, 0); ecosystem.AddCell(0, 1); ecosystem.AddCell(1, 1); ecosystem.AddCell(1, 0); GameOfLife gameOfLife = new GameOfLife(ecosystem); gameOfLife.Play(); Assert.Equal(expectedEcosystem, ecosystem); }
public void ReturnSecondEvolvePatternWhenYouIntroduceABeaconPattern() { Ecosystem expectedEcosystem = new Ecosystem(); expectedEcosystem.AddCell(0, 0); expectedEcosystem.AddCell(0, 1); expectedEcosystem.AddCell(2, 3); expectedEcosystem.AddCell(3, 2); expectedEcosystem.AddCell(3, 3); expectedEcosystem.AddCell(1, 1); expectedEcosystem.AddCell(2, 2); expectedEcosystem.AddCell(1, 0); Ecosystem ecosystem = new Ecosystem(); ecosystem.AddCell(0, 0); ecosystem.AddCell(0, 1); ecosystem.AddCell(1, 1); ecosystem.AddCell(1, 0); ecosystem.AddCell(2, 2); ecosystem.AddCell(2, 3); ecosystem.AddCell(3, 2); ecosystem.AddCell(3, 3); GameOfLife gameOfLife = new GameOfLife(ecosystem); gameOfLife.Play(); GameOfLife gameOfLife2 = new GameOfLife(ecosystem); gameOfLife2.Play(); Assert.Equal(expectedEcosystem, ecosystem); }
public GameOfLife(Ecosystem ecosystem) { _ecosystem = ecosystem; }
public GameOfLife Play() { _ecosystem = _ecosystem.NewGeneration(); return(new GameOfLife(_ecosystem)); }