Fix Cell Population

This commit is contained in:
Marty Oehme 2018-07-06 15:00:45 +02:00
parent b16d108e70
commit c2d46c6e38
2 changed files with 9 additions and 7 deletions

View File

@ -10,14 +10,14 @@ class Cell {
void update(int neighbors) {
bool newState = false;
if (state == true) {
surviveRules.forEach((Rule rule) {
if (rule.evaluate(neighbors) == true) newState = 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;
this.state = newState;
}
}

View File

@ -13,6 +13,8 @@ class Grid {
map.addAll(_buildGrid(w, h));
map[5][5].state = true;
map[5][6].state = true;
map[5][7].state = true;
print("Grid creation finished");
}
@ -21,11 +23,11 @@ class Grid {
List<List<Cell>> grid = new List(h);
Rule threeTrue = new Rule((int n) {
if(n==3) return true;
else return false;
return false;
});
Rule twoTrue = new Rule((int n) {
if(n==2) return true;
else return false;
return false;
});
for (int y = 0; y < h; y++) {
@ -35,9 +37,9 @@ class Grid {
Cell cell = new Cell();
cell.surviveRules.add(twoTrue);
cell.surviveRules.add(threeTrue);
cell.birthRules.add(twoTrue);
cell.birthRules.add(threeTrue);
grid[y][x] = new Cell();
grid[y][x] = cell;
}
}
return grid;