2018-07-07 14:42:30 +00:00
|
|
|
import 'package:rules_of_living/src/Rule.dart';
|
2018-07-05 15:59:11 +00:00
|
|
|
|
|
|
|
class Cell {
|
|
|
|
bool state;
|
2018-07-06 14:46:30 +00:00
|
|
|
bool nextState = false;
|
2018-07-05 15:59:11 +00:00
|
|
|
List<Rule> surviveRules = new List<Rule>();
|
|
|
|
List<Rule> birthRules = new List<Rule>();
|
|
|
|
|
|
|
|
Cell([bool state = false]) : this.state = state;
|
|
|
|
|
2018-07-06 14:46:30 +00:00
|
|
|
void advanceState() {
|
|
|
|
this.state = this.nextState;
|
|
|
|
this.nextState = false;
|
|
|
|
}
|
|
|
|
|
2018-07-05 15:59:11 +00:00
|
|
|
void update(int neighbors) {
|
|
|
|
if (state == true) {
|
2018-07-06 13:00:45 +00:00
|
|
|
surviveRules.forEach( (Rule rule) {
|
2018-07-06 14:46:30 +00:00
|
|
|
if(rule.evaluate(neighbors) == true) this.nextState = true;
|
2018-07-05 15:59:11 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
birthRules.forEach((Rule rule) {
|
2018-07-06 14:46:30 +00:00
|
|
|
if (rule.evaluate(neighbors) == true) this.nextState = true;
|
2018-07-05 15:59:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|