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..8996ee8 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,7 @@
-
+
@@ -11,100 +11,46 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- JAVA
- com.zipcodeconway.ConwayGameOfLife
-
- com.zipcodeconway.ConwayGameOfLife
-
-
-
-
-
-
- Constructors
- Methods
-
- All
- private
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- end
-
-
- currentGeneration
- nextGeneration
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -117,17 +63,8 @@
-
-
-
-
-
-
-
-
-
@@ -139,11 +76,12 @@
DEFINITION_ORDER
-
-
-
-
+
+
+
+
+
@@ -159,34 +97,35 @@
+
-
+
-
+
-
+
-
+
-
+
@@ -194,20 +133,20 @@
-
+
-
+
-
+
@@ -217,36 +156,16 @@
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -260,7 +179,7 @@
-
+
@@ -287,20 +206,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -340,7 +245,7 @@
-
+
@@ -352,7 +257,32 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -410,27 +340,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -471,21 +380,20 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
+
+
@@ -497,78 +405,82 @@
-
- 1519668901598
+
+ 1520867652526
- 1519668901598
-
+ 1520867652526
+
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
-
+
-
+
-
+
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
+
@@ -578,114 +490,78 @@
-
-
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
- JAVA
- com.zipcodeconway.ConwayGameOfLife
-
- com.zipcodeconway.ConwayGameOfLife
-
-
-
-
-
-
- Constructors
- Methods
-
- All
- private
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
+
-
+
-
-
+
+
@@ -693,66 +569,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- No facets are configured
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1.8
-
-
-
-
-
-
-
-
-
-
-
- Game-Of-Life-Java
-
-
-
-
-
-
-
-
-
-
1.8
@@ -765,17 +581,6 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/Game-Of-Life-Java.iml b/Game-Of-Life-Java.iml
similarity index 91%
rename from .idea/Game-Of-Life-Java.iml
rename to Game-Of-Life-Java.iml
index 9c26698..9f1c55c 100644
--- a/.idea/Game-Of-Life-Java.iml
+++ b/Game-Of-Life-Java.iml
@@ -5,7 +5,6 @@
-
diff --git a/README.md b/README.md
index 8b4d93e..eb4f679 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
# Conway's Game of Life
+
+
+
The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.
The "game" is a zero-player game,
diff --git a/src/main/java/com/zipcodeconway/ConwayGameOfLife.java b/src/main/java/com/zipcodeconway/ConwayGameOfLife.java
index 0d3b15b..b33cd11 100644
--- a/src/main/java/com/zipcodeconway/ConwayGameOfLife.java
+++ b/src/main/java/com/zipcodeconway/ConwayGameOfLife.java
@@ -1,11 +1,28 @@
package com.zipcodeconway;
+import java.util.Random;
+
public class ConwayGameOfLife {
+ private Integer edge;
+ int[][] currentGen;
+ int[][] nextGen;
+ private SimpleWindow ourDisplayWindow;
+
+
public ConwayGameOfLife(Integer dimension) {
- }
+ this.ourDisplayWindow= new SimpleWindow(dimension);
+ this.edge=dimension-1;
+ this.nextGen = new int[dimension][dimension];
+ currentGen = createRandomStart(dimension);
+ }
+
+ public ConwayGameOfLife(Integer dimension, int[][] startMatrix) {
+ this.ourDisplayWindow= new SimpleWindow(dimension);
+ this.edge=dimension-1;
+ this.currentGen = startMatrix;
+ this.nextGen = new int[dimension][dimension];
- public ConwayGameOfLife(Integer dimension, int[][] startmatrix) {
}
public static void main(String[] args) {
@@ -17,16 +34,50 @@ public static void main(String[] args) {
// Which cells are alive or dead in generation 0.
// allocates and returns the starting matrix of size 'dimension'
private int[][] createRandomStart(Integer dimension) {
- return new int[1][1];
+//here amy
+
+ currentGen = new int[dimension][dimension];
+
+ for (int i = 0; i < dimension; i++){
+ for (int j = 0; j < dimension; j++){
+ if (Math.random()* 100 > 50){
+ currentGen[i][j] = 1;
+ } else {
+ currentGen[i][j] = 0;
+ }
+ }
+ }
+
+ return currentGen;
}
public int[][] simulate(Integer maxGenerations) {
- return new int[1][1];
+
+ for (int i = 0; i <= maxGenerations; i++){
+ this.ourDisplayWindow.display(currentGen, i);
+ this.ourDisplayWindow.sleep(125);
+ copyAndZeroOut(nextGen,currentGen);
+ }
+
+ return currentGen;
}
// copy the values of 'next' matrix to 'current' matrix,
// and then zero out the contents of 'next' matrix
- public void copyAndZeroOut(int [][] next, int[][] current) {
+ public void copyAndZeroOut(int[][] next, int[][] current) {
+ for (int i = 0; i < next.length ; i++){
+ for (int j = 0; j edge) {
+ rowCheck = 0;
+ }
+
+ for (int cellWereLookingAtVertically = col -1; cellWereLookingAtVertically <= col +1; cellWereLookingAtVertically++){
+ int colCheck = cellWereLookingAtVertically;
+ if (cellWereLookingAtVertically <0 ){
+ colCheck = edge;
+ } else if (cellWereLookingAtVertically > edge){
+ colCheck = 0;
+ }
+
+ if (world[rowCheck][colCheck]==1) numOfLiveCells++;
+ }
+ }
+
+
+ if (numOfLiveCells ==3) {
+ aliveForNextGen = 1;
+ } else if (numOfLiveCells ==4){
+ aliveForNextGen= world[row][col];
+ } else {
+ aliveForNextGen = 0;
+ }
+
+ return aliveForNextGen;
}
+
}
+
+//HI EVERYONE! my screenshot is in my readme.
diff --git a/src/main/java/com/zipcodeconway/SimpleWindow.java b/src/main/java/com/zipcodeconway/SimpleWindow.java
index f315e00..ce62f37 100644
--- a/src/main/java/com/zipcodeconway/SimpleWindow.java
+++ b/src/main/java/com/zipcodeconway/SimpleWindow.java
@@ -37,14 +37,14 @@ public void display(int[][] array, Integer n) {
int BOX_DIM = 10;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[0].length; j++) {
- g.drawRect(i * BOX_DIM, j * BOX_DIM, 10, 10);
+ g.drawRect(i * BOX_DIM+1, j * BOX_DIM+1, 10, 10);
if (array[i][j] == 0) {
g.setColor(Color.WHITE);
- g.fillRect(i * BOX_DIM, j * BOX_DIM, 10, 10);
+ g.fillRect(i * BOX_DIM, j * BOX_DIM+1, 10, 10);
}
if (array[i][j] == 1) {
- g.setColor(Color.BLACK);
- g.fillRect(i * BOX_DIM, j * BOX_DIM, 10, 10);
+ g.setColor(Color.MAGENTA);
+ g.fillRect(i * BOX_DIM, j * BOX_DIM+1, 10, 10);
}
}
}
diff --git a/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java b/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java
index 1e5e845..0d00d92 100644
--- a/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java
+++ b/src/test/java/com/zipcodeconway/ConwayGameOfLifeTest.java
@@ -1,5 +1,6 @@
package com.zipcodeconway;
+import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -43,4 +44,58 @@ public void runTest2() {
int[][] results = sim.simulate(10);
assertTrue(java.util.Arrays.deepEquals(results, expected));
}
+
+// @Test
+// public void copyAndZeroOutTest(){
+// ConwayGameOfLife sim = new ConwayGameOfLife(5);
+// //Given
+//
+// }
+
+ @Test
+ public void isAliveTest(){
+
+ ConwayGameOfLife sim = new ConwayGameOfLife(5);
+ //Given
+
+ Integer row = 2;
+ Integer col= 2;
+ int[][] world = {
+ {0, 0, 0, 0, 0},
+ {0, 1, 0, 0, 0},
+ {0, 0, 1, 1, 0},
+ {0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0}};
+
+
+ Integer expected = 1;
+ Integer actual = sim.isAlive(row, col, world);
+
+ Assert.assertEquals(expected,actual);
+ }
+
+ @Test
+ public void edgeTest(){
+
+ ConwayGameOfLife simEdge = new ConwayGameOfLife(5);
+ //Given
+
+ Integer row =4;
+ Integer col = 4;
+
+ int[][]world = {
+ {1, 0, 0, 0, 0},
+ {0, 1, 0, 0, 0},
+ {0, 0, 1, 1, 0},
+ {0, 0, 0, 0, 1},
+ {0, 0, 0, 1, 0}};
+
+
+ Integer expected = 1;
+ Integer actual = simEdge.isAlive(row, col, world);
+
+ Assert.assertEquals(expected,actual);
+ }
+
+
}
\ No newline at end of file