24 lines
571 B
Dart
24 lines
571 B
Dart
|
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) {
|
||
|
surviveRules.forEach((Rule rule) {
|
||
|
if (rule.evaluate(neighbors) == true) newState = true;
|
||
|
});
|
||
|
} else {
|
||
|
birthRules.forEach((Rule rule) {
|
||
|
if (rule.evaluate(neighbors) == true) newState = true;
|
||
|
});
|
||
|
}
|
||
|
state = newState;
|
||
|
}
|
||
|
}
|