package cellsociety_team08;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Grid {

	/*
	 * Update: 9/16 11am, Brian Bolze: Went ahead and implemented these to
	 * classes because there was so much dependence on my RuleSet and State
	 * implementation.
	 * 
	 * Not sure exactly how to initialize all of this because it all kinda
	 * depends on how we do the XML stuff. I also don't have an initialize
	 * method, I just do it in the constructor. Feel free to change that
	 * accordingly.
	 * 
	 * I also have not implemented the actual shapes/nodes for the cells. I also
	 * do not have color or size of the cells stored ANYWHERE yet. Let me know
	 * what you want to do about this.
	 */
	private Map<String, RuleSet> myImplementedRulesets;

	private static int myRows, myCols;
	private Cell[][] myCells;
	private static RuleSet myRuleSet;

	/**
	 * Use this method to fill up myPossibleRules with all implemented
	 * simulation rulesets. These rulesets then accessed by the constructor and
	 * put into myRuleSet.
	 */
	private void makeMyPossibleRules() {
		myImplementedRulesets = new HashMap<>();
		// We need to implement passing parameters for the rulesets via the XML
		// file
		myImplementedRulesets.put("SpreadingFire", new SpreadingFire(
				new Object[] { (float) 0.9 }));
		myImplementedRulesets.put("Segregation", new Segregation(new Object[] {
				0.3, 0.4 }));
		myImplementedRulesets.put("PredatorPrey", new PredatorPrey(
				new Object[] { 5 })); // Still needs work
	}

	public Grid(String type, int rows, int cols) {
		makeMyPossibleRules();

		myRuleSet = myImplementedRulesets.get(type);
		myRows = rows;
		myCols = cols;

		myCells = new Cell[myRows][myCols];
	}

	public void initialize(RuleSet rules, int[] size, State state) {
		Random rand = new Random();		
		for (int i = 0; i < myRows; i++) {
			for (int j = 0; j < myCols; j++) {
				int oddsOfCell = rand.nextInt(100) + 1;
				if (oddsOfCell > 50) {
					myCells[i][j] = new Cell(state, new int[]{i, j});
				}
			}
		}
	}

	public void update() {
		for (int i = 0; i < myCells.length; i++) {
			for (int j = 0; j < myCells[0].length; j++) {
				Cell[][] neighborhood = getNeighborhood(myCells[i][j]);
				myCells[i][j].setState(myRuleSet.getState(neighborhood));
				myCells[i][j].setLocation(myRuleSet.getLocation(neighborhood));
			}
		}
	}

	public Cell[][] getNeighborhood(Cell c) {

		Cell[][] ret = new Cell[3][3];

		for (int i = -1; i < 2; i++) {
			for (int j = -1; j < 2; j++) {
				if (isOutside(i, j)) {
					ret[i][j] = null;
				} else {
					ret[i][j] = myCells[i][j];
				}
			}
		}

		return ret;
	}

	public boolean isOutside(int row, int col) {
		return (row >= myRows || row < 0 || col >= myCols || col < 0);
	}

}

@@ -1763,18 +1763,16 @@
 les, int
-%5B%5D
  size, S
@@ -1785,16 +1785,22 @@
 tate) %7B%0A
+%09%09%0A%09%09%0A
 %09%09Random
@@ -1822,36 +1822,32 @@
 dom();%09%09%0A%09%09for (
-int 
 i = 0; i %3C myRow
@@ -1856,36 +1856,32 @@
  i++) %7B%0A%09%09%09for (
-int 
 j = 0; j %3C myCol
@@ -1886,24 +1886,83 @@
 ols; j++) %7B%0A
+%09%09%09%09myPatches%5Bi%5D%5Bj%5D = new Patch(%5Bi, j%5D, size/myRows, true)%0A
 %09%09%09%09int odds
@@ -2016,24 +2016,62 @@
 ell %3E 50) %7B%0A
+%09%09%09%09%09myPatches%5Bi%5D%5Bj%5D.isEmpty = false;%0A
 %09%09%09%09%09myCells
@@ -2099,25 +2099,15 @@
 te, 
-new int%5B%5D%7B
+%5B
 i, j
-%7D);
+%5D)
 %0A%09%09%09

Update Grid.java