diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index 777d704..25f0938 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -24,7 +24,6 @@ public class Simulator extends Thread { private boolean loopingBorder; private boolean clickActionFlag; private int loopDelay = 150; - private int[][] grid; private int[][] world; //TODO : add missing attribute(s) @@ -115,22 +114,7 @@ public class Simulator extends Thread { // in agent classes - int[][] newWorld = new int[getWidth()][getHeight()]; - // Apply Game of Life rules - for (int x = 0; x < getWidth(); x++) { - for (int y = 0; y < getHeight(); y++) { - int aliveNeighbors = countAliveNeighbors(x, y); - if (world[x][y] == 1) { - newWorld[x][y] = (aliveNeighbors < 2 || aliveNeighbors > 3) ? 0 : 1; - } else { - newWorld[x][y] = (aliveNeighbors == 3) ? 1 : 0; - } - } - } - - - world = newWorld; ArrayList newAgents = new ArrayList<>(); @@ -139,12 +123,13 @@ public class Simulator extends Thread { this.getNeighboringAnimals( agent.getX(), agent.getY(), - ANIMAL_AREA_RADIUS); - if(!agent.liveTurn( - neighbors, - this)) { - agents.remove(agent); - } + ANIMAL_AREA_RADIUS);} + //if(!agent.liveTurn( + // neighbors, + // this)) { + // agents.remove(agent); + //{ + } //then evolution of the field // TODO : apply game rule to all cells of the field @@ -165,19 +150,6 @@ public class Simulator extends Thread { - for (int x = 0; x < getWidth(); x++) { - for (int y = 0; y < getHeight(); y++) { - int aliveNeighbors = countAliveNeighbors(x, y); - if (world[x][y] == 1) { - newWorld[x][y] = (aliveNeighbors < 2 || aliveNeighbors > 3) ? 0 : 1; - } else { - newWorld[x][y] = (aliveNeighbors == 3) ? 1 : 0; - } - } - } - - - } /* * leave this as is @@ -230,7 +202,7 @@ public class Simulator extends Thread { ArrayList inArea = new ArrayList(); for(int i=0;i getSaveState() { + ArrayList saveState = new ArrayList<>(); + for (int i = 0; i < getHeight(); i++) { + StringBuilder lineState = new StringBuilder(); + for (int j = 0 ; j < getHeight() ; j++) { + lineState.append(getCell(i, j)); + if (j < getWidth() - 1) { + lineState.append(";"); + } + } + saveState.add(lineState.toString()); + } + return saveState; + //TODO : complete method with proper return - return null; } /** *