played a bit with the rules but no result and did the get saveState but
it deconne it loads it but at 90 degrees
This commit is contained in:
parent
be88fc0918
commit
3d5057a959
|
|
@ -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<Agent> 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
|
||||
|
|
@ -254,8 +226,20 @@ public class Simulator extends Thread {
|
|||
* the simulated world in its present state
|
||||
*/
|
||||
public ArrayList<String> getSaveState() {
|
||||
ArrayList<String> 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;
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue