non working getSaveState+randomfield
This commit is contained in:
parent
123b4f6adf
commit
9ba015829d
|
|
@ -1,6 +1,6 @@
|
|||
package backend;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.Random;
|
||||
import windowInterface.MyInterface;
|
||||
//import backend.Rules;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ public class Simulator extends Thread {
|
|||
|
||||
//TODO : add missing attribute initialization
|
||||
|
||||
ruleSurviveCriteria.add(2);//initializing system with conway rule
|
||||
ruleSurviveCriteria.add(2);//initializing system with Conway rule
|
||||
ruleSurviveCriteria.add(3);
|
||||
ruleBirthCriteria.add(3);
|
||||
//initialize grid with dead cells
|
||||
|
|
@ -354,7 +354,22 @@ public class Simulator extends Thread {
|
|||
*/
|
||||
public ArrayList<String> getSaveState() {
|
||||
//TODO : complete method with proper return
|
||||
return null;
|
||||
//We need to create an array of strings
|
||||
//each string should be the sum of all int transformed to strings in each Arrays of int
|
||||
ArrayList<String> arrayLines=new ArrayList<String>();
|
||||
for(int x=0;x<getWidth();x++) {
|
||||
String sumElementToLine="";
|
||||
for(int y=0;y<getHeight();y++) {
|
||||
sumElementToLine+=(Integer.toString(getCell(x, y)));
|
||||
if(y<getHeight()-1) {
|
||||
sumElementToLine+=";";
|
||||
}
|
||||
}
|
||||
arrayLines.add(sumElementToLine);
|
||||
//System.out.println(sumElementToLine.length());
|
||||
}
|
||||
//System.out.println(arrayLines);
|
||||
return arrayLines;
|
||||
}
|
||||
/**
|
||||
*
|
||||
|
|
@ -398,6 +413,18 @@ public class Simulator extends Thread {
|
|||
*/
|
||||
public void generateRandom(float chanceOfLife) {
|
||||
//TODO : complete method
|
||||
Random ran= new Random();
|
||||
for (int x=0;x<getWidth();x++){
|
||||
for (int y=0;y<getHeight();y++) {
|
||||
if (ran.nextFloat()<=chanceOfLife) {
|
||||
setCell(x, y, 1);
|
||||
}else {
|
||||
setCell(x, y, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Advice :
|
||||
* as you should probably have a separate class
|
||||
|
|
@ -486,25 +513,7 @@ public class Simulator extends Thread {
|
|||
|
||||
public void loadAgents(ArrayList<String> stringArray) {
|
||||
//TODO : Same idea as other load methods, but for agent list
|
||||
if(stringArray.size()<=0) {
|
||||
System.out.println("empty agents file");
|
||||
return;
|
||||
}
|
||||
//TODO : remove previous rule (=emptying lists)
|
||||
|
||||
|
||||
|
||||
for(int x=0; x<stringArray.size();x++) {
|
||||
String agentsLine = stringArray.get(x);
|
||||
String[] agentsElements = agentsLine.split(";");
|
||||
int[] agentsValues = new int[3];
|
||||
for(int i=0; i<agentsElements.length;i++) {
|
||||
agentsValues[i]= Integer.parseInt(agentsElements[i]);
|
||||
}
|
||||
if(agentsValues[2]==1) {
|
||||
agents.add(new Sheep(agentsValues[0], agentsValues[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue