void Map::update() { // iterate over everything except for the border and mark // which cells should live, die and be born: for ( int x = 1 ; x < mapSize - 1 ; x++ ) { for (int y = 1 ; y < mapSize - 1 ; y++ ) { int n = countAliveNeighbours( x, y ); applyRules( x, y, n ); } } // now that we have counted all neighbours and determined the new states, // we can actually change the alive-states of the cells: for ( int x = 1 ; x < mapSize - 1 ; x++ ) { for (int y = 1 ; y < mapSize - 1 ; y++ ) { tiles[x][y].alive = tiles[x][y].newState; } } }
void World::doSimulationStep() { for (int x = 0; x < static_cast<int>(cellmap.size()); ++x) { for (int y = 0; y < static_cast<int>(cellmap[0].size()); ++y) { int nbs = countAliveNeighbours(cellmap, x, y); // If a cell is alive, but has too few neightboors, kill it if (cellmap[x][y]) { if (nbs < deathLimit) { newCellmap[x][y] = false; } else { newCellmap[x][y] = true; } } else { // If a cell is dead, check if she has enough nbs to be alive (DEADCELL lol) if (nbs > birthLimit) { newCellmap[x][y] = true; } else { newCellmap[x][y] = false; } } } } }