/**
 *
 * GameOfLife.java
 * generated by CASIM
 *
 */

import de.tubs.cs.sc.casim.State;
import de.tubs.cs.sc.casim.Cell;
import de.tubs.cs.sc.casim.Lattice;
import java.awt.Color;

/**
 * GameOfLife
 */
public class GameOfLife extends State {
    /**
     * (1) add state variables here
     * i.e. int condition;
     */
    private int condition;
    
    /**
     * (2) add initialization of state variables here
     */
    public void GameOfLife() {
		condition = 0;
    }
    /**
     * (3) add lattice initialization here
     * access is (StateClass)l.getState(...)
     */
    public static void initialize(Lattice l, int option) {
    	int shape[] = {1,1, 2,2, 3,2, 3,1, 3,0};
	int x = l.getY();
	for(int i=0; i<shape.length; i++) {
	    ((GameOfLife)l.getState(shape[i], x-2-shape[++i])).condition = 1;
	}
    }
    /**
     * (4) add drawing color definition here
     * an array of Color's is recommended
     * returning null means the cell will not be drawn
     */
    public Color getColor() {
	switch(condition) {
	    case 1: return Color.red;
	    
	}
      	return null;
    }
    /**
     * (5) add state variables copy code here
     * do a field to field copy from s to this
     */
    public void copy(State s) {
      	GameOfLife source = (GameOfLife)s;
      	condition = source.condition;
    }
    /**
     * (6) add transion function code here
     * evaluating the new state of the cell
     * use i.e. cell.getNeighbors to get the neighborhood set
     */
    public void  transition(Cell cell) {
	
	State neighbors[] = cell.getNeighbors();
	int value = 0;
	for(int i=1; i<neighbors.length; i++) {
	    if(((GameOfLife)neighbors[i]).condition == 1) {
		value++;
	    }
	}
	
	switch(value) {
	    case 2: break;
	    case 3: condition = 1; break;
	    default: condition = 0; break;
	}
    }
    /**
     * (7) add code for definition of constant states here
     * if the state class is used in lattices with constant boundary
     * conditions, it should return the constant state
     */
    public State getConstant() {
	return null;
    }
}


