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; } }