From 127cc64841e369caeeb8117310dbe42cc55648b8 Mon Sep 17 00:00:00 2001 From: laure Date: Wed, 29 May 2024 18:55:07 +0200 Subject: [PATCH 1/4] now realy uptodate --- src/backend/Simulator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 6450bde..4f7a38b 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -198,7 +198,15 @@ public class Simulator extends Thread { * method called when clicking on a cell in the interface */ public void clickCell(int x, int y) { - setCell(x, y, getCell(x, y) == 1 ? 0 : 1); + if (clickActionFlag==0) { // cell + setCell(x, y, getCell(x, y) == 1 ? 0 : 1); + } else if (clickActionFlag==1) { // sheep + Sheep sheep = new Sheep(x,y); + agents.add(sheep); + } else if (clickActionFlag==2) { // wolf + Wolf wolf = new Wolf(x,y); + agents.add(wolf); + } } From d39dd5d90e3fdfc4ea803b2a05b4e0104082315a Mon Sep 17 00:00:00 2001 From: laure Date: Wed, 29 May 2024 19:43:55 +0200 Subject: [PATCH 2/4] load and save agent --- Rule/BlobRule.csv | 2 +- src/backend/Simulator.java | 55 +++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Rule/BlobRule.csv b/Rule/BlobRule.csv index 10f61a6..922060c 100644 --- a/Rule/BlobRule.csv +++ b/Rule/BlobRule.csv @@ -1,2 +1,2 @@ 1;3;5;8 -3;5;7; +3;5;7 diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 4f7a38b..dba94a7 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -129,11 +129,11 @@ public class Simulator extends Thread { agent.getX(), agent.getY(), ANIMAL_AREA_RADIUS);} - //if(!agent.liveTurn( - // neighbors, - //this)) { - //agents.remove(agent); - //{ + /*if(!agent.liveTurn( + neighbors, + this)) { + agents.remove(agent); + {*/ // Apply Game of Life rules @@ -415,23 +415,46 @@ public class Simulator extends Thread { public ArrayList getAgentsSave() { - ArrayList agentsSave = new ArrayList<>(); - for (int j = 0; j < getHeight(); j++) { - StringBuilder lineState = new StringBuilder(); - for (int i = 0 ; i < getWidth() ; i++) { - lineState.append(getCell(i, j)); - if (j < getHeight() -1) { - lineState.append(","); - } + ArrayList agentsList = new ArrayList(); + String sheepLine = "1,"; + String wolfLine = "2,"; + for (Agent agent : agents) { + int x = agent.getX(); + int y = agent.getY(); + if (agent instanceof Sheep) + { + sheepLine = sheepLine + x + ";" + y + ","; + } + else if (agent instanceof Wolf) + { + wolfLine = wolfLine + x + ";" + y + ","; } - agentsSave.add(lineState.toString()); } - return agentsSave; + agentsList.add(sheepLine); + agentsList.add(wolfLine); + return agentsList; } public void loadAgents(ArrayList stringArray) { //TODO : Same idea as other load methods, but for agent list - + for(int y =0; y Date: Wed, 29 May 2024 19:44:09 +0200 Subject: [PATCH 3/4] test 1 agent --- Agents/test1 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Agents/test1 diff --git a/Agents/test1 b/Agents/test1 new file mode 100644 index 0000000..9519474 --- /dev/null +++ b/Agents/test1 @@ -0,0 +1,2 @@ +1,46;17,61;17,57;33, +2, From 381d12f02160a7856a9fe909070ceba504c98f1b Mon Sep 17 00:00:00 2001 From: laure Date: Wed, 29 May 2024 19:50:37 +0200 Subject: [PATCH 4/4] can delete agent went click on it --- src/backend/Simulator.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index dba94a7..4990fa4 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -201,11 +201,25 @@ public class Simulator extends Thread { if (clickActionFlag==0) { // cell setCell(x, y, getCell(x, y) == 1 ? 0 : 1); } else if (clickActionFlag==1) { // sheep - Sheep sheep = new Sheep(x,y); - agents.add(sheep); + ArrayList nearby=getNeighboringAnimals(x,y,1); //look if the cell has an agent + if (nearby.isEmpty()) { + Sheep sheep = new Sheep(x,y); + agents.add(sheep); + }else { + for (Agent animal:nearby) { + agents.remove(animal); + } + } } else if (clickActionFlag==2) { // wolf - Wolf wolf = new Wolf(x,y); - agents.add(wolf); + ArrayList nearby=getNeighboringAnimals(x,y,1); + if (nearby.isEmpty()) { + Sheep sheep = new Sheep(x,y); + agents.add(sheep); + }else { + for (Agent animal:nearby) { + agents.remove(animal); + } + } } }