Ejemplo n.º 1
0
        //calculate the cell value by looking at the neighbouring cells
        private Cell calculateCell(Cell current, Cell left, Cell right)
        {
            Cell c = new Cell();
            //rule 1:   if both of the neighbouring cells have a state equal to the
            //          next state, then the cell is changed to the previous state.
            if (left.getState == current.getNextState && right.getState == current.getNextState)
            {
                c.setState(c.getPreviousState);
            }
            //rule 2:   if only one of the neighbouring cells has a state equal to
            //          the next state, then the cell is changed to the next state.
            else if (left.getState == current.getNextState || right.getState == current.getNextState)
            {
                c.setState(current.getNextState);
            }

            //rule 3:   if both neighbours have the same state as the current cell, then 
            //          the current cell is changed to the next state.
            else if (current.getState == left.getState && current.getState == right.getState)
            {
                c.setState(current.getNextState);
            }
            //rule 4:   if none of the above rules apply, leave the cell unchanged.
            else
            {
                return c;
            }            
            return c;
        }
Ejemplo n.º 2
0
 //scramble every cell in the cells array using a random integer
 public void scrambleCells(int number) 
 {
     generation++;
     Random r = new Random(number);
     int move;
     for (int i = 0; i < GRIDSIZE; i++)
     {
         move = r.Next(3);
         cells[i] = new Cell(move);
     }
 }
Ejemplo n.º 3
0
 public String name(Cell c) // return the value of the cell
 {
     return c.name();
 }