import 'package:rules_of_living/src/Rule.dart'; class Cell { bool state; bool nextState = false; List surviveRules = new List(); List birthRules = new List(); /// For determining if render updates are necessary in [Grid].render() function bool dirty = false; Cell([bool state = false]) : this.state = state; // Sets the actual state to what it should be next update // Returns the newly assumed actual state of the cell. bool advanceState() { this.state = this.nextState; this.nextState = false; this.dirty = true; return this.state; } void update(int neighbors) { if (state == true) { surviveRules.forEach((Rule rule) { if (rule.evaluate(neighbors) == true) this.nextState = true; }); } else { birthRules.forEach((Rule rule) { if (rule.evaluate(neighbors) == true) this.nextState = true; }); } } }