From 444f3c2be7783e501942c5a1efe3a6bd6bde4811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=C3=A9o?= Date: Thu, 30 May 2024 10:09:17 +0200 Subject: [PATCH 1/3] # WARNING: head commit changed in the meantime Merge branch 'master' of https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git --- src/backend/Simulator.java | 49 ++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 8cbb0b1..795a360 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -11,8 +11,8 @@ public class Simulator extends Thread { private MyInterface mjf; - private final int COL_NUM = 100; - private final int LINE_NUM = 100; + private int COL_NUM = 100; + private int LINE_NUM = 100; private final int LIFE_TYPE_NUM = 4; //Conway Radius : 1 private final int LIFE_AREA_RADIUS = 1; @@ -66,14 +66,6 @@ public class Simulator extends Thread { return LINE_NUM; } - public int[] getBirthRulesArray() { - return this.birthRulesArray; - } - - public int[] getSurvivalRulesArray() { - return this.survivalRulesArray; - } - public void loadRule(ArrayList row) { String surviveRulesRow = row.get(0); String[] surviveCells = surviveRulesRow.split(";"); @@ -101,11 +93,17 @@ public class Simulator extends Thread { survivalRulesArray[x] = value; } //determines the number of alive neighboring cells needed to survive, and places them in the surviveCells list - } + } } + public int[] getBirthRulesArray() { + return this.birthRulesArray; + } + public int[] getSurvivalRulesArray() { + return this.survivalRulesArray; + } //Should probably stay as is @@ -156,11 +154,27 @@ public class Simulator extends Thread { } - /*public void setWorld(int[][] world, int width, int height) { + public void setWorld(int[][] world, int width, int height) { this.world = world; this.COL_NUM = width; this.LINE_NUM = height; - }*/ + } + + private boolean shouldSurvive(int aliveNeighbors) { + for (int value : getSurvivalRulesArray()) { + if ( value == aliveNeighbors) { + return true; + } + }return false; + } + + private boolean shouldBeBorn(int aliveNeighbors) { + for(int value : getBirthRulesArray()) { + if (value == aliveNeighbors) { + return true; + } + }return false; + } @@ -205,19 +219,18 @@ public class Simulator extends Thread { for (int y = 0; y < getHeight(); y++) { int aliveNeighbors = countAliveNeighbors(x, y); if (getCell(x, y) == 1) { - //newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0; + newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0; } else { - //newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0; + newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0; } } } - //setWorld(newWorld, getWidth(), getHeight()); + setWorld(newWorld, getWidth(), getHeight()); } - - //world = newWorld; + From a6f75c507c6cbd6a73b8d56d143439988b37ceae Mon Sep 17 00:00:00 2001 From: laure Date: Thu, 30 May 2024 10:13:27 +0200 Subject: [PATCH 2/3] wolf clikCell --- src/backend/Agent.java | 2 +- src/backend/Simulator.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backend/Agent.java b/src/backend/Agent.java index bc71b36..9a8cc1c 100644 --- a/src/backend/Agent.java +++ b/src/backend/Agent.java @@ -33,7 +33,7 @@ public abstract class Agent { // Does whatever the agent does during a step // then returns a boolean // if false, agent dies at end of turn - // see step function in Simulator + // see step function in Simulator public abstract boolean liveTurn(ArrayList neighbors, Simulator world); diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 795a360..4e63b76 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -79,7 +79,6 @@ public class Simulator extends Thread { System.out.println("wrong file buddy, this one's empty"); }else if(surviveCells.length<=0) { System.out.println("wrong file buddy, this one's does not have survival rules, won't work"); - return; }else { for (int x = 0; x < birthCells.length; x++) { String elem = birthCells[x]; @@ -295,8 +294,8 @@ public class Simulator extends Thread { } else if (clickActionFlag==2) { // wolf ArrayList nearby=getNeighboringAnimals(x,y,1); if (nearby.isEmpty()) { - Sheep sheep = new Sheep(x,y); - agents.add(sheep); + Wolf wolf = new Wolf(x,y); + agents.add(wolf); }else { for (Agent animal:nearby) { agents.remove(animal); From 2005ffc98490d74451de613bc1429fae4e6b796b Mon Sep 17 00:00:00 2001 From: laure Date: Thu, 30 May 2024 11:11:45 +0200 Subject: [PATCH 3/3] idk --- src/backend/Simulator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 4e63b76..14199f4 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -11,8 +11,8 @@ public class Simulator extends Thread { private MyInterface mjf; - private int COL_NUM = 100; - private int LINE_NUM = 100; + private int COL_NUM = 10; + private int LINE_NUM = 10; private final int LIFE_TYPE_NUM = 4; //Conway Radius : 1 private final int LIFE_AREA_RADIUS = 1;