| @@ -7,20 +7,14 @@ public class Conway extends RuleSet { | |||||
| public static int states = 2; | public static int states = 2; | ||||
| public static Grid run (Grid g) { | public static Grid run (Grid g) { | ||||
| //Thread[] threads = new Thread[g.getWidth()]; | |||||
| 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++) { | ||||
| //Conway.rowThread rt = new Conway.rowThread(g, newGrid, i); | |||||
| //Thread t = new Thread(rt); | |||||
| //rt.setThread(t); | |||||
| //threads[i] = t; | |||||
| //t.run(); | |||||
| for (int j = 0; j < g.getHeight(); j++) { | for (int j = 0; j < g.getHeight(); j++) { | ||||
| Patch[] neighbors = g.getPatch(i, j).get8Neighbors(); | Patch[] neighbors = g.getPatch(i, j).get8Neighbors(); | ||||
| 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 < 2) { | if (numAlive < 2) { | ||||
| p.setState(0); //Dies by underpopulation | p.setState(0); //Dies by underpopulation | ||||
| } | } | ||||
| @@ -28,58 +22,10 @@ public class Conway extends RuleSet { | |||||
| 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); | |||||
| } | } | ||||
| } | } | ||||
| //boolean running = true; | |||||
| //while (running) { | |||||
| //running = false; | |||||
| //for (Thread t : threads) { | |||||
| //if (t.isAlive()) running = true; | |||||
| //} | |||||
| //} | |||||
| return newGrid; | return newGrid; | ||||
| } | } | ||||
| //public static class rowThread implements Runnable { | |||||
| //private Grid _original, _newGrid; | |||||
| //private int _rowNum; | |||||
| //private Thread _thread; | |||||
| //public rowThread (Grid orig, Grid newGrid, int rowNum) { | |||||
| //_original = orig; | |||||
| //_newGrid = newGrid; | |||||
| //_rowNum = rowNum; | |||||
| //} | |||||
| //public void setThread (Thread t) { | |||||
| //_thread = t; | |||||
| //} | |||||
| //public void run () { | |||||
| //for (int j = 0; j < _original.getHeight(); j++) { | |||||
| //Patch[] neighbors = _original.getPatch(_rowNum, j).get8Neighbors(); | |||||
| //int numAlive = 0; | |||||
| //for (Patch p : neighbors) | |||||
| //if (p.getState() == 1) numAlive++; | |||||
| //Patch p = _original.getPatch(_rowNum,j).clone(_newGrid); | |||||
| //if (numAlive < 2) { | |||||
| //p.setState(0); //Dies by underpopulation | |||||
| //} | |||||
| //if (numAlive > 3) { | |||||
| //p.setState(0); //Dies by overpopulation | |||||
| //} | |||||
| //if (numAlive == 3) | |||||
| //p.setState(1); //Born with 3 neighbors. | |||||
| //_newGrid.setPatch(_rowNum,j,p); | |||||
| //} | |||||
| //try { | |||||
| //_thread.join(); | |||||
| //} catch (Exception e) { | |||||
| //e.printStackTrace(); | |||||
| //} | |||||
| //} | |||||
| //} | |||||
| } | } | ||||