private DecoratorCellState[,] CleanMap(DecoratorCellState[,] map) { map = new DecoratorCellState[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map[x, y] = DecoratorCellState.True; } } return(map); }
private DecoratorCellState[,] DoSimulationStep(DecoratorCellState[,] oldMap) { DecoratorCellState[,] newMap = new DecoratorCellState[width, height]; //Loop over each row and column of the map for (int x = 0; x < oldMap.GetLength(0); x++) { for (int y = 0; y < oldMap.GetLength(1); y++) { int nbs = countAliveNeighbours(oldMap, x, y); //The new value is based on our simulation rules //First, if a cell is alive but has too few neighbours, kill it. if (oldMap[x, y] == DecoratorCellState.True) { if (nbs < deathLimit) { newMap[x, y] = DecoratorCellState.False; } else { newMap[x, y] = DecoratorCellState.True; } } //Otherwise, if the cell is dead now, check if it has the right number of neighbours to be 'born' else { if (nbs > birthLimit) { newMap[x, y] = DecoratorCellState.True; } else { newMap[x, y] = DecoratorCellState.False; } } if (oldMap[x, y] == DecoratorCellState.RoadDiagonal || oldMap[x, y] == DecoratorCellState.RoadSmooth || oldMap[x, y] == DecoratorCellState.RoadStripe) { // Re write the new map with the road data newMap[x, y] = oldMap[x, y]; } } } return(newMap); }