Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int next_generation(int lives, char firstGen[][DIM_COL+2],char nextGen[][DIM_COL+2]){
- int r,c;
- int i,j;
- for(r=1;r<=DIM_ROW;r++){
- for(c=1;c<=DIM_COL;c++) {
- int liveCount=0; //counts the number of live cells
- for(i=r-1;i<i+3;i++){
- for(j=c-1;j<j+3;j++){
- if(firstGen[i][j]==LIFE){
- liveCount++;
- }
- }
- }
- if(firstGen[r][c] == LIFE){
- liveCount -= 1; //remove the original live cell as it is not a neighbour
- if(liveCount<2 || liveCount>3){
- nextGen[r][c] = DEAD;
- lives--;
- }
- } else { // firstGen[r][c] is DEAD
- if(liveCount == 3){
- nextGen[r][c] = LIFE;
- lives++;
- }
- }
- }
- }
- return lives;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement