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

---
 .idea/.gitignore  |  2 ++
 .idea/misc.xml    |  6 ++++++
 .idea/modules.xml |  8 ++++++++
 .idea/vcs.xml     |  6 ++++++
 Grid.java         | 22 ++++++++++++++++------
 Main.java         |  2 +-
 TP3.iml           | 11 +++++++++++
 7 files changed, 50 insertions(+), 7 deletions(-)
 create mode 100644 .idea/.gitignore
 create mode 100644 .idea/misc.xml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/vcs.xml
 create mode 100644 TP3.iml

diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..e7e9d11
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..1763e15
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..3d411e5
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/TP3.iml" filepath="$PROJECT_DIR$/TP3.iml" />
+    </modules>
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/Grid.java b/Grid.java
index 939e05f..10a03b8 100644
--- a/Grid.java
+++ b/Grid.java
@@ -1,7 +1,4 @@
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
 
 /**
  * {@code Grid} instances represent the grid in <i>The Game of Life</i>.
@@ -106,12 +103,25 @@ public class Grid implements Iterable<Cell> {
     }
 
     private int countAliveNeighbours(int rowIndex, int columnIndex) {
-        return 0;
+        int aliveNeighbours = 0;
+        for (Cell cell : getNeighbours(rowIndex,columnIndex)) {
+            if (cell.isAlive()) {aliveNeighbours++;}
+        }
+        return aliveNeighbours;
     }
 
 
     private List<Cell> getNeighbours(int rowIndex, int columnIndex) {
-	return null;
+        List<Cell> neighbours = new ArrayList<>();
+        neighbours.add(getCell(rowIndex-1,columnIndex-1));
+        neighbours.add(getCell(rowIndex,columnIndex-1));
+        neighbours.add(getCell(rowIndex+1,columnIndex-1));
+        neighbours.add(getCell(rowIndex-1,columnIndex));
+        neighbours.add(getCell(rowIndex+1,columnIndex));
+        neighbours.add(getCell(rowIndex-1,columnIndex+1));
+        neighbours.add(getCell(rowIndex,columnIndex+1));
+        neighbours.add(getCell(rowIndex+1,columnIndex+1));
+        return neighbours;
     }
 
     private void goToNextState(boolean[][] nextState) {
diff --git a/Main.java b/Main.java
index bf344ee..178b007 100644
--- a/Main.java
+++ b/Main.java
@@ -3,7 +3,7 @@ import java.awt.*;
 import javax.swing.*;
 
 public class Main{
-    public static void main(String args[]) throws IOException {
+    public static void main(String[] args) throws IOException {
 	int NUMBER_OF_ROWS = 64;
 	int NUMBER_OF_COLUMNS = 64;
 	
diff --git a/TP3.iml b/TP3.iml
new file mode 100644
index 0000000..b107a2d
--- /dev/null
+++ b/TP3.iml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
\ No newline at end of file
-- 
GitLab