Merge branch 'master' of https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
commit
410a3be1f6
|
|
@ -25,7 +25,6 @@ public class Simulator extends Thread {
|
||||||
private boolean loopingBorder;
|
private boolean loopingBorder;
|
||||||
private boolean clickActionFlag;
|
private boolean clickActionFlag;
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
private int[][] grid;
|
|
||||||
private int[][] world;
|
private int[][] world;
|
||||||
|
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
|
@ -118,22 +117,7 @@ public class Simulator extends Thread {
|
||||||
// in agent classes
|
// 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<>();
|
ArrayList<Agent> newAgents = new ArrayList<>();
|
||||||
|
|
@ -142,12 +126,13 @@ public class Simulator extends Thread {
|
||||||
this.getNeighboringAnimals(
|
this.getNeighboringAnimals(
|
||||||
agent.getX(),
|
agent.getX(),
|
||||||
agent.getY(),
|
agent.getY(),
|
||||||
ANIMAL_AREA_RADIUS);
|
ANIMAL_AREA_RADIUS);}
|
||||||
if(!agent.liveTurn(
|
//if(!agent.liveTurn(
|
||||||
neighbors,
|
// neighbors,
|
||||||
this)) {
|
// this)) {
|
||||||
agents.remove(agent);
|
// agents.remove(agent);
|
||||||
}
|
//{
|
||||||
|
|
||||||
}
|
}
|
||||||
//then evolution of the field
|
//then evolution of the field
|
||||||
// TODO : apply game rule to all cells of the field
|
// TODO : apply game rule to all cells of the field
|
||||||
|
|
@ -168,19 +153,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
|
* leave this as is
|
||||||
|
|
@ -233,7 +205,7 @@ public class Simulator extends Thread {
|
||||||
ArrayList<Agent> inArea = new ArrayList<Agent>();
|
ArrayList<Agent> inArea = new ArrayList<Agent>();
|
||||||
for(int i=0;i<agents.size();i++) {
|
for(int i=0;i<agents.size();i++) {
|
||||||
Agent agent = agents.get(i);
|
Agent agent = agents.get(i);
|
||||||
if(agent.isInArea(x,y,radius)) {
|
if(agent.isInArea(x , y , radius)) {
|
||||||
inArea.add(agent);
|
inArea.add(agent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -257,8 +229,20 @@ public class Simulator extends Thread {
|
||||||
* the simulated world in its present state
|
* the simulated world in its present state
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> getSaveState() {
|
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
|
//TODO : complete method with proper return
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue