From ac78093dfc44be2e3aaeb8e4bc514e97101a976d Mon Sep 17 00:00:00 2001 From: benoi Date: Tue, 28 May 2024 09:37:48 +0200 Subject: [PATCH] load rule --- src/backend/Simulator.java | 55 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/backend/Simulator.java b/src/backend/Simulator.java index ca12683..c01f8a5 100644 --- a/src/backend/Simulator.java +++ b/src/backend/Simulator.java @@ -322,6 +322,36 @@ public class Simulator extends Thread { } return rule; } + public void loadRule(ArrayList 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) { - if(lines.size()<=0) { - System.out.println("empty rule file"); - return; - } - //TODO : remove previous rule (=emptying lists) + - String surviveLine = lines.get(0); - String birthLine = lines.get(1); - String[] surviveElements = surviveLine.split(";"); - for(int x=0; x getAgentsSave() { //TODO : Same idea as the other save method, but for agents return null;