From 9e7d3df181ff4ff7b0aae9de904e8956524c8d87 Mon Sep 17 00:00:00 2001 From: Daniel Horowitz Date: Mon, 12 Mar 2018 16:19:03 -0400 Subject: [PATCH 1/4] so cclose fixing alive error --- .idea/.name | 1 + .idea/misc.xml | 4 +- .idea/modules.xml | 2 +- .idea/uiDesigner.xml | 124 ----- .idea/vcs.xml | 2 +- .idea/workspace.xml | 501 +++--------------- ...-Of-Life-Java.iml => Game-Of-Life-Java.iml | 1 - .../com/zipcodeconway/ConwayGameOfLife.java | 75 ++- .../java/com/zipcodeconway/SimpleWindow.java | 4 +- 9 files changed, 166 insertions(+), 548 deletions(-) create mode 100644 .idea/.name delete mode 100644 .idea/uiDesigner.xml rename .idea/Game-Of-Life-Java.iml => Game-Of-Life-Java.iml (91%) diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d920b20 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Game-Of-Life-Java \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 05e1d17..d30d09e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,5 +7,7 @@ - + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index f98eea2..6604c74 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ce6df6f..9d2ad46 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,17 @@ - + + + + + + + + + + + - - - - - - end - - - currentGeneration - nextGeneration - - @@ -117,17 +78,7 @@ @@ -139,11 +90,12 @@ DEFINITION_ORDER - + @@ -159,94 +111,94 @@ + + + + - + - + - + - + - + + + + + + + + + + - + + + + + + + + - + + - + + + + @@ -206,7 +206,7 @@ - + @@ -447,39 +448,39 @@ - - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + - - + + @@ -493,6 +494,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -504,11 +531,14 @@ - - - - - + + + + + + + + @@ -522,14 +552,22 @@ - - + + + + + + + + + + diff --git a/src/main/java/com/zipcodeconway/ConwayGameOfLife.java b/src/main/java/com/zipcodeconway/ConwayGameOfLife.java index cf4d781..b0750fb 100644 --- a/src/main/java/com/zipcodeconway/ConwayGameOfLife.java +++ b/src/main/java/com/zipcodeconway/ConwayGameOfLife.java @@ -10,8 +10,8 @@ public class ConwayGameOfLife { public ConwayGameOfLife(Integer dimension) { this.displayWindow = new SimpleWindow(dimension); - currentGen = createRandomStart(dimension); - nextGen = new int[dimension][dimension]; + this.currentGen = createRandomStart(dimension); + this.nextGen = new int[dimension][dimension]; } public ConwayGameOfLife(Integer dimension, int[][] startmatrix) { @@ -52,7 +52,7 @@ public int[][] simulate(Integer maxGenerations) { } } copyAndZeroOut(nextGen, currentGen); - displayWindow.sleep(125); + displayWindow.sleep(500); count++; } return currentGen; @@ -78,34 +78,34 @@ public void copyAndZeroOut(int[][] next, int[][] current) { Any dead cell with exactly three live neighbours cells will come to life. */ private int isAlive(int row, int col, int[][] world) { + int numOfLiveNeighbors = numberOfLivingNeighbors(row,col,world); + if (numOfLiveNeighbors < 2 || numOfLiveNeighbors > 3) { + return 0; + } else if (numOfLiveNeighbors == 3) + return 1; + else { + return world[row][col]; + } + } + + public int numberOfLivingNeighbors(int row, int col, int[][] world) { int north = col - 1; int south = col + 1; int west = row - 1; int east = row + 1; - if (north == -1) { + if (north == -1) north = world[row].length - 1; - } - if (south == world[row].length) { + if (south == world[row].length) south = 0; - } - if (west == -1) { + if (west == -1) west = world.length - 1; - } - if (east == world.length) { + if (east == world.length) east = 0; - } - int numOfLiveNeighbors = world[row][north] + world[east][north] + world[west][north] + + return world[row][north] + world[east][north] + world[west][north] + world[row][south] + world[east][south] + world[west][south] + world[east][col] + world[west][col]; - - if (numOfLiveNeighbors < 2 || numOfLiveNeighbors > 3) { - return 0; - } else if (numOfLiveNeighbors == 3) - return 1; - else { - return world[row][col]; - } } + } From 1bf3e19a48ca4f4eb99ab28658c612309e25d79b Mon Sep 17 00:00:00 2001 From: Daniel Horowitz Date: Mon, 12 Mar 2018 18:22:26 -0400 Subject: [PATCH 4/4] pic included --- .idea/workspace.xml | 332 ++---------------- .../Screen Shot 2018-03-12 at 6.20.56 PM.png | Bin 0 -> 57140 bytes 2 files changed, 38 insertions(+), 294 deletions(-) create mode 100644 src/main/Screen Shot 2018-03-12 at 6.20.56 PM.png diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 10707b3..df0729f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,9 +1,9 @@ - + - + - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -70,14 +35,6 @@ - - - @@ -105,8 +62,6 @@ - - @@ -149,42 +104,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -