saveState and rule methods
This commit is contained in:
parent
770828e42d
commit
4e024f0a74
|
|
@ -213,8 +213,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() {
|
||||||
//TODO : complete method with proper return
|
ArrayList<String> saveState = new ArrayList<>();
|
||||||
return null;
|
|
||||||
|
for (int y = 0; y < LINE_NUM; y++) {
|
||||||
|
StringBuilder line = new StringBuilder();
|
||||||
|
for (int x = 0; x < COL_NUM; x++) {
|
||||||
|
line.append(grid[x][y]);
|
||||||
|
if (x < COL_NUM - 1) {
|
||||||
|
line.append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveState.add(line.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveState;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -294,9 +306,12 @@ public class Simulator extends Thread {
|
||||||
* @see loadRule for inverse process
|
* @see loadRule for inverse process
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> getRule() {
|
public ArrayList<String> getRule() {
|
||||||
//TODO : complete method with proper return
|
ArrayList<String> rules = new ArrayList<>();
|
||||||
|
rules.add("1"); // Rule 1: Any live cell with fewer than two live neighbours dies
|
||||||
return null;
|
rules.add("2;3"); // Rule 2: Any live cell with two or three live neighbours will live
|
||||||
|
rules.add("4"); // Rule 3: Any live cell with more than three live neighbours dies
|
||||||
|
rules.add("3"); // Rule 4: Any dead cell with exactly three live neighbours becomes alive
|
||||||
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadRule(ArrayList<String> lines) {
|
public void loadRule(ArrayList<String> lines) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue