Browse Source

General cleanup for consistency.

master
Ben Kurtovic 11 years ago
parent
commit
7d451dfbca
6 changed files with 27 additions and 27 deletions
  1. +12
    -10
      src/Goldfish.java
  2. +5
    -5
      src/rules/BriansBrain.java
  3. +3
    -3
      src/rules/Conway.java
  4. +5
    -5
      src/rules/Conway4.java
  5. +2
    -3
      src/rules/LifeWithoutDeath.java
  6. +0
    -1
      src/rules/RuleSet.java

+ 12
- 10
src/Goldfish.java View File

@@ -55,7 +55,7 @@ public class Goldfish {
} }
private void setup(String rule) { private void setup(String rule) {
if(rule.equals("Conway")) {
if (rule.equals("Conway")) {
int[][] glidergun = { 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,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}, {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,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} {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")) { } else if (rule.equals("Life Without Death")) {
@@ -77,9 +77,10 @@ public class Goldfish {
{1,1,1,1,0,1}, {1,1,1,1,0,1},
{1,0,1,1,1,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")) { } else if (rule.equals("Brian's Brain")) {
@@ -88,9 +89,10 @@ public class Goldfish {
{2,0,2,0,2}, {2,0,2,0,2},
{0,1,0,1,0} {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]);
} }
} }
} }


+ 5
- 5
src/rules/BriansBrain.java View File

@@ -6,7 +6,7 @@ import edu.stuy.goldfish.Patch;
public class BriansBrain extends RuleSet { public class BriansBrain extends RuleSet {
public static int states = 3; 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()); Grid newGrid = new Grid(g.getWidth(), g.getHeight());
for (int i = 0; i < g.getWidth(); i++) { for (int i = 0; i < g.getWidth(); i++) {
for (int j = 0; j < g.getHeight(); j++) { for (int j = 0; j < g.getHeight(); j++) {
@@ -14,11 +14,11 @@ public class BriansBrain extends RuleSet {
int numAlive = 0; int numAlive = 0;
for (Patch neighbor : neighbors) for (Patch neighbor : neighbors)
if (neighbor.getState() == 2) numAlive++; 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() == 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); newGrid.setPatch(i,j,p);
} }
} }


+ 3
- 3
src/rules/Conway.java View File

@@ -16,13 +16,13 @@ public class Conway extends RuleSet {
if (neighbor.getState() == 1) numAlive++; if (neighbor.getState() == 1) numAlive++;
Patch p = g.getPatch(i, j).clone(newGrid); Patch p = g.getPatch(i, j).clone(newGrid);
if (numAlive < 2) { if (numAlive < 2) {
p.setState(0); //Dies by underpopulation
p.setState(0); // Dies by underpopulation
} }
if (numAlive > 3) { if (numAlive > 3) {
p.setState(0); //Dies by overpopulation
p.setState(0); // Dies by overpopulation
} }
if (numAlive == 3) if (numAlive == 3)
p.setState(1); //Born with 3 neighbors
p.setState(1); // Born with 3 neighbors
newGrid.setPatch(i, j, p); newGrid.setPatch(i, j, p);
} }
} }


+ 5
- 5
src/rules/Conway4.java View File

@@ -15,16 +15,16 @@ public class Conway4 extends RuleSet {
int numAlive = 0; int numAlive = 0;
for (Patch p : neighbors) for (Patch p : neighbors)
if (p.getState() == 1) numAlive++; if (p.getState() == 1) numAlive++;
Patch p = g.getPatch(i,j).clone(newGrid);
Patch p = g.getPatch(i, j).clone(newGrid);
if (numAlive < 2) { if (numAlive < 2) {
p.setState(0); //Dies by underpopulation
p.setState(0); // Dies by underpopulation
} }
if (numAlive > 3) { if (numAlive > 3) {
p.setState(0); //Dies by overpopulation
p.setState(0); // Dies by overpopulation
} }
if (numAlive == 3) 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; return newGrid;


+ 2
- 3
src/rules/LifeWithoutDeath.java View File

@@ -15,13 +15,12 @@ public class LifeWithoutDeath extends RuleSet {
int numAlive = 0; int numAlive = 0;
for (Patch neighbor : neighbors) for (Patch neighbor : neighbors)
if (neighbor.getState() == 1) numAlive++; if (neighbor.getState() == 1) numAlive++;
Patch p = g.getPatch(i,j).clone(newGrid);
Patch p = g.getPatch(i, j).clone(newGrid);
if (numAlive == 3) if (numAlive == 3)
p.setState(1); //Born with 3 neighbors. p.setState(1); //Born with 3 neighbors.
newGrid.setPatch(i,j,p);
newGrid.setPatch(i, j, p);
} }
} }

return newGrid; return newGrid;
} }
} }

+ 0
- 1
src/rules/RuleSet.java View File

@@ -15,5 +15,4 @@ public class RuleSet {
public static Grid run (Grid g) { public static Grid run (Grid g) {
return g; return g;
} }

} }

Loading…
Cancel
Save