Kirielson 0 Light Poster

Hello, I've checked a recent Game of Life thread and unfortunately it did not address my problem.

I'm trying to manipulate life based on how many cells have life.

I'm assuming that it's the way that I'm doing the counting that is messing up the problem but it could also be the way the rows and collums are executed.

In this code assume that

int life_counter = -1

in order to make the amount of cells that should have life ( cell_life - 1) since if all cells have life the number would equal 9 but since you're basing the number off of the neighbors it should actually be 8.

void Calc_Corner(cell_life life, int row_counter, int col_counter, int& life_counter){
	int Life_Row;
	int Life_Col;
	int temp_row_c = row_counter;
	int life_counter_holder = 0;
	if(temp_row_c == 19){
		temp_row_c = 18;
		}
	if(temp_row_c == 0){}
	else {
	return;
	}
	life_counter = life_counter;
	if(col_counter == 0){
			for(Life_Row = temp_row_c; Life_Row <= (temp_row_c + 1); Life_Row++) {
				for(Life_Col = 0; Life_Col <= 1; Life_Col++) {
					if(life[Life_Row][Life_Col] == '*'){
						life_counter_holder++;
					}
					if(life[Life_Row][Life_Col]== ' '){
					}
				}
			}
		}
		
	if(col_counter == 19){
		for(Life_Row = temp_row_c; Life_Row <= (temp_row_c + 1); Life_Row++){
			for(Life_Col = 18; Life_Col <=19; Life_Col++){
				if(life[Life_Row][Life_Col]== '*'){
					life_counter_holder++;
					}
					if(life[Life_Row][Life_Col] == ' '){
					}
				}
			}
		}
	life_counter = life_counter + life_counter_holder;
	}
	
void Calc_Row_Side(cell_life life, int row_counter, int col_counter, int& life_counter){
	int temp_row_c = row_counter;
	int Life_Row;
	int Life_Col;
	int life_counter_holder = 0;
	if(temp_row_c == 19){
		temp_row_c = 18;
		}
	if(temp_row_c == 0){}
	else {
	return;
	}
	for(Life_Row = temp_row_c; Life_Row <= (temp_row_c + 1); Life_Row++) {
		for(Life_Col = (col_counter - 1); Life_Col <= (col_counter + 1); Life_Col++) {
			if(life[Life_Row][Life_Col] == '*'){
				life_counter_holder++;
				}
			if(life[Life_Row][Life_Col]== ' '){
				}
			}
			life_counter = (life_counter_holder + life_counter);
			}
	}

void Calc_Col_Side(cell_life life, int row_counter, int col_counter, int& life_counter){
	int temp_col_c = col_counter;
	int Life_Row;
	int Life_Col;
	int life_counter_holder = 0;
	if(temp_col_c == 19){
		temp_col_c = 18;
		}
	else {
	return;
	}
	for(Life_Row = (row_counter - 1); Life_Row <= (row_counter + 1); Life_Row++) {
		for(Life_Col = temp_col_c; Life_Col <= (temp_col_c + 1); Life_Col++) {
			if(life[Life_Row][Life_Col] == '*'){
				life_counter_holder++;
				}
			}
			}
		life_counter =  life_counter_holder + life_counter;
	}

void Calc_Internal(cell_life life, int row_counter, int col_counter, int& life_counter){
int Life_Row;
int Life_Col;
int life_counter_holder = 0;
	for(Life_Row = (row_counter - 1); Life_Row <= (row_counter + 1); Life_Row++){
		for(Life_Col = (col_counter - 1); Life_Col <= (col_counter + 1); Life_Col++){
			if(life[Life_Row][Life_Col] == '*'){
			life_counter_holder++;
			}
		}
	}
	
life_counter = life_counter_holder + life_counter;

}

Please and thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.