Advertisement
Guest User

Untitled

a guest
May 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. neighbours(int grid[x][y])
  2. {
  3. /*
  4. find out if neighbours are on or off
  5. add up the number of neighbours that are on
  6. /*
  7.  
  8. int alive, dead;
  9. int i, j;
  10.  
  11. alive = dead = 0;
  12.  
  13. for(j=y-1; j<=y+1; j++){
  14. for(i=x-1; i<=x+1; i++){
  15.  
  16. if(i != miny && grid[i][j]==on){
  17. alive=alive+1;
  18. }
  19. else{dead=dead+1;
  20. }
  21. }
  22.  
  23. if(i != minx && grid[i][j]==on){
  24. alive=alive+1;
  25. }
  26. else{dead=dead+1;
  27. }
  28. }
  29.  
  30.  
  31. return(alive);
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement