startSimulation work for all size of world

This commit is contained in:
Laure BEL 2024-05-30 11:50:56 +02:00
parent 61e6b7a42a
commit fba8069874
1 changed files with 13 additions and 5 deletions

View File

@ -183,19 +183,25 @@ public class Simulator extends Thread {
// to modify agent behavior, see liveTurn method
// in agent classes
ArrayList<Agent> newAgents = new ArrayList<>();
for (int i = agents.size() - 1; i >= 0; i--) {
Agent agent = agents.get(i);
ArrayList<Agent> neighbors = this.getNeighboringAnimals(agent.getX(), agent.getY(), ANIMAL_AREA_RADIUS);
if (!agent.liveTurn(neighbors, this)) {
agents.remove(i);
}
}
/*ArrayList<Agent> newAgents = new ArrayList<>();
for(Agent agent : agents) {
ArrayList<Agent> neighbors =
this.getNeighboringAnimals(
agent.getX(),
agent.getY(),
ANIMAL_AREA_RADIUS);}
/*if(!agent.liveTurn(
if(!agent.liveTurn(
neighbors,
this)) {
agents.remove(agent);
{*/
}*/
// Apply Game of Life rules
@ -570,8 +576,10 @@ public class Simulator extends Thread {
public void startSimulation() {
if (isWorldEmpty()) {
if (isWorldEmpty() & getWidth()==100 & getHeight()==100) {
mjf.clicLoadFileButtonCSV("World/baseworld.csv");
}else {
mjf.generateRandomBoard();
}