Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • das.s/tp3
  • f19002502/tp3
  • r17010960/tp3
  • l19004806/tp3
  • y19010055/tp3
  • o18034026/tp3
  • z18029613/tp3
  • p19021289/tp3
  • d19027596/tp3
  • f18010428/tp3
  • f19003868/tp3
  • c19022214/tp3
  • c19017929/tp3
  • m16014784/tp3
  • a19028956/tp3
  • c19026071/tp3
  • h18008908/tp3
17 results
Select Git revision
  • master
1 result
Show changes
Commits on Source (1)
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.*;
import java.util.concurrent.Callable;
/**
* {@code Grid} instances represent the grid in <i>The Game of Life</i>.
......@@ -97,30 +95,113 @@ public class Grid implements Iterable<Cell> {
goToNextState(calculateNextStates());
}
private boolean[][] calculateNextStates() {
return null;
boolean [][] MyMatrice=new boolean [numberOfRows][numberOfColumns];
for(int i=0; i<numberOfRows;i++){
for (int j=0; j<numberOfColumns;j++){
MyMatrice[i][j]= calculateNextState(i,j);
}
}
private boolean calculateNextState(int rowIndex, int columnIndex, Cell cell) {
return MyMatrice; }
private boolean calculateNextState(int rowIndex, int columnIndex) {
int alive=countAliveNeighbours(rowIndex, columnIndex);
Cell c=getCell(rowIndex,columnIndex);
if (c.isAlive()){
if ((alive == 2) || (alive == 3)){
return true;
}
else{
return false;
}
}
else {
if(alive == 3){
return true;
}
else{
return false;
}
}
}
private int countAliveNeighbours(int rowIndex, int columnIndex) {
return 0;
List<Cell> neighbours = getNeighbours(rowIndex, columnIndex);
int count=0;
for (Cell i: neighbours) {
if (i.isAlive()) {
count++;
}
}
return count;
}
private List<Cell> getNeighbours(int rowIndex, int columnIndex) {
return null;
List<Cell> voisines = new ArrayList<>();
Cell c = getCell(rowIndex,columnIndex);
voisines.add(c);
Cell v1=getCell(rowIndex-1,columnIndex-1);
voisines.add(v1);
Cell v2=getCell(rowIndex-1,columnIndex);
voisines.add(v2);
Cell v3=getCell(rowIndex-1,columnIndex+1);
voisines.add(v3);
Cell v4=getCell(rowIndex,columnIndex-1);
voisines.add(v4);
Cell v5=getCell(rowIndex,columnIndex+1);
voisines.add(v5);
Cell v6=getCell(rowIndex+1,columnIndex-1);
voisines.add(v6);
Cell v7=getCell(rowIndex+1,columnIndex);
voisines.add(v7);
Cell v8=getCell(rowIndex+1,columnIndex+1);
voisines.add(v8);
return voisines;
}
private void goToNextState(boolean[][] nextState) {
nextState=calculateNextStates();
for (int i=0;i<numberOfRows;i++){
for(int j=0;j<numberOfColumns;j++){
if(nextState[i][j]==true){
cells[i][j].setAlive();
}
else{
cells[i][j].setDead();
}
}
}
}
/**
* Sets all {@link Cell}s in this {@code Grid} as dead.
*/
void clear() {
for(int i=0;i<numberOfRows;i++){
for(int j=0;j<numberOfColumns;j++){
cells[i][j].setDead();
}
}
}
/**
......@@ -131,6 +212,20 @@ public class Grid implements Iterable<Cell> {
*/
void randomGeneration(Random random) {
boolean b;
for(int i=0;i<numberOfRows;i++){
for(int j=0;j<numberOfColumns;j++){
b= random.nextBoolean();
if(b){
cells[i][j].setAlive();
}
else{
cells[i][j].setDead();
}
}
}
}
}