methods cellDies and cellBorns implemented
This commit is contained in:
parent
778ae63f4e
commit
350665e641
|
|
@ -22,14 +22,15 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
private ArrayList<Agent> agents;
|
private ArrayList<Agent> agents;
|
||||||
private ArrayList<ArrayList<Cell>> cells;
|
private ArrayList<ArrayList<Cell>> cells;
|
||||||
private ArrayList<ArrayList<Integer>> newCells;
|
private ArrayList<ArrayList<Cell>> newCells;
|
||||||
|
|
||||||
private boolean stopFlag;
|
private boolean stopFlag;
|
||||||
private boolean pauseFlag;
|
private boolean pauseFlag;
|
||||||
private boolean loopingBorder;
|
private boolean loopingBorder;
|
||||||
private boolean clickActionFlag;
|
private boolean clickActionFlag;
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
|
|
||||||
|
//Rules rule = new Rules();
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
|
||||||
public Simulator(MyInterface mjfParam) {
|
public Simulator(MyInterface mjfParam) {
|
||||||
|
|
@ -39,7 +40,7 @@ public class Simulator extends Thread {
|
||||||
loopingBorder=false;
|
loopingBorder=false;
|
||||||
clickActionFlag=false;
|
clickActionFlag=false;
|
||||||
cells = new ArrayList<ArrayList<Cell>>();
|
cells = new ArrayList<ArrayList<Cell>>();
|
||||||
newCells = new ArrayList<ArrayList<Integer>>();
|
newCells = new ArrayList<ArrayList<Cell>>();
|
||||||
|
|
||||||
agents = new ArrayList<Agent>();
|
agents = new ArrayList<Agent>();
|
||||||
fieldBirthValues = new ArrayList<Integer>();
|
fieldBirthValues = new ArrayList<Integer>();
|
||||||
|
|
@ -58,10 +59,11 @@ public class Simulator extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int x=0; x <= getWidth();x++) {
|
for(int x=0; x <= getWidth();x++) {
|
||||||
ArrayList<Integer> arrayNewCell = new ArrayList<Integer>(); //initialize first dimension with ArrayLists
|
ArrayList<Cell> arrayNewCell = new ArrayList<Cell>(); //initialize first dimension with ArrayLists
|
||||||
newCells.add(arrayNewCell);
|
newCells.add(arrayNewCell);
|
||||||
for(int y=0; y <= getHeight(); y++) {
|
for(int y=0; y <= getHeight(); y++) {
|
||||||
newCells.get(x).add(0); //assign dead cell to its position in second dimension array
|
Cell newCell = new Cell(0); //create a dead cell
|
||||||
|
newCells.get(x).add(newCell); //assign dead cell to its position in second dimension array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,18 +115,18 @@ public class Simulator extends Thread {
|
||||||
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
|
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
|
||||||
|
|
||||||
if(aliveNeighbors < 2 || aliveNeighbors > 3) {
|
if(aliveNeighbors < 2 || aliveNeighbors > 3) {
|
||||||
//setNewCell(x, y, 0);
|
setNewCell(x, y, 0);
|
||||||
newCells.get(x).set(y, 0);
|
//newCells.get(x).set(y, 0);
|
||||||
}
|
}else{setNewCell(x, y, 1);}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cellBorns(int x, int y) {
|
public void cellBorns(int x, int y) {
|
||||||
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
|
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
|
||||||
|
|
||||||
if(aliveNeighbors == 3) {
|
if(aliveNeighbors == 3) {
|
||||||
//setNewCell(x, y, 1);
|
setNewCell(x, y, 1);
|
||||||
newCells.get(x).set(y, 1);
|
//newCells.get(x).set(y, 1);
|
||||||
}
|
}else{setNewCell(x, y, 0);}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAliveNeighbors(int x, int y, int radius) {
|
public int getAliveNeighbors(int x, int y, int radius) {
|
||||||
|
|
@ -187,24 +189,13 @@ public class Simulator extends Thread {
|
||||||
//i started from 1 and ended < to ignore the borders
|
//i started from 1 and ended < to ignore the borders
|
||||||
for(int x=1; x < getWidth();x++) {
|
for(int x=1; x < getWidth();x++) {
|
||||||
for(int y=1; y < getHeight(); y++) {
|
for(int y=1; y < getHeight(); y++) {
|
||||||
|
|
||||||
int status = getCell(x,y);
|
int status = getCell(x,y);
|
||||||
|
|
||||||
if(status == 1) {
|
if(status == 1) {
|
||||||
//cellDies(x, y);
|
cellDies(x, y);
|
||||||
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
|
}else if(status == 0) {
|
||||||
|
cellBorns(x, y);
|
||||||
if(aliveNeighbors < 2 || aliveNeighbors > 3) {
|
|
||||||
//setNewCell(x, y, 0);
|
|
||||||
newCells.get(x).set(y, 0);
|
|
||||||
}else{newCells.get(x).set(y, status);}
|
|
||||||
}else if(status == 0) {
|
|
||||||
//cellBorns(x, y);
|
|
||||||
int aliveNeighbors = getAliveNeighbors(x, y, LIFE_AREA_RADIUS);
|
|
||||||
|
|
||||||
if(aliveNeighbors == 3) {
|
|
||||||
//setNewCell(x, y, 1);
|
|
||||||
newCells.get(x).set(y, 1);
|
|
||||||
}else{newCells.get(x).set(y, status);}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -272,8 +263,8 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
public int getNewCell(int x, int y) {
|
public int getNewCell(int x, int y) {
|
||||||
//TODO : complete method with proper return
|
//TODO : complete method with proper return
|
||||||
//int status = newCells.get(x).get(y).getAlive();
|
int status = newCells.get(x).get(y).getAlive();
|
||||||
int status = newCells.get(x).get(y);
|
//int status = newCells.get(x).get(y);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,9 +303,9 @@ public class Simulator extends Thread {
|
||||||
public void setCell(int x, int y, int status) {
|
public void setCell(int x, int y, int status) {
|
||||||
cells.get(x).get(y).setAlive(status);
|
cells.get(x).get(y).setAlive(status);
|
||||||
}
|
}
|
||||||
/*public void setNewCell(int x, int y, int status) {
|
public void setNewCell(int x, int y, int status) {
|
||||||
newCells.get(x).get(y).setAlive(status);
|
newCells.get(x).get(y).setAlive(status);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue