Merge branch 'master' of https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
commit
61e6b7a42a
|
|
@ -11,8 +11,8 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
private MyInterface mjf;
|
private MyInterface mjf;
|
||||||
|
|
||||||
private final int COL_NUM = 100;
|
private int COL_NUM = 10;
|
||||||
private final int LINE_NUM = 100;
|
private int LINE_NUM = 10;
|
||||||
private final int LIFE_TYPE_NUM = 4;
|
private final int LIFE_TYPE_NUM = 4;
|
||||||
//Conway Radius : 1
|
//Conway Radius : 1
|
||||||
private final int LIFE_AREA_RADIUS = 1;
|
private final int LIFE_AREA_RADIUS = 1;
|
||||||
|
|
@ -66,14 +66,6 @@ public class Simulator extends Thread {
|
||||||
return LINE_NUM;
|
return LINE_NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getBirthRulesArray() {
|
|
||||||
return this.birthRulesArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getSurvivalRulesArray() {
|
|
||||||
return this.survivalRulesArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadRule(ArrayList<String> row) {
|
public void loadRule(ArrayList<String> row) {
|
||||||
String surviveRulesRow = row.get(0);
|
String surviveRulesRow = row.get(0);
|
||||||
String[] surviveCells = surviveRulesRow.split(";");
|
String[] surviveCells = surviveRulesRow.split(";");
|
||||||
|
|
@ -87,7 +79,6 @@ public class Simulator extends Thread {
|
||||||
System.out.println("wrong file buddy, this one's empty");
|
System.out.println("wrong file buddy, this one's empty");
|
||||||
}else if(surviveCells.length<=0) {
|
}else if(surviveCells.length<=0) {
|
||||||
System.out.println("wrong file buddy, this one's does not have survival rules, won't work");
|
System.out.println("wrong file buddy, this one's does not have survival rules, won't work");
|
||||||
return;
|
|
||||||
}else {
|
}else {
|
||||||
for (int x = 0; x < birthCells.length; x++) {
|
for (int x = 0; x < birthCells.length; x++) {
|
||||||
String elem = birthCells[x];
|
String elem = birthCells[x];
|
||||||
|
|
@ -105,7 +96,13 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public int[] getBirthRulesArray() {
|
||||||
|
return this.birthRulesArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getSurvivalRulesArray() {
|
||||||
|
return this.survivalRulesArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Should probably stay as is
|
//Should probably stay as is
|
||||||
|
|
@ -156,11 +153,27 @@ public class Simulator extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*public void setWorld(int[][] world, int width, int height) {
|
public void setWorld(int[][] world, int width, int height) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.COL_NUM = width;
|
this.COL_NUM = width;
|
||||||
this.LINE_NUM = height;
|
this.LINE_NUM = height;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
private boolean shouldSurvive(int aliveNeighbors) {
|
||||||
|
for (int value : getSurvivalRulesArray()) {
|
||||||
|
if ( value == aliveNeighbors) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldBeBorn(int aliveNeighbors) {
|
||||||
|
for(int value : getBirthRulesArray()) {
|
||||||
|
if (value == aliveNeighbors) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -205,19 +218,18 @@ public class Simulator extends Thread {
|
||||||
for (int y = 0; y < getHeight(); y++) {
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
int aliveNeighbors = countAliveNeighbors(x, y);
|
int aliveNeighbors = countAliveNeighbors(x, y);
|
||||||
if (getCell(x, y) == 1) {
|
if (getCell(x, y) == 1) {
|
||||||
//newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0;
|
newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0;
|
||||||
} else {
|
} else {
|
||||||
//newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0;
|
newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//setWorld(newWorld, getWidth(), getHeight());
|
setWorld(newWorld, getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//world = newWorld;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -282,8 +294,8 @@ public class Simulator extends Thread {
|
||||||
} else if (clickActionFlag==2) { // wolf
|
} else if (clickActionFlag==2) { // wolf
|
||||||
ArrayList<Agent> nearby=getNeighboringAnimals(x,y,1);
|
ArrayList<Agent> nearby=getNeighboringAnimals(x,y,1);
|
||||||
if (nearby.isEmpty()) {
|
if (nearby.isEmpty()) {
|
||||||
Sheep sheep = new Sheep(x,y);
|
Wolf wolf = new Wolf(x,y);
|
||||||
agents.add(sheep);
|
agents.add(wolf);
|
||||||
}else {
|
}else {
|
||||||
for (Agent animal:nearby) {
|
for (Agent animal:nearby) {
|
||||||
agents.remove(animal);
|
agents.remove(animal);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue