Advertisement
Guest User

abrala

a guest
Apr 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. bool underpopulation (bool M[][n], int i, int j)
  2. {
  3. int cont=0;
  4.  
  5. if (M[i-1][j-1])
  6. cont++;
  7. if (M[i-1][j])
  8. cont++;
  9. if (M[i-1][j+1])
  10. cont++;
  11. if (M[i][j-1])
  12. cont++;
  13. if (M[i][j+1])
  14. cont++;
  15. if (M[i+1][j-1])
  16. cont++;
  17. if (M[i+1][j])
  18. cont++;
  19. if (M[i+1][j+1])
  20. cont++;
  21.  
  22. if(cont < 2)
  23. return true;
  24.  
  25. return false;
  26. }
  27.  
  28. bool overpopulation (bool M[][n], int i, int j)
  29. {
  30. int cont=0;
  31.  
  32. if (M[i-1][j-1])
  33. cont++;
  34. if (M[i-1][j])
  35. cont++;
  36. if (M[i-1][j+1])
  37. cont++;
  38. if (M[i][j-1])
  39. cont++;
  40. if (M[i][j+1])
  41. cont++;
  42. if (M[i+1][j-1])
  43. cont++;
  44. if (M[i+1][j])
  45. cont++;
  46. if (M[i+1][j+1])
  47. cont++;
  48.  
  49. if(cont > 3)
  50. return true;
  51.  
  52. return false;
  53. }
  54.  
  55.  
  56. bool reproduction (bool M[][n], int i, int j)
  57. {
  58. int cont=0;
  59.  
  60. if (M[i-1][j-1])
  61. cont++;
  62. if (M[i-1][j])
  63. cont++;
  64. if (M[i-1][j+1])
  65. cont++;
  66. if (M[i][j-1])
  67. cont++;
  68. if (M[i][j+1])
  69. cont++;
  70. if (M[i+1][j-1])
  71. cont++;
  72. if (M[i+1][j])
  73. cont++;
  74. if (M[i+1][j+1])
  75. cont++;
  76.  
  77. if(cont == 3)
  78. return true;
  79.  
  80. return false;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement