Browse Source

Don't fill new grids unless we need it.

Also update places where it isn't needed.
master
Josh Hofing 12 years ago
parent
commit
d50dbb417a
5 changed files with 14 additions and 8 deletions
  1. +10
    -4
      src/Grid.java
  2. +1
    -1
      src/rules/BriansBrain.java
  3. +1
    -1
      src/rules/Conway.java
  4. +1
    -1
      src/rules/Conway4.java
  5. +1
    -1
      src/rules/LifeWithoutDeath.java

+ 10
- 4
src/Grid.java View File

@@ -9,15 +9,21 @@ public class Grid {
_grid[0][0] = new Patch(this, 0, 0, 0);
}

public Grid(int x, int y) {
public Grid(int x, int y, boolean fill) {
_grid = new Patch[y][x];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
_grid[j][i] = new Patch(this, i, j, 0);
if (fill) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
_grid[j][i] = new Patch(this, i, j, 0);
}
}
}
}

public Grid (int x, int y) {
this(x,y,true);
}

private int normalizeX(int x) {
while (x >= getWidth())
x -= getWidth();


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

@@ -7,7 +7,7 @@ public class BriansBrain extends RuleSet {
public static int states = 3;

public static Grid run(Grid g) {
Grid newGrid = new Grid(g.getWidth(), g.getHeight());
Grid newGrid = new Grid(g.getWidth(), g.getHeight(), false);
for (int i = 0; i < g.getWidth(); i++) {
for (int j = 0; j < g.getHeight(); j++) {
Patch[] neighbors = g.getPatch(i, j).get8Neighbors();


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

@@ -7,7 +7,7 @@ public class Conway extends RuleSet {
public static int states = 2;

public static Grid run (Grid g) {
Grid newGrid = new Grid(g.getWidth(), g.getHeight());
Grid newGrid = new Grid(g.getWidth(), g.getHeight(), false);
for (int i = 0; i < g.getWidth(); i++) {
for (int j = 0; j < g.getHeight(); j++) {
Patch[] neighbors = g.getPatch(i, j).get8Neighbors();


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

@@ -8,7 +8,7 @@ public class Conway4 extends RuleSet {
public static int states = 2;

public static Grid run (Grid g) {
Grid newGrid = new Grid(g.getWidth(), g.getHeight());
Grid newGrid = new Grid(g.getWidth(), g.getHeight(), false);
for (int i = 0; i < g.getWidth(); i++) {
for (int j = 0; j < g.getHeight(); j++) {
Patch[] neighbors = g.getPatch(i, j).get4Neighbors();


+ 1
- 1
src/rules/LifeWithoutDeath.java View File

@@ -8,7 +8,7 @@ public class LifeWithoutDeath extends RuleSet {
public static int states = 2;

public static Grid run (Grid g) {
Grid newGrid = new Grid(g.getWidth(), g.getHeight());
Grid newGrid = new Grid(g.getWidth(), g.getHeight(), false);
for (int i = 0; i < g.getWidth(); i++) {
for (int j = 0; j < g.getHeight(); j++) {
Patch[] neighbors = g.getPatch(i, j).get8Neighbors();


Loading…
Cancel
Save