From 45c9e8ebf88b6eb7116db2bb608260a1075d0f66 Mon Sep 17 00:00:00 2001 From: g le-chartier Date: Wed, 29 May 2024 14:19:15 +0200 Subject: [PATCH] e --- src/backend/Simulator.java | 8 +++- src/backend/Wolf | 14 ------- src/backend/Wolf.java | 58 +++++++++++++++++++++++++++++ src/windowInterface/JPanelDraw.java | 2 +- 4 files changed, 65 insertions(+), 17 deletions(-) delete mode 100644 src/backend/Wolf create mode 100644 src/backend/Wolf.java diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index becd2f7..a5aa32e 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -18,8 +18,8 @@ public class Simulator extends Thread { private MyInterface mjf; - private final int COL_NUM = 100; - private final int LINE_NUM = 100; + private final int COL_NUM = 10; + private final int LINE_NUM = 10; private final int LIFE_TYPE_NUM = 4; //Conway Radius : 1 private final int LIFE_AREA_RADIUS = 1; @@ -86,6 +86,10 @@ public class Simulator extends Thread { public ArrayList> getColorArrayList(){ return colorArrayList; } + //method to get the list of agents + public ArrayList getArrayAgent(){ + return agents; + } //Should probably stay as is public void run() { diff --git a/src/backend/Wolf b/src/backend/Wolf deleted file mode 100644 index b97bc5b..0000000 --- a/src/backend/Wolf +++ /dev/null @@ -1,14 +0,0 @@ -package backend; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.Random; - -public class Wolf extends Agent { - - int hunger; - random rand; - Wolf(int x,int y){ - super(x,y,Color.red) - } -} \ No newline at end of file diff --git a/src/backend/Wolf.java b/src/backend/Wolf.java new file mode 100644 index 0000000..16a666c --- /dev/null +++ b/src/backend/Wolf.java @@ -0,0 +1,58 @@ +package backend; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.Random; + +public class Wolf extends Agent { + + int hunger; + Random rand; + Wolf(int x,int y){ + + super(x,y,Color.red); + hunger = 0; + rand = new Random(); + } + public boolean liveTurn(ArrayList neighbors, Simulator world) { + //implement that hunger increases until the wolf is on a cell with a sheep + + //we put a condition for the behavior of the wolf depending on the presence of a sheep in the detection range + int detectionRange =3; + int eatingRange=1; + int i=0; + if (isInArea(x, y,detectionRange)){ + for(i=0;i<=world.getArrayAgent().size()-1;i++){ + + //if we proceed to find the agent, we check if it is an instance of sheep + if (world.getArrayAgent().get(i) instanceof Sheep ){ + Agent agent = new Wolf(x,y); + //if the instance of sheep is detected to be inside the detection range it will + if (world.getArrayAgent().get(i).getX()-Wolf.getX()<=detectionRange || world.getArrayAgent().get(i).getY()-Wolf.getY()<=detectionRange){ + + } + + } + } + + } + } + //move randomly if no sheep in detection range + private void moveRandom() { + int direction = rand.nextInt(4); + if(direction == 0) { + x+=1; + } + if(direction == 1) { + y+=1; + } + if(direction == 2) { + x-=1; + } + if(direction == 3) { + y-=1; + } + } + //implement a method that induce movement in the direction of the sheep in the detection range + +} \ No newline at end of file diff --git a/src/windowInterface/JPanelDraw.java b/src/windowInterface/JPanelDraw.java index c5711de..167d799 100644 --- a/src/windowInterface/JPanelDraw.java +++ b/src/windowInterface/JPanelDraw.java @@ -17,7 +17,7 @@ public class JPanelDraw extends JPanel { private Simulator mySimu; private MyInterface interfaceGlobal; ArrayList> colorArrayList; - ArrayList> colorArrayList; + public JPanelDraw(MyInterface itf) { super();