# WARNING: head commit changed in the meantime

Merge branch 'master' of
https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
Timéo 2024-05-30 10:09:17 +02:00
parent 65d2baabfd
commit 444f3c2be7
1 changed files with 31 additions and 18 deletions

View File

@ -11,8 +11,8 @@ public class Simulator extends Thread {
private MyInterface mjf;
private final int COL_NUM = 100;
private final int LINE_NUM = 100;
private int COL_NUM = 100;
private int LINE_NUM = 100;
private final int LIFE_TYPE_NUM = 4;
//Conway Radius : 1
private final int LIFE_AREA_RADIUS = 1;
@ -66,14 +66,6 @@ public class Simulator extends Thread {
return LINE_NUM;
}
public int[] getBirthRulesArray() {
return this.birthRulesArray;
}
public int[] getSurvivalRulesArray() {
return this.survivalRulesArray;
}
public void loadRule(ArrayList<String> row) {
String surviveRulesRow = row.get(0);
String[] surviveCells = surviveRulesRow.split(";");
@ -105,7 +97,13 @@ public class Simulator extends Thread {
}
public int[] getBirthRulesArray() {
return this.birthRulesArray;
}
public int[] getSurvivalRulesArray() {
return this.survivalRulesArray;
}
//Should probably stay as is
@ -156,11 +154,27 @@ public class Simulator extends Thread {
}
/*public void setWorld(int[][] world, int width, int height) {
public void setWorld(int[][] world, int width, int height) {
this.world = world;
this.COL_NUM = width;
this.LINE_NUM = height;
}*/
}
private boolean shouldSurvive(int aliveNeighbors) {
for (int value : getSurvivalRulesArray()) {
if ( value == aliveNeighbors) {
return true;
}
}return false;
}
private boolean shouldBeBorn(int aliveNeighbors) {
for(int value : getBirthRulesArray()) {
if (value == aliveNeighbors) {
return true;
}
}return false;
}
@ -205,19 +219,18 @@ public class Simulator extends Thread {
for (int y = 0; y < getHeight(); y++) {
int aliveNeighbors = countAliveNeighbors(x, y);
if (getCell(x, y) == 1) {
//newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0;
newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0;
} else {
//newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0;
newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0;
}
}
}
//setWorld(newWorld, getWidth(), getHeight());
setWorld(newWorld, getWidth(), getHeight());
}
//world = newWorld;