Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. int next_generation(int lives, char firstGen[][DIM_COL+2],char nextGen[][DIM_COL+2]){
  2. int r,c;
  3. int i,j;
  4. for(r=1;r<=DIM_ROW;r++){
  5. for(c=1;c<=DIM_COL;c++) {
  6. int liveCount=0; //counts the number of live cells
  7. for(i=r-1;i<i+3;i++){
  8. for(j=c-1;j<j+3;j++){
  9. if(firstGen[i][j]==LIFE){
  10. liveCount++;
  11. }
  12. }
  13. }
  14.  
  15. if(firstGen[r][c] == LIFE){
  16. liveCount -= 1; //remove the original live cell as it is not a neighbour
  17. if(liveCount<2 || liveCount>3){
  18. nextGen[r][c] = DEAD;
  19. lives--;
  20. }
  21. } else { // firstGen[r][c] is DEAD
  22. if(liveCount == 3){
  23. nextGen[r][c] = LIFE;
  24. lives++;
  25. }
  26. }
  27. }
  28. }
  29. return lives;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement