agent implementation in progress

This commit is contained in:
Guillaume LE CHARTIER 2024-05-22 11:51:28 +02:00
parent 7ba8160e2b
commit 65fe9efa34
4 changed files with 56 additions and 8 deletions

View File

@ -23,6 +23,17 @@ public abstract class Agent {
public int getY() {
return y;
}
//presence of an agent at those coordinates
public boolean agentPresence(int x, int y){
if (this.getX() == x && this.getY() == y) {
return true;
}
else {
return false;
}
}
public boolean isInArea(int x, int y, int radius) {
int diffX = this.x-x;
int diffY = this.y-y;

View File

@ -3,7 +3,6 @@ package backend;
public class Cell {
private int value;
public Cell(int value) {
this.value = value;
}
@ -12,12 +11,7 @@ public class Cell {
return value;
}
public void setValue(int value) {
this.value = value;
}
}

View File

@ -1,4 +1,5 @@
package backend;
import java.awt.Color;
import java.util.ArrayList;
import windowInterface.MyInterface;
@ -448,7 +449,7 @@ public class Simulator extends Thread {
* @return String representation of click action
*/
public String clickActionName() {
// TODO : initially return "sheep" or "cell"
// TODO-COMPLETE : initially return "sheep" or "cell"
// depending on clickActionFlag
if (clickActionFlag){
return "cell";
@ -458,4 +459,47 @@ public class Simulator extends Thread {
}
}
//TODO-INPROGRESS : set agent (x y agent) load an agent to coordinates x,y
public void setSheep(int x,int y){
Sheep sheep = new Sheep(x,y);
agents.add(sheep);
printAgents();
}
//method for clickAgent first setup to spawn sheeps
public void clickAgent(int x, int y) {
if (clickActionFlag == false) {
Sheep sheep = new Sheep(x,y);
this.setSheep(x,y);
//process to check if there is already an agent (removes the agent if clicking on it)
//if (agentPresence(x,y) == true) {
//}
if (enableLogs) {
System.out.println("clickAgent Called, Agent spawned at coordinates:" + x + "," + y + "");
}
}
else {
return;
}
}
public void printAgents() {
for (Agent agent : agents) {
String agentType = agent.getClass().getSimpleName();
int x = agent.getX();
int y = agent.getY();
Color color = agent.getDisplayColor();
System.out.println("Agent Type: " + agentType);
System.out.println("Position: (" + x + ", " + y + ")");
System.out.println("Color: " + color);
System.out.println();
}
}
}

View File

@ -90,7 +90,6 @@ public class Table {
}
//TODO : set agent (x y agent) load an agent to coordinates x,y
//TODO : set random (density) create a random table of determined density
public void setRandom(double density) {