From c2d46c6e38a3cbc5efba7c5ba3bbf76b34128d6f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 6 Jul 2018 15:00:45 +0200 Subject: [PATCH] Fix Cell Population --- lib/Cell.dart | 6 +++--- lib/Grid.dart | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Cell.dart b/lib/Cell.dart index 2509733..5528492 100644 --- a/lib/Cell.dart +++ b/lib/Cell.dart @@ -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; } } diff --git a/lib/Grid.dart b/lib/Grid.dart index 885b294..5632972 100644 --- a/lib/Grid.dart +++ b/lib/Grid.dart @@ -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> 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;