diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index a9c7743..0e326be 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -133,21 +133,21 @@ public class Simulator extends Thread { return count; } -// private boolean survives(int aliveNeighbors) { -// for (int value : rules.getSuvivalRulesArray()) { -// if ( value == aliveNeighbors) { -// return true; -// } -// } -// } + private boolean survives (int aliveNeighbors) { + for (int value : rules.getSurvivalRulesArray()) { + if ( value == aliveNeighbors) { + return true; + } + }return false; + } -// private boolean bornes(int aliveNeighbors) { -// for(int value : rules.getBirthRulesArray()) { -// if (value == aliveNeighbors) { -// return true; -// } -// } -// } + private boolean bornes(int aliveNeighbors) { + for(int value : rules.getBirthRulesArray()) { + if (value == aliveNeighbors) { + return true; + } + }return false; + } @@ -158,8 +158,6 @@ public class Simulator extends Thread { // in agent classes - int[][] newWorld = new int[getWidth()][getHeight()]; - /*ArrayList newAgents = new ArrayList<>(); for(Agent agent : agents) { ArrayList neighbors = @@ -174,23 +172,21 @@ public class Simulator extends Thread { }*/ - // 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; - // } - // } - //} - - - + int[][] nextWorld = new int[getWidth()][getHeight()]; + for (int x = 0; x < getWidth(); x++) { + for (int y = 0; y < getHeight(); y++) { + int aliveNeighbors = countAliveNeighbors(x, y); + if (world.getCell(x, y) == 1) { + nextWorld[x][y] = survives(aliveNeighbors) ? 1 : 0; + } else { + nextWorld[x][y] = bornes(aliveNeighbors) ? 1 : 0; + } + } + } - //world = newWorld; + world.setWorld(nextWorld, getWidth(), getHeight()); + } @@ -212,7 +208,7 @@ public class Simulator extends Thread { * then the cell becomes alive */ - } +