public ValueMap Generate() { map = input.Clone(); for (int i = 0; i < iterations; i++) { buffer.Initialize(size); for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { // Count alive neighbours int neighbours = map.GetNeighbours(new Vector2Int(x, y), searchRadius, true).FindAll(n => map[n] > threshold).Count; // cell is alive if (neighbours > birthRule) { buffer[x, y] = 1; } // cell is dead else if (neighbours < deathRule) { buffer[x, y] = 0; } } } map = buffer.Clone(); } return(map); }