fix loading rules for every size of rule

This commit is contained in:
l.dupuis-burtin 2024-05-29 10:16:50 +02:00
parent f8dc94ec80
commit 82bcd85852
1 changed files with 14 additions and 8 deletions

View File

@ -114,20 +114,26 @@ public class Simulator extends Thread {
//i put everything here for now //i put everything here for now
public void cellDies(int x, int y) { public void cellDies(int x, int y) {
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS); int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
for (int i=0;i<ruleSurviveCriteria.size();i++) {
if(aliveNeighbors == ruleSurviveCriteria.get(i)) {
setNewCell(x, y, 1);
break;
//newCells.get(x).set(y, 0);
}else{setNewCell(x, y, 0);}
}
if(aliveNeighbors < ruleSurviveCriteria.get(0) || aliveNeighbors > ruleSurviveCriteria.get(1)) {
setNewCell(x, y, 0);
//newCells.get(x).set(y, 0);
}else{setNewCell(x, y, 1);}
} }
public void cellBorns(int x, int y) { public void cellBorns(int x, int y) {
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS); int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
if(aliveNeighbors == ruleBirthCriteria.get(0)) { for (int i=0;i<ruleBirthCriteria.size();i++) {
setNewCell(x, y, 1); if(aliveNeighbors == ruleBirthCriteria.get(i)) {
//newCells.get(x).set(y, 1); setNewCell(x, y, 1);
}else{setNewCell(x, y, 0);} break;
//newCells.get(x).set(y, 0);
}else{setNewCell(x, y, 0);}
}
} }
public int getAliveNeighbors(int x, int y, int radius) { public int getAliveNeighbors(int x, int y, int radius) {