Skip to content
Snippets Groups Projects
Commit a34eeb44 authored by Mattéo's avatar Mattéo
Browse files

getNeighbours done

countAliveNeighbours done
calculateNextState done
calculateNextStates done
parent 5809143d
No related branches found
No related tags found
No related merge requests found
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[][];
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment