// Start is called before the first frame update void Start() { rand = new System.Random(); cells = new CellularSimulation <int>(width, height); meshGen = GetComponent <MeshGenerator>(); cells.UpdateInPlace(cell => rand.Next(0, 100) <= percentFilled ? 1 : 0); meshGen.GenerateMesh(cells.Values(), 1); StartCoroutine(RunLoop()); }
int InitialValue(CellularSimulation <int> .Cell cell) { if (cell.IsEdge) { return(1); } else { return(rand.Next(0, 100) <= percentFilled ? 1 : 0); } }
int Smooth(CellularSimulation <int> .Cell cell) { int outOfBoundsNeighbors = 8 - cell.CountNeighbors(); int wallNeighbors = cell.CountNeighbors((me, other) => other.Value == 1); int wallCount = outOfBoundsNeighbors + wallNeighbors; if (wallCount > 4) { return(1); } else if (wallCount < 4) { return(0); } return(cell.Value); }
void GenerateCave() { if (!useCustomSeed) { randomSeed = Time.time.ToString(); } rand = new System.Random(randomSeed.GetHashCode()); cells = new CellularSimulation <int>(width, height); cells.UpdateInPlace(InitialValue); for (int i = 0; i < smoothCount; i++) { cells.Update(Smooth); } MeshGenerator meshGen = GetComponent <MeshGenerator>(); meshGen.GenerateMesh(cells.Values(), 1); }
int Tick(CellularSimulation <int> .Cell cell) { switch (cell.CountNeighbors((x, y) => y.Value == 1)) { case 0: case 1: return(0); case 2: return(cell.Value); case 3: return(1); case 4: case 5: case 6: case 7: case 8: default: return(0); } }
internal Cell(CellularSimulation <T> simulation, int x, int y) { this.simulation = simulation; X = x; Y = y; }