From 68f4106a434338add1d563b1b3e5ff5625bb99d4 Mon Sep 17 00:00:00 2001 From: laure Date: Wed, 29 May 2024 17:22:36 +0200 Subject: [PATCH 1/3] idk --- src/backend/Rules.java | 32 +++++++++++++++++--------------- src/backend/Simulator.java | 3 +-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/backend/Rules.java b/src/backend/Rules.java index 1896db0..561b4cf 100644 --- a/src/backend/Rules.java +++ b/src/backend/Rules.java @@ -10,20 +10,12 @@ public class Rules { public Rules() { - survivalRulesArray = new int[0]; - birthRulesArray = new int[0]; + //survivalRulesArray = new int[0]; + //birthRulesArray = new int[0]; } //initialize my arrays to empty - public int[] getBirthRulesArray() { - return this.birthRulesArray; - - } - - public int[] getSurvivalRulesArray() { - return this.survivalRulesArray; - - } + public void loadRule(ArrayList row) { String surviveRulesRow = row.get(0); @@ -42,14 +34,14 @@ public class Rules { }else { for (int x = 0; x < surviveCells.length; x++) { - String elem = surviveCells[x]; - int value = Integer.parseInt(elem); + String eleme = surviveCells[x]; + int value = Integer.parseInt(eleme); survivalRulesArray[x] = value; } //determines the number of alive neighboring cells needed to survive, and places them in the survivalRulesArray for (int x = 0; x < birthCells.length; x++) { - String elem = birthCells[x]; - int value = Integer.parseInt(elem); + String elemee = birthCells[x]; + int value = Integer.parseInt(elemee); birthRulesArray[x] = value; } //determines the number of alive neighboring cells needed to birth, and places them in the birthRules list @@ -58,5 +50,15 @@ public class Rules { } + + public int[] getBirthRulesArray() { + return this.birthRulesArray; + + } + + public int[] getSurvivalRulesArray() { + return this.survivalRulesArray; + + } } diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 9964506..77cef13 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -178,8 +178,7 @@ public class Simulator extends Thread { for (int y = 0; y < getHeight(); y++) { int aliveNeighbors = countAliveNeighbors(x, y); if (world.getCell(x, y) == 1) { - nextWorld[x][y] = 1; - //survives(aliveNeighbors) ? 1 : 0; + nextWorld[x][y] = survives(aliveNeighbors) ? 1 : 0; } else { nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0; } From 73662f1c0c6ae2390a36be966c472c7c9bac6a2e Mon Sep 17 00:00:00 2001 From: laure Date: Wed, 29 May 2024 17:37:56 +0200 Subject: [PATCH 2/3] try make step agent --- src/backend/Simulator.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 77cef13..e7bebb6 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -158,18 +158,12 @@ public class Simulator extends Thread { // in agent classes - /*ArrayList newAgents = new ArrayList<>(); + ArrayList newAgents = new ArrayList<>(); for(Agent agent : agents) { - ArrayList neighbors = - this.getNeighboringAnimals( - agent.getX(), - agent.getY(), - ANIMAL_AREA_RADIUS);} - if(!agent.liveTurn( - neighbors, - this)) { + ArrayList neighbors =this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS);} + if(!agent.liveTurn(neighbors,this)) { agents.remove(agent); - }*/ + } int[][] nextWorld = new int[getWidth()][getHeight()]; From 7acff3e63834ee490cf75eabeac4f1896b0ed88e Mon Sep 17 00:00:00 2001 From: laure Date: Wed, 29 May 2024 18:07:23 +0200 Subject: [PATCH 3/3] test --- src/backend/Sheep.java | 6 +++++- src/backend/Simulator.java | 25 ++++++++++++------------- src/backend/World.java | 6 +++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/backend/Sheep.java b/src/backend/Sheep.java index 3c0f302..0317fab 100644 --- a/src/backend/Sheep.java +++ b/src/backend/Sheep.java @@ -36,7 +36,11 @@ public class Sheep extends Agent { hunger++; } this.moveRandom(); - return hunger>10; + if (hunger<=10) { + return true; + }else { + return hunger>10; + } } private void moveRandom() { diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index e7bebb6..439fc03 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -16,8 +16,8 @@ public class Simulator extends Thread { private MyInterface mjf; public Rules rules; - //private final int COL_NUM = 100; - //private final int LINE_NUM = 100; + private final int COL_NUM = 100; + private final int LINE_NUM = 100; private final int LIFE_TYPE_NUM = 4; //Conway Radius : 1 private final int LIFE_AREA_RADIUS = 1; @@ -66,11 +66,11 @@ public class Simulator extends Thread { } public int getWidth() { - return world.getWidth(); + return this.getWidth(); } public int getHeight() { - return world.getHeight(); + return this.getHeight(); } public World getActualWorld(){ @@ -160,13 +160,15 @@ public class Simulator extends Thread { ArrayList newAgents = new ArrayList<>(); for(Agent agent : agents) { - ArrayList neighbors =this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS);} - if(!agent.liveTurn(neighbors,this)) { + /*ArrayList neighbors =this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS);} + */ + System.out.println("makeStep Called"); + if(!agent.liveTurn(this.getNeighboringAnimals(agent.getX(),agent.getY(),ANIMAL_AREA_RADIUS),world)) { agents.remove(agent); } - + } - int[][] nextWorld = new int[getWidth()][getHeight()]; + /*int[][] nextWorld = new int[getWidth()][getHeight()]; for (int x = 0; x < getWidth(); x++) { for (int y = 0; y < getHeight(); y++) { @@ -182,7 +184,7 @@ public class Simulator extends Thread { world.setWorld(nextWorld, getWidth(), getHeight()); } - + */ //then evolution of the field @@ -203,10 +205,7 @@ public class Simulator extends Thread { */ - - - - + } /* * leave this as is diff --git a/src/backend/World.java b/src/backend/World.java index 3c1cfe9..121df0b 100644 --- a/src/backend/World.java +++ b/src/backend/World.java @@ -3,9 +3,9 @@ package backend; import java.util.Random; public class World { - - private int width; - private int height; + Simulator simulator; + private int width = simulator.getWidth(); + private int height = simulator.getHeight(); private int[][] world; public World(int width, int height) {