From 6b7e8edb28bab6495fbc75c11be0805949811dfe Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 6 Jul 2018 16:46:30 +0200 Subject: [PATCH] Fix Cell Propagation through intermediate Step the next targeted state is first propagated to all Cells, then they all adopt their new states at once. --- lib/Cell.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Cell.dart b/lib/Cell.dart index 5528492..d9344ff 100644 --- a/lib/Cell.dart +++ b/lib/Cell.dart @@ -2,22 +2,26 @@ import 'package:rules_of_living/Rule.dart'; class Cell { bool state; + bool nextState = false; List surviveRules = new List(); List birthRules = new List(); Cell([bool state = false]) : this.state = state; + void advanceState() { + this.state = this.nextState; + this.nextState = false; + } + void update(int neighbors) { - bool newState = false; if (state == true) { surviveRules.forEach( (Rule rule) { - if(rule.evaluate(neighbors) == true) newState = true; + if(rule.evaluate(neighbors) == true) this.nextState = true; }); } else { birthRules.forEach((Rule rule) { - if (rule.evaluate(neighbors) == true) newState = true; + if (rule.evaluate(neighbors) == true) this.nextState = true; }); } - this.state = newState; } }