This commit is contained in:
Timéo 2024-05-30 12:00:44 +02:00
parent 444f3c2be7
commit 042db3f31c
3 changed files with 56 additions and 23 deletions

View File

@ -1,2 +1,2 @@
1;3;5;8
3;5;7
"1;3;5;8"
"3;5;7"

1 1;3;5;8
2 3;5;7

View File

@ -1,2 +1,2 @@
2;3
"2;3"
3
1 2;3
2 3

View File

@ -29,8 +29,10 @@ public class Simulator extends Thread {
private int clickActionFlag;
private int loopDelay = 150;
private int[][] world;
private int [] survivalRulesArray;
private int[] birthRulesArray;
//private int[] survivalRulesArray;
//private int[] birthRulesArray;
private int[] birthRulesArrays;
private int[] surviveRulesArrays;
//TODO : add missing attribute(s)
private int stepCount;
@ -67,42 +69,73 @@ public class Simulator extends Thread {
}
public void loadRule(ArrayList<String> row) {
String surviveRulesRow = row.get(0);
String surviveRulesRow = row.get(0).replace("\"","").trim();
String[] surviveCells = surviveRulesRow.split(";");
String birthRulesRow = row.get(1);
String birthRulesRow = row.get(1).replace("\"","").trim();
String[] birthCells = birthRulesRow.split(";");
survivalRulesArray = new int[surviveCells.length];
birthRulesArray = new int[birthCells.length];
this.birthRulesArrays = new int[birthCells.length];
this.surviveRulesArrays = new int[surviveCells.length];
if (row.size() <= 0) {
System.out.println("wrong file buddy, this one's empty");
}else if(surviveCells.length<=0) {
}else if(row.size() <= 0) {
System.out.println("wrong file buddy, this one's does not have survival rules, won't work");
return;
}else {
for (int x = 0; x < birthCells.length; x++) {
String elem = birthCells[x];
try {
for (int x = 0; x < surviveCells.length; x++) {
String elem = surviveCells[x].trim();
int value = Integer.parseInt(elem);
birthRulesArray[x] = value;
surviveRulesArrays[x] = value;
}
for (int x = 0; x < birthCells.length; x++) {
String elem = birthCells[x].trim();
int value = Integer.parseInt(elem);
birthRulesArrays[x] = value;
}
System.out.println("Rules loaded successfully");
} catch (NumberFormatException e) {
System.out.println("Error parsing rule values: " + e.getMessage());
}
}
/*for (int x = 0; x < birthCells.length; x++) {
String[] birthElements = birthCells[x].split(",");
int[] birthRulesArray = new int[birthElements.length];
for (int y = 0; y < birthElements.length; y++) {
String elem = birthElements[y];
int value = Integer.parseInt(elem);
birthRulesArray[y] = value;
}
this.birthRulesArrays[x] = birthRulesArray;
System.out.println("birth rule taken into account");
}
//determines the number of alive neighboring cells needed to birth, and places them in the birthCells list
for (int x = 0; x < surviveCells.length; x++) {
String elem = surviveCells[x];
String[] surviveElements = surviveCells[x].split(",");
int[] surviveArray = new int[surviveElements.length];
for (int y = 0; y < surviveElements.length; y++) {
String elem = surviveElements[y];
int value = Integer.parseInt(elem);
survivalRulesArray[x] = value;
surviveArray[y] = value;
}
this.surviveRulesArrays[x] = surviveArray;
System.out.println("survival rule taken into account");
}*/
//determines the number of alive neighboring cells needed to survive, and places them in the surviveCells list
}
}
public int[] getBirthRulesArray() {
return this.birthRulesArray;
return this.birthRulesArrays;
}
public int[] getSurvivalRulesArray() {
return this.survivalRulesArray;
return this.surviveRulesArrays;
}