public void Ticks_OneAlive_100Generations_AllDead() { // arrange var worldGenerator = new StandardWorldGenerator(); var cellGrid = new StandardCellGrid ( new[] { new[] { Dead(), Dead(), Dead() }, new[] { Dead(), Alive(), Dead() }, new[] { Dead(), Dead(), Dead() } } ); var world = new StandardWorldBuilder().With(w => w.Data, new StandardWorldData { Grid = cellGrid }).Create(); var expected = new StandardCellGrid(EnumerablePrelude.Repeat(() => EnumerablePrelude.Repeat(Dead, 3).ToArray(), 3).ToArray()); // act var result = worldGenerator.Ticks(world).Skip(100).First().Data.Grid; // assert Assert.AreEqual(GridToString(expected), GridToString(result)); }
public IEnumerable <StandardWorld> Ticks(StandardWorld world) { yield return(world); var nextGrid = world.Data.Grid.Cells.AsParallel().Select((row, outerInd) => row.AsParallel().Select((_, innerInd) => world.CellCalculator.CalculateCell( world.Data.Grid.Cells[outerInd][innerInd], world.NeighbourFinder.FindNeighbours(world.Data.Grid, outerInd, innerInd), world.Data)).ToArray()).ToArray(); var data = new StandardWorldData { Generation = world.Data.Generation + 1, Grid = new StandardCellGrid(nextGrid) }; var nextWorld = new StandardWorldBuilder(world).With(w => w.Data, data).Create(); foreach (var tick in Ticks(nextWorld)) { yield return(tick); } }
public void Ticks_WithOscillating_100Generations_IsSame() { // arrange var worldGenerator = new StandardWorldGenerator(); var cellGrid = new StandardCellGrid ( new[] { new[] { Dead(), Dead(), Dead(), Dead() }, new[] { Dead(), Alive(), Alive(), Dead() }, new[] { Dead(), Alive(), Alive(), Dead() }, new[] { Dead(), Dead(), Dead(), Dead() } } ); var world = new StandardWorldBuilder().With(w => w.Data, new StandardWorldData { Grid = cellGrid }).Create(); // act var result = worldGenerator.Ticks(world).Skip(100).First().Data.Grid; // assert Assert.AreEqual(GridToString(cellGrid), GridToString(result)); }