Application of the loaded rule for surviving and being born

This commit is contained in:
l.dupuis-burtin 2024-05-29 00:40:04 +02:00
parent 868da2b221
commit f8dc94ec80
1 changed files with 6 additions and 5 deletions

View File

@ -29,7 +29,8 @@ public class Simulator extends Thread {
private boolean loopingBorder;
private boolean clickActionFlag;
private int loopDelay = 150;
private ArrayList<Integer> ruleSurviveCriteria= new ArrayList<Integer>() ;
private ArrayList<Integer> ruleBirthCriteria=new ArrayList<Integer>() ;
//Rules rule = new Rules();
//TODO : add missing attribute(s)
@ -114,7 +115,7 @@ public class Simulator extends Thread {
public void cellDies(int x, int y) {
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
if(aliveNeighbors < 2 || aliveNeighbors > 3) {
if(aliveNeighbors < ruleSurviveCriteria.get(0) || aliveNeighbors > ruleSurviveCriteria.get(1)) {
setNewCell(x, y, 0);
//newCells.get(x).set(y, 0);
}else{setNewCell(x, y, 1);}
@ -123,7 +124,7 @@ public class Simulator extends Thread {
public void cellBorns(int x, int y) {
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
if(aliveNeighbors == 3) {
if(aliveNeighbors == ruleBirthCriteria.get(0)) {
setNewCell(x, y, 1);
//newCells.get(x).set(y, 1);
}else{setNewCell(x, y, 0);}
@ -457,14 +458,14 @@ public class Simulator extends Thread {
String elem = surviveElements[x];
int value = Integer.parseInt(elem);
//TODO : add value to possible survive values
ruleSurviveCriteria.add(value);
}
String[] birthElements = birthLine.split(";");
for(int x=0; x<birthElements.length;x++) {
String elem = birthElements[x];
int value = Integer.parseInt(elem);
//TODO : add value to possible birth values
ruleBirthCriteria.add(value);
}
}