cellular-automata/lib/Cell.dart

24 lines
576 B
Dart
Raw Normal View History

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