// Returns the next generation of a world public World GetNext() => new World( // Return a new world LiveCells.Select( // that focuses on every live cell, c => NeighborsAndSelf(c)) // and each of its neighbors. .SelectMany(s => s).Distinct() // (Flatten enumerable of enumerables) .Select(focusedCell => // Then for each focused cell focusedCell.GetNext( // get the next generation of that cell LiveNeighborCount(focusedCell.coord) // Based on that cell's current value and its live neighbor count )), Age + 1); // That is one generation older
)), Age + 1); // That is one generation older // Returns the same world, but shifted by a coordinate delta public World GetShifted(Coordinate delta) => new World( LiveCells.Select(c => new Cell(c.coord.Plus(delta), c.value)), Age);