From a34eeb44fa49a38817de25b29ae47687bd491fd6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o?= <mat.comti@gmail.com>
Date: Thu, 8 Oct 2020 19:58:58 +0200
Subject: [PATCH] getNeighbours done countAliveNeighbours done
 calculateNextState done calculateNextStates done

---
 Grid.java | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/Grid.java b/Grid.java
index 10a03b8..ed6ef3b 100644
--- a/Grid.java
+++ b/Grid.java
@@ -1,5 +1,8 @@
 import java.util.*;
 
+import static com.sun.tools.doclint.Entity.ne;
+import static com.sun.tools.doclint.Entity.or;
+
 /**
  * {@code Grid} instances represent the grid in <i>The Game of Life</i>.
  */
@@ -95,11 +98,22 @@ public class Grid implements Iterable<Cell> {
     }
 
     private boolean[][] calculateNextStates() {
-        return null;
+        boolean[][] nextStates = new boolean[numberOfRows][numberOfColumns];
+        for (Cell cell : this) {
+            for (int i = 0; i == numberOfRows - 1; i++) {
+                for (int j = 0; j == numberOfColumns - 1; j++) {
+                    nextStates[i][j] = calculateNextState(i, j, cell);
+                }
+            }
+        }
+        return nextStates;
     }
 
     private boolean calculateNextState(int rowIndex, int columnIndex, Cell cell) {
-	return false;
+        if (cell.isAlive()) {
+            return (countAliveNeighbours(rowIndex, columnIndex) == 2) || (countAliveNeighbours(rowIndex, columnIndex) == 3);
+        }
+        else return false;
     }
 
     private int countAliveNeighbours(int rowIndex, int columnIndex) {
@@ -125,6 +139,11 @@ public class Grid implements Iterable<Cell> {
     }
 
     private void goToNextState(boolean[][] nextState) {
+        Iterator<Cell> iterator = iterator();
+        while (iterator.hasNext()) {
+            Cell cell = iterator.next();
+            cell.isAlive() = nextState[][];
+        }
     }
 
     /**
-- 
GitLab