diff --git a/lib/Grid.dart b/lib/Grid.dart index cd47a83..885b294 100644 --- a/lib/Grid.dart +++ b/lib/Grid.dart @@ -1,5 +1,5 @@ -import 'package:rules_of_living/Cell.dart'; -import 'package:rules_of_living/Rule.dart'; +import 'Cell.dart'; +import 'Rule.dart'; class Grid { final int w; @@ -13,9 +13,11 @@ class Grid { map.addAll(_buildGrid(w, h)); map[5][5].state = true; + print("Grid creation finished"); } List> _buildGrid(int w, int h) { + print("grid being created"); List> grid = new List(h); Rule threeTrue = new Rule((int n) { if(n==3) return true; @@ -45,17 +47,18 @@ class Grid { for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE - map[y][x].update( getNeighbors(x, y, 1) ); + map[y][x].update( getSurroundingNeighbors(x, y, 1) ); } } } - int getNeighbors(int x, int y, int range) { + int getSurroundingNeighbors(int x, int y, int range) { int count = 0; - for (int iy = y - range ~/ 2; iy < iy + range / 2; iy++) { - for (int ix = x - range ~/ 2; ix < ix + range / 2; ix++) { - if (iy > 0 && iy < map.length && ix > 0 && ix < map[iy].length && - map[iy][ix].state == true) count++; + for (int iy = y - range; iy <= y + range; iy++) { + for (int ix = x - range; ix <= x + range; ix++) { + if (ix > 0 && iy > 0 && iy < map.length && ix < map[iy].length && map[iy][ix].state == true && !(x == ix && y == iy)) { + count++; + } } } return count;