build/safeCopy.c
/*update the the grid following the simple fundamental rules
1) Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
2) Any live cell with more than three live neighbors dies, as if by overcrowding.
3) Any live cell with two or three live neighbors lives on to the next generation.
4) Any dead cell with exactly three live neighbors becomes a live cell.
with the help of
https://rosettacode.org/wiki/Conway%27s_Game_of_Life
*/
update the the grid following the simple fundamental rules
1) Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
2) Any live cell with more than three live neighbors dies, as if by overcrowding.
3) Any live cell with two or three live neighbors lives on to the next generation.
4) Any dead cell with exactly three live neighbors becomes a live cell.
update the the grid following the simple fundamental rules 1 ) Any live cell with fewer than two live neighbors dies as if caused by underpopulation . 2 ) Any live cell with more than three live neighbors dies as if by overcrowding . 3 ) Any live cell with two or three live neighbors lives on to the next generation . 4 ) Any dead cell with exactly three live neighbors becomes a live cell .
void evolve(struct argb8888 *grid, unsigned char table[SCREEN_HEIGHT][SCREEN_WIDTH]){
	unsigned char temp[SCREEN_HEIGHT][SCREEN_WIDTH];
	for (int i = 0; i < SCREEN_HEIGHT; i++){
		for (int j = 0; j < SCREEN_WIDTH; j++) {
			int neighbors = 0;
			looking at a 3x3 grid checking for conditions
			for(int i_test = i - 1; i_test <= i + 1; i_test++){
				for(int j_test = j - 1; j_test <= j + 1; j_test++){
					if value is positive then yes and update neighbors
					if(table[(i_test + SCREEN_HEIGHT) % SCREEN_HEIGHT][(j_test + SCREEN_WIDTH) % SCREEN_WIDTH]){
						neighbors++;
					}
				}
			}
			update for correct calculation and application of rules
			if(table[i][j]){
				neighbors--;
			}
			new life is created or extinguished by the rules
			temp[i][j] = (neighbors == 3 || (neighbors == 2 && table[i][j]));
		}
	}
	for(int i = 0; i < SCREEN_HEIGHT; i++){
		for(int j = 0; j < SCREEN_WIDTH; j++){
			update matrix
			table[i][j] = temp[i][j];
			either 255 or 0
			grid[i * SCREEN_WIDTH + j].red = 255 * table[i][j];
		}
	}
}
void evolve ( struct argb8888 * grid , unsigned char table [ SCREEN_HEIGHT ] [ SCREEN_WIDTH ] ) { unsigned char temp [ SCREEN_HEIGHT ] [ SCREEN_WIDTH ] ; for ( int i = 0 ; i < SCREEN_HEIGHT ; i ++ ) { for ( int j = 0 ; j < SCREEN_WIDTH ; j ++ ) { int neighbors = 0 ; for ( int i_test = i - 1 ; i_test <= i + 1 ; i_test ++ ) { for ( int j_test = j - 1 ; j_test <= j + 1 ; j_test ++ ) { if ( table [ ( i_test + SCREEN_HEIGHT ) % SCREEN_HEIGHT ] [ ( j_test + SCREEN_WIDTH ) % SCREEN_WIDTH ] ) { neighbors ++ ; } } } if ( table [ i ] [ j ] ) { neighbors -- ; } temp [ i ] [ j ] = ( neighbors == 3 || ( neighbors == 2 && table [ i ] [ j ] ) ) ; } } for ( int i = 0 ; i < SCREEN_HEIGHT ; i ++ ) { for ( int j = 0 ; j < SCREEN_WIDTH ; j ++ ) { table [ i ] [ j ] = temp [ i ] [ j ] ; grid [ i * SCREEN_WIDTH + j ] . red = 255 * table [ i ] [ j ] ; } } }
update the the grid following the simple fundamental rules
1) Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.
update the the grid following the simple fundamental rules 1 ) Any live cell with fewer than two live neighbors dies as if caused by underpopulation .
//for checking the conditions //unsigned char value = 0; // //looking at a 3x3 grid checking for conditions //if value is positive then yes and update neighbors //update for correct calculation and application of rules //new life is created or extinguished by the rules //update matrix //either 255 or 0