optimized code for agents

This commit is contained in:
Guillaume LE CHARTIER 2024-05-29 11:38:13 +02:00
parent 68ff872248
commit d591e83bca
1 changed files with 8 additions and 10 deletions

View File

@ -225,29 +225,27 @@ public class Simulator extends Thread {
if (agents.get(i).getX() == x && agents.get(i).getY() == y ){
agents.remove(i);
System.out.println("Corresponding agent found, proceeding with removal");
System.out.println(agents.size());
removal = true;
}
}
if(i==agents.size() && removal ==false){
//if we find no corresponding agent after the for loop, we add one
System.out.println("no agents to remove, proceeding with creation");
setSheep(x, y);
if (enableLogs) {
System.out.println("clickAgent Called, Agent created at: " + x + "," + y + "");
}
}
}
else{
System.out.println("1st iteration");
else{
setSheep(x,y);
if (enableLogs) {
System.out.println("clickAgent Called, Agent created at: " + x + "," + y + "");
}
}
if (enableLogs) {
System.out.println("clickAgent Called, Agent created at: " + x + "," + y + "");
}
}
}