diff --git a/src/Grid.java b/src/Grid.java index ca18d64..27d9466 100644 --- a/src/Grid.java +++ b/src/Grid.java @@ -6,14 +6,14 @@ public class Grid { public Grid() { _grid = new Patch[1][1]; - _grid[0][0] = new Patch(this, 0, 0); + _grid[0][0] = new Patch(this, 0, 0, 0, ""); } public Grid(int x, int y) { _grid = new Patch[x][y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { - _grid[i][j] = new Patch(this, i, j); + _grid[i][j] = new Patch(this, i, j, 0, ""); } } } diff --git a/src/Patch.java b/src/Patch.java index bcae989..d0daed9 100644 --- a/src/Patch.java +++ b/src/Patch.java @@ -46,7 +46,7 @@ public class Patch { } public String toString() { - return _plabel; + return _label; } public Patch[] get4Neighbors() { @@ -55,6 +55,7 @@ public class Patch { neighbors[1] = _grid.getPatch(_xcor - 1, _ycor); neighbors[2] = _grid.getPatch(_xcor, _ycor + 1); neighbors[3] = _grid.getPatch(_xcor, _ycor - 1); + return neighbors; } public Patch[] get8Neighbors() { @@ -67,6 +68,7 @@ public class Patch { neighbors[5] = _grid.getPatch(_xcor + 1, _ycor - 1); neighbors[6] = _grid.getPatch(_xcor - 1, _ycor + 1); neighbors[7] = _grid.getPatch(_xcor - 1, _ycor - 1); + return neighbors; } public Patch clone() { diff --git a/src/rules/Conway.java b/src/rules/Conway.java index 7b7b6a7..f9dfa15 100644 --- a/src/rules/Conway.java +++ b/src/rules/Conway.java @@ -3,14 +3,13 @@ package edu.stuy.goldfish.rules; import edu.stuy.goldfish.Grid; import edu.stuy.goldfish.Patch; -public class Conway implements RuleSet { - states = 2; +public class Conway extends RuleSet { + public static int states = 2; - @Override public static Grid run (Grid g) { Grid newGrid = new Grid(g.getWidth(), g.getHeight()); for (int i = 0; i < g.getWidth(); i++) { - for (int j = 0; j < j.getHeight(); j++) { + for (int j = 0; j < g.getHeight(); j++) { Patch[] neighbors = g.getPatch(i, j).get8Neighbors(); int numAlive = 0; for (Patch p : neighbors) diff --git a/src/rules/RuleSet.java b/src/rules/RuleSet.java index 7609b30..236f7f9 100644 --- a/src/rules/RuleSet.java +++ b/src/rules/RuleSet.java @@ -2,8 +2,8 @@ package edu.stuy.goldfish.rules; import edu.stuy.goldfish.Grid; -public interface RuleSet { - public static int states; +public class RuleSet { + public static int states = 0; /** * Run this ruleset on a grid, returning the result. @@ -12,6 +12,8 @@ public interface RuleSet { * * @return The new grid */ - public static Grid run (Grid g); + public static Grid run (Grid g) { + return g; + } }