engine/generators/source/CellularAutomataGenerator.cpp
// 1. Initialize the map
// For each iteration from 1 to ITERATIONS:
// 2. Randomly choose a square
// 3. Close that square if the random probability is less than P_CLOSE_CELL
// 4. If the cell is open, generate a random number.  If this is less than P_CLOSE_CELL, close the cell.
// 5. If the number of closed neighbours is greater than or equal to the number required to trigger, then open the cell, else close it.
1. Initialize the map
For each iteration from 1 to ITERATIONS:
2. Randomly choose a square
3. Close that square if the random probability is less than P_CLOSE_CELL
4. If the cell is open, generate a random number.  If this is less than P_CLOSE_CELL, close the cell.
5. If the number of closed neighbours is greater than or equal to the number required to trigger, then open the cell, else close it.
1 . Initialize the map For each iteration from 1 to ITERATIONS : 2 . Randomly choose a square 3 . Close that square if the random probability is less than P_CLOSE_CELL 4 . If the cell is open generate a random number . If this is less than P_CLOSE_CELL close the cell . 5 . If the number of closed neighbours is greater than or equal to the number required to trigger then open the cell else close it .
CellMap CellularAutomataGenerator::generate()
{
  int y = dimensions.get_y();
  int x = dimensions.get_x();
  int rand_cell_y, rand_cell_x, num_closed_neighbours;
  int close_cell;
  CellMap cell_map = get_initialized_cells(y, x);
  for (int iteration = 0; iteration < ITERATIONS; iteration++)
  {
    rand_cell_y = RNG::range(0, y-1);
    rand_cell_x = RNG::range(0, x-1);
    close_cell = RNG::range(0, 100);
    if (close_cell < P_CLOSE_CELL)
    {
      cell_map[rand_cell_y][rand_cell_x] = CellValue::CELL_OFF;
    }
    num_closed_neighbours = get_number_closed_neighbours(cell_map, dimensions, rand_cell_y, rand_cell_x);
    if (num_closed_neighbours > NEIGHBOUR_THRESHOLD)
    {
      cell_map[rand_cell_y][rand_cell_x] = CellValue::CELL_OFF;
    }
    else
    {
      cell_map[rand_cell_y][rand_cell_x] = CellValue::CELL_ON;
    }
  }
  return cell_map;
}
CellMap CellularAutomataGenerator :: generate ( ) { int y = dimensions . get_y ( ) ; int x = dimensions . get_x ( ) ; int rand_cell_y , rand_cell_x , num_closed_neighbours ; int close_cell ; CellMap cell_map = get_initialized_cells ( y , x ) ; for ( int iteration = 0 ; iteration < ITERATIONS ; iteration ++ ) { rand_cell_y = RNG :: range ( 0 , y - 1 ) ; rand_cell_x = RNG :: range ( 0 , x - 1 ) ; close_cell = RNG :: range ( 0 , 100 ) ; if ( close_cell < P_CLOSE_CELL ) { cell_map [ rand_cell_y ] [ rand_cell_x ] = CellValue :: CELL_OFF ; } num_closed_neighbours = get_number_closed_neighbours ( cell_map , dimensions , rand_cell_y , rand_cell_x ) ; if ( num_closed_neighbours > NEIGHBOUR_THRESHOLD ) { cell_map [ rand_cell_y ] [ rand_cell_x ] = CellValue :: CELL_OFF ; } else { cell_map [ rand_cell_y ] [ rand_cell_x ] = CellValue :: CELL_ON ; } } return cell_map ; }
1
1 .
// vectors start at 0, go to size-1.