# WARNING: head commit changed in the meantime

Merge branch 'master' of
https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
Timéo 2024-05-29 16:08:34 +02:00
parent 4d7f223e9d
commit c0f524a814
1 changed files with 28 additions and 32 deletions

View File

@ -133,21 +133,21 @@ public class Simulator extends Thread {
return count;
}
// private boolean survives(int aliveNeighbors) {
// for (int value : rules.getSuvivalRulesArray()) {
// if ( value == aliveNeighbors) {
// return true;
// }
// }
// }
private boolean survives (int aliveNeighbors) {
for (int value : rules.getSurvivalRulesArray()) {
if ( value == aliveNeighbors) {
return true;
}
}return false;
}
// private boolean bornes(int aliveNeighbors) {
// for(int value : rules.getBirthRulesArray()) {
// if (value == aliveNeighbors) {
// return true;
// }
// }
// }
private boolean bornes(int aliveNeighbors) {
for(int value : rules.getBirthRulesArray()) {
if (value == aliveNeighbors) {
return true;
}
}return false;
}
@ -158,8 +158,6 @@ public class Simulator extends Thread {
// in agent classes
int[][] newWorld = new int[getWidth()][getHeight()];
/*ArrayList<Agent> newAgents = new ArrayList<>();
for(Agent agent : agents) {
ArrayList<Agent> neighbors =
@ -174,23 +172,21 @@ public class Simulator extends Thread {
}*/
// Apply Game of Life rules
//for (int x = 0; x < getWidth(); x++) {
// for (int y = 0; y < getHeight(); y++) {
// int aliveNeighbors = countAliveNeighbors(x, y);
// if (world[x][y] == 1) {
// newWorld[x][y] = (aliveNeighbors < 2 || aliveNeighbors > 3) ? 0 : 1;
// } else {
// newWorld[x][y] = (aliveNeighbors == 3) ? 1 : 0;
// }
// }
//}
int[][] nextWorld = new int[getWidth()][getHeight()];
for (int x = 0; x < getWidth(); x++) {
for (int y = 0; y < getHeight(); y++) {
int aliveNeighbors = countAliveNeighbors(x, y);
if (world.getCell(x, y) == 1) {
nextWorld[x][y] = survives(aliveNeighbors) ? 1 : 0;
} else {
nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0;
}
}
}
//world = newWorld;
world.setWorld(nextWorld, getWidth(), getHeight());
}
@ -212,7 +208,7 @@ public class Simulator extends Thread {
* then the cell becomes alive
*/
}