From 84d0a890b74d90aa3516740ec9f30908dfa46e10 Mon Sep 17 00:00:00 2001 From: benoi Date: Mon, 27 May 2024 13:08:42 +0200 Subject: [PATCH] Get Rule done ig --- src/backend/Simulator.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index f2c71d0..826f85c 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -301,6 +301,20 @@ public class Simulator extends Thread { * @param chanceOfLife the chance for each cell * to be alive in new state */ + public ArrayList getRule() { //to check + ArrayList rule = new ArrayList<>(); + for (int i = 0; i < getHeight(); i++) { + StringBuilder lineState = new StringBuilder(); + for (int j = 0 ; j < getHeight() ; j++) { + lineState.append(getCell(i, j)); + if (j < getWidth() - 1) { + lineState.append(";"); + } + } + rule.add(lineState.toString()); + } + return rule; + } public void generateRandom(float chanceOfLife) { //TODO : complete method /* @@ -348,12 +362,7 @@ public class Simulator extends Thread { * @return File content as an ArrayList of Lines (String) * @see loadRule for inverse process */ - public ArrayList getRule() { - //TODO : complete method with proper return - - return null; - } - + public void loadRule(ArrayList lines) { if(lines.size()<=0) { System.out.println("empty rule file");