# WARNING: head commit changed in the meantime
Merge branch 'master' of https://gitarero.ecam.fr/laure.bel/OOP_F3_Project.git
This commit is contained in:
parent
2d7b199765
commit
5e1edab424
|
|
@ -29,6 +29,8 @@ public class Simulator extends Thread {
|
|||
private int clickActionFlag;
|
||||
private int loopDelay = 150;
|
||||
private int[][] world;
|
||||
private int [] survivalRulesArray;
|
||||
private int[] birthRulesArray;
|
||||
|
||||
//TODO : add missing attribute(s)
|
||||
private int stepCount;
|
||||
|
|
@ -64,6 +66,48 @@ public class Simulator extends Thread {
|
|||
return LINE_NUM;
|
||||
}
|
||||
|
||||
public int[] getBirthRulesArray() {
|
||||
return this.birthRulesArray;
|
||||
}
|
||||
|
||||
public int[] getSurvivalRulesArray() {
|
||||
return this.survivalRulesArray;
|
||||
}
|
||||
|
||||
public void loadRule(ArrayList<String> row) {
|
||||
String surviveRulesRow = row.get(0);
|
||||
String[] surviveCells = surviveRulesRow.split(";");
|
||||
String birthRulesRow = row.get(1);
|
||||
String[] birthCells = birthRulesRow.split(";");
|
||||
survivalRulesArray = new int[surviveCells.length];
|
||||
birthRulesArray = new int[birthCells.length];
|
||||
|
||||
|
||||
if (row.size() <= 0) {
|
||||
System.out.println("wrong file buddy, this one's empty");
|
||||
}else if(surviveCells.length<=0) {
|
||||
System.out.println("wrong file buddy, this one's does not have survival rules, won't work");
|
||||
return;
|
||||
}else {
|
||||
for (int x = 0; x < birthCells.length; x++) {
|
||||
String elem = birthCells[x];
|
||||
int value = Integer.parseInt(elem);
|
||||
birthRulesArray[x] = value;
|
||||
}
|
||||
//determines the number of alive neighboring cells needed to birth, and places them in the birthCells list
|
||||
for (int x = 0; x < surviveCells.length; x++) {
|
||||
String elem = surviveCells[x];
|
||||
int value = Integer.parseInt(elem);
|
||||
survivalRulesArray[x] = value;
|
||||
}
|
||||
//determines the number of alive neighboring cells needed to survive, and places them in the surviveCells list
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Should probably stay as is
|
||||
public void run() {
|
||||
stepCount=0;
|
||||
|
|
@ -112,6 +156,13 @@ public class Simulator extends Thread {
|
|||
}
|
||||
|
||||
|
||||
/*public void setWorld(int[][] world, int width, int height) {
|
||||
this.world = world;
|
||||
this.COL_NUM = width;
|
||||
this.LINE_NUM = height;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
public void makeStep() {
|
||||
// agent behaviors first
|
||||
|
|
@ -120,8 +171,6 @@ public class Simulator extends Thread {
|
|||
// in agent classes
|
||||
|
||||
|
||||
int[][] newWorld = new int[getWidth()][getHeight()];
|
||||
|
||||
ArrayList<Agent> newAgents = new ArrayList<>();
|
||||
for(Agent agent : agents) {
|
||||
ArrayList<Agent> neighbors =
|
||||
|
|
@ -137,7 +186,7 @@ public class Simulator extends Thread {
|
|||
|
||||
|
||||
// Apply Game of Life rules
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
/*for (int x = 0; x < getWidth(); x++) {
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
int aliveNeighbors = countAliveNeighbors(x, y);
|
||||
if (world[x][y] == 1) {
|
||||
|
|
@ -147,14 +196,34 @@ public class Simulator extends Thread {
|
|||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
int[][] newWorld = new int[getWidth()][getHeight()];
|
||||
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
int aliveNeighbors = countAliveNeighbors(x, y);
|
||||
if (getCell(x, y) == 1) {
|
||||
//newWorld[x][y] = shouldSurvive(aliveNeighbors) ? 1 : 0;
|
||||
} else {
|
||||
//newWorld[x][y] = shouldBeBorn(aliveNeighbors) ? 1 : 0;
|
||||
}
|
||||
world = newWorld;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//setWorld(newWorld, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//world = newWorld;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//then evolution of the field
|
||||
// TODO : apply game rule to all cells of the field
|
||||
|
||||
|
|
@ -303,12 +372,7 @@ public class Simulator extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called by button, with slider providing the argument
|
||||
* makes a new world state with random cell states
|
||||
* @param chanceOfLife the chance for each cell
|
||||
* to be alive in new state
|
||||
*/
|
||||
|
||||
public ArrayList<String> getRule() { //to check
|
||||
ArrayList<String> rule = new ArrayList<>();
|
||||
for (int i = 0; i < getHeight(); i++) {
|
||||
|
|
@ -323,35 +387,7 @@ public class Simulator extends Thread {
|
|||
}
|
||||
return rule;
|
||||
}
|
||||
public void loadRule(ArrayList<String> lines) { //to check
|
||||
/*
|
||||
* First some checks that the file is usable
|
||||
* We call early returns in conditions like this
|
||||
* "Guard clauses", as they guard the method
|
||||
* against unwanted inputs
|
||||
*/
|
||||
if(lines.size()<=0) {
|
||||
return;
|
||||
}
|
||||
String firstLine = lines.get(0);
|
||||
String[] firstLineElements = firstLine.split(";");
|
||||
if(firstLineElements.length<=0) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* now we fill in the world
|
||||
* with the content of the file
|
||||
*/
|
||||
for(int y =0; y<lines.size();y++) {
|
||||
String line = lines.get(y);
|
||||
String[] lineElements = line.split(";");
|
||||
for(int x=0; x<lineElements.length;x++) {
|
||||
String elem = lineElements[x];
|
||||
int value = Integer.parseInt(elem);
|
||||
setCell(x, y, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void generateRandom(float chanceOfLife) {
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue