diff --git a/.idea/dictionaries/karoushafennimore.xml b/.idea/dictionaries/karoushafennimore.xml
new file mode 100644
index 0000000..42dc912
--- /dev/null
+++ b/.idea/dictionaries/karoushafennimore.xml
@@ -0,0 +1,7 @@
+
+
+
+ boundries
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ce6df6f..4ce1dec 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,10 @@
-
+
+
+
+
@@ -11,77 +14,32 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- JAVA
- com.zipcodeconway.ConwayGameOfLife
-
- com.zipcodeconway.ConwayGameOfLife
-
-
-
-
-
-
- Constructors
- Methods
-
- All
- private
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
+
+
@@ -126,8 +84,8 @@
-
+
@@ -139,10 +97,9 @@
DEFINITION_ORDER
-
-
+
-
+
@@ -159,55 +116,61 @@
+
-
-
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -217,10 +180,9 @@
-
-
+
@@ -233,19 +195,20 @@
+
-
-
+
+
-
-
+
+
@@ -503,26 +466,31 @@
1519668901598
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
@@ -536,39 +504,39 @@
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
@@ -584,26 +552,40 @@
-
+
-
-
+
+
-
+
-
-
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -614,11 +596,11 @@
JAVA
com.zipcodeconway.ConwayGameOfLife
- com.zipcodeconway.ConwayGameOfLife
+ com.zipcodeconway.ConwayGameOfLife
-
+
Constructors
@@ -629,63 +611,77 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+ JAVA
+ com.zipcodeconway.ConwayGameOfLife
+
+ com.zipcodeconway.ConwayGameOfLife
+
+
+
+
+
+
+ Constructors
+ Methods
+
+ All
+ private
+
-
+
-
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
+
-
-
+
+
diff --git a/Screen Shot 2018-03-12 at 4.07.11 PM.png b/Screen Shot 2018-03-12 at 4.07.11 PM.png
new file mode 100644
index 0000000..b76b051
Binary files /dev/null and b/Screen Shot 2018-03-12 at 4.07.11 PM.png differ
diff --git a/src/main/java/com/zipcodeconway/ConwayGameOfLife.java b/src/main/java/com/zipcodeconway/ConwayGameOfLife.java
index 0d3b15b..7c71bf0 100644
--- a/src/main/java/com/zipcodeconway/ConwayGameOfLife.java
+++ b/src/main/java/com/zipcodeconway/ConwayGameOfLife.java
@@ -2,42 +2,141 @@
public class ConwayGameOfLife {
+ private int[][] currentGen;
+ private int[][] nextGen;
+ private SimpleWindow displayWindow;
+
public ConwayGameOfLife(Integer dimension) {
- }
+
+ currentGen = createRandomStart(dimension);
+ nextGen = new int[dimension][dimension];
+ this.displayWindow = new SimpleWindow(dimension);
+
+ }
public ConwayGameOfLife(Integer dimension, int[][] startmatrix) {
+
+ currentGen = startmatrix;
+ nextGen = new int[dimension][dimension];
+ this.displayWindow = new SimpleWindow(dimension);
+
}
public static void main(String[] args) {
+
ConwayGameOfLife sim = new ConwayGameOfLife(50);
int[][] endingWorld = sim.simulate(50);
}
+ public int[][] simulate(Integer maxGenerations) {
+ int generations = 0;
+ //count has to be less than OR equal to maxGen because it has to be equal to the number of times it has to run
+ while (generations <= maxGenerations) {
+ //new display
+ displayWindow.display(currentGen, generations);
+ //update the currentGeneration to nextGen
+ for (int row = 0; row < currentGen.length; row++) {
+ //do not need [row] because it is a cube but it would require that if it wasnt one.
+ for (int column = 0; column < currentGen[row].length; column++) {
+ nextGen[row][column] = isAlive(row, column, currentGen);
+ }
+ }
+
+ copyAndZeroOut(nextGen, currentGen);
+ displayWindow.sleep(125);
+ generations++;
+
+ }
+ return currentGen;
+ }
+
// Contains the logic for the starting scenario.
// 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];
+ //have to create a random array!!! define with dimension parameter!
+ int[][] newRandomArray = new int[dimension][dimension];
+ for (int row = 0; row < newRandomArray.length ; row++) {
+ for (int column = 0; column < newRandomArray[row].length; column++) {
+ newRandomArray[row][column] = (int)(Math.random() * 2);
+ }
+ }
+ return newRandomArray;
}
- public int[][] simulate(Integer maxGenerations) {
- return new int[1][1];
- }
// 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 row = 0; row < current.length; row++)
+ for (int column = 0; column < current[row].length; column++) {
+ //Copying current to next
+ current[row][column] = next[row][column];
+ //wipe out next
+ next[row][column] = 0;
+ }
}
+
+
// Calculate if an individual cell should be alive in the next generation.
// Based on the game logic:
- /*
+
+ private int isAlive(int row, int col, int[][] world) {
+
+ //set instance variables to figure out location around cell
+ int north = col - 1;
+ int south = col + 1;
+ int east = row + 1;
+ int west = row -1;
+ int count = 0;
+
+
+ //boundries loops around if neighbor is against wall
+ if(north < 0) {
+ north = world[row].length - 1;
+ }
+ if(south == world[row].length) {
+ south = 0;
+ }
+ if(east == world[col].length) {
+ east = 0;
+ }
+ if(west < 0) {
+ west = world[col].length - 1;
+ }
+
+ //checking how many cells around it are alive
+ //by rows first
+ if(world[east][north] == 1) count++;
+ if(world[east][south] == 1) count++;
+ if(world[east][col] == 1) count++;
+
+ if(world[west][north] == 1) count++;
+ if(world[west][south] == 1) count++;
+ if(world[west][col] == 1) count++;
+ //rows
+ if(world[row][north] == 1) count++;
+ if(world[row][south] == 1) count++;
+
+ //check rules and determine if it stays alive or dies.
+ /*
Any live cell with fewer than two live neighbours dies, as if by needs caused by underpopulation.
Any live cell with more than three live neighbours dies, as if by overcrowding.
Any live cell with two or three live neighbours lives, unchanged, to the next generation.
Any dead cell with exactly three live neighbours cells will come to life.
- */
- private int isAlive(int row, int col, int[][] world) {
- return 0;
+ */
+
+ //underpopulation
+ if(count < 2 || count > 3 ) {
+ return 0;
+ //3 neighbors brings it to life so = 1.
+ }else if(count == 3) {
+ return 1;
+ }else
+ //return the cell UNCHANGED as it is JUST incase...... instead of returning 1.
+ return world[row][col];
+
}
}
diff --git a/src/main/java/com/zipcodeconway/SimpleWindow.java b/src/main/java/com/zipcodeconway/SimpleWindow.java
index f315e00..f3e2a9c 100644
--- a/src/main/java/com/zipcodeconway/SimpleWindow.java
+++ b/src/main/java/com/zipcodeconway/SimpleWindow.java
@@ -39,11 +39,11 @@ public void display(int[][] array, Integer n) {
for (int j = 0; j < array[0].length; j++) {
g.drawRect(i * BOX_DIM, j * BOX_DIM, 10, 10);
if (array[i][j] == 0) {
- g.setColor(Color.WHITE);
+ g.setColor(Color.DARK_GRAY);
g.fillRect(i * BOX_DIM, j * BOX_DIM, 10, 10);
}
if (array[i][j] == 1) {
- g.setColor(Color.BLACK);
+ g.setColor(Color.MAGENTA);
g.fillRect(i * BOX_DIM, j * BOX_DIM, 10, 10);
}
}