Le code de la art 1 marche!!

This commit is contained in:
yoyom 2024-05-14 17:22:43 +02:00
parent 063937a5e0
commit fe2f80d27c
1 changed files with 21 additions and 12 deletions

View File

@ -46,8 +46,11 @@ public class Simulator extends Thread {
//Default rule : Survive always, birth never
//for(int i =0; i<9; i++) {
// fieldSurviveValues.add(i); }
for(int i =0; i<9; i++) {
fieldSurviveValues.add(2);
fieldSurviveValues.add(3);
fieldBirthValues.add(3);
}
}
@ -170,12 +173,19 @@ public class Simulator extends Thread {
*/
public void clickCell(int x, int y) {
if (clickActionFlag) {
Agent newAgent = new Sheep(x, y); // we consider that the new agent created is a sheep
agents.add(newAgent);
}
for (int i = 0; i < agents.size(); i++) {
Agent agent = agents.get(i);
if (agent.getX() == x && agent.getY() == y && agent instanceof Sheep) {
agents.remove(i);
return;
}
}
Agent newAgent = new Sheep(x, y);
agents.add(newAgent);
}
else {
grid[x][y] = (grid[x][y] == 0) ? 1 : 0; // 0=dead and 1=alive
}
grid[x][y] = (grid[x][y] == 0) ? 1 : 0;
}
}
/**
@ -320,7 +330,7 @@ public class Simulator extends Thread {
}
public void toggleClickAction() {
clickActionFlag = !clickActionFlag;
clickActionFlag =! clickActionFlag;
}
/**
@ -333,10 +343,8 @@ public class Simulator extends Thread {
*/
public ArrayList<String> getRule() {
ArrayList<String> rules = new ArrayList<>();
rules.add("1"); // Rule 1: Any live cell with fewer than two live neighbours dies
rules.add("2;3"); // Rule 2: Any live cell with two or three live neighbours will live
rules.add("4"); // Rule 3: Any live cell with more than three live neighbours dies
rules.add("3"); // Rule 4: Any dead cell with exactly three live neighbours becomes alive
rules.add("2;3");
rules.add("3");
return rules;
}
@ -397,6 +405,7 @@ public class Simulator extends Thread {
* used by label in interface to show the active click action
* @return String representation of click action
*/
public String clickActionName() {
return clickActionFlag ? "sheep" : "cell";
}