Skip to content
Snippets Groups Projects
Commit 41c69169 authored by arthur's avatar arthur
Browse files

correction de la methode getNeighbour qui donnait un mauvais nombre de voisin...

correction de la methode getNeighbour qui donnait un mauvais nombre de voisin (9) et correction de la méthode calculateNextState
parent 05541007
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,7 @@ public class Grid implements Iterable<Cell> { ...@@ -107,7 +107,7 @@ public class Grid implements Iterable<Cell> {
private boolean calculateNextState(int rowIndex, int columnIndex, Cell cell) { private boolean calculateNextState(int rowIndex, int columnIndex, Cell cell) {
int aliveNeighbours = countAliveNeighbours(rowIndex, columnIndex); int aliveNeighbours = countAliveNeighbours(rowIndex, columnIndex);
if (cell.isAlive()) { if (cell.isAlive()) {
return aliveNeighbours > 1 && aliveNeighbours < 4; return aliveNeighbours >= 2 && aliveNeighbours <= 3;
} }
return aliveNeighbours == 3; return aliveNeighbours == 3;
} }
...@@ -127,7 +127,7 @@ public class Grid implements Iterable<Cell> { ...@@ -127,7 +127,7 @@ public class Grid implements Iterable<Cell> {
List<Cell> cells = new ArrayList<>(); List<Cell> cells = new ArrayList<>();
for (int i = rowIndex - 1; i <= rowIndex + 1; i++) { for (int i = rowIndex - 1; i <= rowIndex + 1; i++) {
for (int j = columnIndex - 1; j <= columnIndex + 1; j++) { for (int j = columnIndex - 1; j <= columnIndex + 1; j++) {
if (i != rowIndex && j != columnIndex || i > 0 && j > 0 && i < getNumberOfRows() && j < getNumberOfColumns()) if ((!(i == rowIndex && j == columnIndex)) && i > 0 && j > 0 && i < getNumberOfRows() && j < getNumberOfColumns())
cells.add(getCell(i, j)); cells.add(getCell(i, j));
} }
} }
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment