ajout d'un null agent

This commit is contained in:
Guillaume LE CHARTIER 2024-05-28 14:54:32 +02:00
parent 99fb4fdb02
commit 184c5bd759
2 changed files with 26 additions and 3 deletions

14
src/backend/NullAgent Normal file
View File

@ -0,0 +1,14 @@
package backend;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;
//null agent that signifies the absence of agents
public class NullAgent extends Agent {
NullAgent(int x,int y){
super(x,y,Color.black);
}
}

View File

@ -71,7 +71,14 @@ public class Simulator extends Thread {
}
//we define the initial size of the arraylist as 1 in order to ease the code in the clickAgent part
public void StartingCap(int initialCapacity){
// Initial capacity of the agent arraylist
initialCapacity = COL_NUM*LINE_NUM;
agents = new ArrayList<>(initialCapacity);
//we fill it with null values
for (int i = 0; i <= agents.size(); i++) {
agents.add(i,NullAgent.NullAgent);
}
System.out.println(agents);
}
//Should probably stay as is
public void run() {
@ -206,15 +213,17 @@ public class Simulator extends Thread {
else {
int radius = 1;
Agent agent = new Sheep(x,y);
System.out.println(agents);
if(agent.isInArea(x,y,radius)){
System.out.println("true");
for(int i=0;i<=agents.size();i++){
if (agents.get(i) instanceof Sheep){
agents.remove(i);
System.out.println("Corresponding agent found, proceeding with removal");
}
else{
setSheep(x,y);
System.out.println("Corresponding agent not found, proceeding with creation");
}
}
}