Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. public void step() {
  2.  
  3. for (int i = 0; i < grid.length; i++) {
  4. for (int j = 0; j < grid.length; j++) {
  5. boolean middle = grid[i][j];
  6. int num = 0;
  7.  
  8. if (middle = false) {
  9. if (i - 1 < 0) {
  10.  
  11. } else if (grid[i - 1][j]) {
  12. num++;
  13. }
  14.  
  15. if (j - 1 < 0) {
  16.  
  17. } else if (grid[i][j - 1]) {
  18. num++;
  19. }
  20.  
  21. if (i + 1 >= 20) {
  22.  
  23. } else if (grid[i + 1][j]) {
  24. num++;
  25. }
  26.  
  27. if (j + 1 >= 20) {
  28.  
  29. } else if (grid[i][j + 1]) {
  30. num++;
  31. }
  32.  
  33. if (i - 1 < 0 || j + 1 >= 20) {
  34.  
  35. } else if (grid[i - 1][j + 1]) {
  36. num++;
  37. }
  38. if (i - 1 < 0 || j - 1 < 0) {
  39.  
  40. } else if (grid[i - 1][j - 1]) {
  41. num++;
  42. }
  43. if (i + 1 >= 20 || j + 1 >= 20) {
  44.  
  45. } else if (grid[i + 1][j + 1]) {
  46. num++;
  47. }
  48. if (i + 1 >= 20 || j - 1 < 0) {
  49.  
  50. } else if (grid[i + 1][j - 1]) {
  51. num++;
  52. }
  53.  
  54. if (num == 3) {
  55. grid[i][j] = true;
  56. }
  57. } else if (middle = true) {
  58. if (i - 1 < 0) {
  59.  
  60. } else if (grid[i - 1][j]) {
  61. num++;
  62. }
  63.  
  64. if (j - 1 < 0) {
  65.  
  66. } else if (grid[i][j - 1]) {
  67. num++;
  68. }
  69.  
  70. if (i + 1 >= 20) {
  71.  
  72. } else if (grid[i + 1][j]) {
  73. num++;
  74. }
  75.  
  76. if (j + 1 >= 20) {
  77.  
  78. } else if (grid[i][j + 1]) {
  79. num++;
  80. }
  81. if (i - 1 < 0 || j + 1 >= 20) {
  82.  
  83. } else if (grid[i - 1][j + 1]) {
  84. num++;
  85. }
  86. if (i - 1 < 0 || j - 1 < 0) {
  87.  
  88. } else if (grid[i - 1][j - 1]) {
  89. num++;
  90. }
  91. if (i + 1 >= 20 || j + 1 >= 20) {
  92.  
  93. } else if (grid[i + 1][j + 1]) {
  94. num++;
  95. }
  96. if (i + 1 >= 20 || j - 1 < 0) {
  97.  
  98. } else if (grid[i + 1][j - 1]) {
  99. num++;
  100. }
  101. if (num == 1 || num == 0 || num >= 4) {
  102. grid[i][j] = false;
  103. } else if (num == 2 || num == 3) {
  104. grid[i][j] = true;
  105. }
  106. }
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement