diff --git a/src/Goldfish.java b/src/Goldfish.java index b92a69a..ac12b93 100644 --- a/src/Goldfish.java +++ b/src/Goldfish.java @@ -55,7 +55,7 @@ public class Goldfish { } private void setup(String rule) { - if(rule.equals("Conway")) { + if (rule.equals("Conway")) { int[][] glidergun = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0}, @@ -67,9 +67,9 @@ public class Goldfish { {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }; - for(int i = 0; i < 36; i++) { - for(int j = 0; j < 9; j++) { - _grid.getPatch(i+2,j+2).setState(glidergun[j][i]); + for (int i = 0; i < 36; i++) { + for (int j = 0; j < 9; j++) { + _grid.getPatch(i + 2, j + 2).setState(glidergun[j][i]); } } } else if (rule.equals("Life Without Death")) { @@ -77,9 +77,10 @@ public class Goldfish { {1,1,1,1,0,1}, {1,0,1,1,1,1} }; - for(int i = 0; i < 6; i++) { - for(int j = 0; j < 2; j++) { - _grid.getPatch(i+((_grid.getHeight()-6)/2),j+((_grid.getWidth()-2)/2)).setState(pattern[j][i]); + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 2; j++) { + _grid.getPatch(i + ((_grid.getHeight() - 6) / 2), + j + ((_grid.getWidth() - 2) / 2)).setState(pattern[j][i]); } } } else if (rule.equals("Brian's Brain")) { @@ -88,9 +89,10 @@ public class Goldfish { {2,0,2,0,2}, {0,1,0,1,0} }; - for(int i = 0; i < 5; i++) { - for(int j = 0; j < 3; j++) { - _grid.getPatch(i+((_grid.getHeight()-5)/2),j+((_grid.getWidth()-3)/2)).setState(pattern[j][i]); + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 3; j++) { + _grid.getPatch(i + ((_grid.getHeight() - 5) / 2), + j + ((_grid.getWidth() - 3) / 2)).setState(pattern[j][i]); } } } diff --git a/src/rules/BriansBrain.java b/src/rules/BriansBrain.java index 3f12628..599ca70 100644 --- a/src/rules/BriansBrain.java +++ b/src/rules/BriansBrain.java @@ -6,7 +6,7 @@ import edu.stuy.goldfish.Patch; public class BriansBrain extends RuleSet { public static int states = 3; - public static Grid run (Grid g) { + 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 < g.getHeight(); j++) { @@ -14,11 +14,11 @@ public class BriansBrain extends RuleSet { int numAlive = 0; for (Patch neighbor : neighbors) if (neighbor.getState() == 2) numAlive++; - Patch orig = g.getPatch(i,j); - Patch p = g.getPatch(i,j).clone(newGrid); + Patch orig = g.getPatch(i, j); + Patch p = g.getPatch(i, j).clone(newGrid); if (orig.getState() == 0 && numAlive == 2) p.setState(2); - if (orig.getState() == 1) p.setState(0); //Dying cells die. - if (orig.getState() == 2) p.setState(1); //Make living cells dying. + if (orig.getState() == 1) p.setState(0); // Dying cells die. + if (orig.getState() == 2) p.setState(1); // Make living cells dying. newGrid.setPatch(i,j,p); } } diff --git a/src/rules/Conway.java b/src/rules/Conway.java index f470744..0221e68 100644 --- a/src/rules/Conway.java +++ b/src/rules/Conway.java @@ -16,13 +16,13 @@ public class Conway extends RuleSet { if (neighbor.getState() == 1) numAlive++; Patch p = g.getPatch(i, j).clone(newGrid); if (numAlive < 2) { - p.setState(0); //Dies by underpopulation + p.setState(0); // Dies by underpopulation } if (numAlive > 3) { - p.setState(0); //Dies by overpopulation + p.setState(0); // Dies by overpopulation } if (numAlive == 3) - p.setState(1); //Born with 3 neighbors + p.setState(1); // Born with 3 neighbors newGrid.setPatch(i, j, p); } } diff --git a/src/rules/Conway4.java b/src/rules/Conway4.java index 0dd8aa9..6aab4e8 100644 --- a/src/rules/Conway4.java +++ b/src/rules/Conway4.java @@ -15,16 +15,16 @@ public class Conway4 extends RuleSet { int numAlive = 0; for (Patch p : neighbors) if (p.getState() == 1) numAlive++; - Patch p = g.getPatch(i,j).clone(newGrid); + Patch p = g.getPatch(i, j).clone(newGrid); if (numAlive < 2) { - p.setState(0); //Dies by underpopulation + p.setState(0); // Dies by underpopulation } if (numAlive > 3) { - p.setState(0); //Dies by overpopulation + p.setState(0); // Dies by overpopulation } if (numAlive == 3) - p.setState(1); //Born with 3 neighbors. - newGrid.setPatch(i,j,p); + p.setState(1); // Born with 3 neighbors. + newGrid.setPatch(i, j, p); } } return newGrid; diff --git a/src/rules/LifeWithoutDeath.java b/src/rules/LifeWithoutDeath.java index afeeccc..64112fa 100644 --- a/src/rules/LifeWithoutDeath.java +++ b/src/rules/LifeWithoutDeath.java @@ -15,13 +15,12 @@ public class LifeWithoutDeath extends RuleSet { int numAlive = 0; for (Patch neighbor : neighbors) if (neighbor.getState() == 1) numAlive++; - Patch p = g.getPatch(i,j).clone(newGrid); + Patch p = g.getPatch(i, j).clone(newGrid); if (numAlive == 3) p.setState(1); //Born with 3 neighbors. - newGrid.setPatch(i,j,p); + newGrid.setPatch(i, j, p); } } - return newGrid; } } diff --git a/src/rules/RuleSet.java b/src/rules/RuleSet.java index 236f7f9..36e39a2 100644 --- a/src/rules/RuleSet.java +++ b/src/rules/RuleSet.java @@ -15,5 +15,4 @@ public class RuleSet { public static Grid run (Grid g) { return g; } - }