This commit is contained in:
Laure BEL 2024-05-29 17:22:36 +02:00
parent d569d9e9f3
commit 68f4106a43
2 changed files with 18 additions and 17 deletions

View File

@ -10,20 +10,12 @@ public class Rules {
public Rules() { public Rules() {
survivalRulesArray = new int[0]; //survivalRulesArray = new int[0];
birthRulesArray = new int[0]; //birthRulesArray = new int[0];
} }
//initialize my arrays to empty //initialize my arrays to empty
public int[] getBirthRulesArray() {
return this.birthRulesArray;
}
public int[] getSurvivalRulesArray() {
return this.survivalRulesArray;
}
public void loadRule(ArrayList<String> row) { public void loadRule(ArrayList<String> row) {
String surviveRulesRow = row.get(0); String surviveRulesRow = row.get(0);
@ -42,14 +34,14 @@ public class Rules {
}else { }else {
for (int x = 0; x < surviveCells.length; x++) { for (int x = 0; x < surviveCells.length; x++) {
String elem = surviveCells[x]; String eleme = surviveCells[x];
int value = Integer.parseInt(elem); int value = Integer.parseInt(eleme);
survivalRulesArray[x] = value; survivalRulesArray[x] = value;
} }
//determines the number of alive neighboring cells needed to survive, and places them in the survivalRulesArray //determines the number of alive neighboring cells needed to survive, and places them in the survivalRulesArray
for (int x = 0; x < birthCells.length; x++) { for (int x = 0; x < birthCells.length; x++) {
String elem = birthCells[x]; String elemee = birthCells[x];
int value = Integer.parseInt(elem); int value = Integer.parseInt(elemee);
birthRulesArray[x] = value; birthRulesArray[x] = value;
} }
//determines the number of alive neighboring cells needed to birth, and places them in the birthRules list //determines the number of alive neighboring cells needed to birth, and places them in the birthRules list
@ -58,5 +50,15 @@ public class Rules {
} }
public int[] getBirthRulesArray() {
return this.birthRulesArray;
}
public int[] getSurvivalRulesArray() {
return this.survivalRulesArray;
}
} }

View File

@ -178,8 +178,7 @@ public class Simulator extends Thread {
for (int y = 0; y < getHeight(); y++) { for (int y = 0; y < getHeight(); y++) {
int aliveNeighbors = countAliveNeighbors(x, y); int aliveNeighbors = countAliveNeighbors(x, y);
if (world.getCell(x, y) == 1) { if (world.getCell(x, y) == 1) {
nextWorld[x][y] = 1; nextWorld[x][y] = survives(aliveNeighbors) ? 1 : 0;
//survives(aliveNeighbors) ? 1 : 0;
} else { } else {
nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0; nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0;
} }