Ejemplo n.º 1
0
 public void Reset()
 {
     // If we are handed an initial state then use it, else create a randomized matrix
     if (_initialState != null)
     {
         for (int x = 0; x < _columns; ++x)
         {
             for (int y = 0; y < _rows; ++y)
             {
                 int state = _initialState [x, y];
                 _matrix [x, y] = new AutomataCell(state, state);
             }
         }
     }
     else
     {
         for (int x = 0; x < _columns; ++x)
         {
             for (int y = 0; y < _rows; ++y)
             {
                 int state = _randomGenerator.Next(2);
                 _matrix [x, y] = new AutomataCell(state, state);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void VisitMatrix(Action <int> action)
 {
     for (int x = 0; x < _columns; ++x)
     {
         for (int y = 0; y < _rows; ++y)
         {
             AutomataCell cell = _matrix [x, y];
             action(cell.State);
         }
     }
 }
Ejemplo n.º 3
0
 public void VisitMatrix(AutomataCellVisitor action)
 {
     for (int x = 0; x < _columns; ++x)
     {
         for (int y = 0; y < _rows; ++y)
         {
             AutomataCell cell = _matrix [x, y];
             action(x, y, cell);
         }
     }
 }
Ejemplo n.º 4
0
        public int Evaluate(AutomataCell cell, int neighbors)
        {
            // Check the dead cells to see if they are born
            if (cell.State == 0)
            {
                if (_birthRule != null)
                {
                    return(_birthRule [neighbors]);
                }
                return(0);
            }

            // Check the living cell to see if it survives. Living cells keep track of how long
            // they've been living.
            if (_sustainRule != null)
            {
                if (_sustainRule [neighbors] > 0)
                {
                    return(cell.State + 1);
                }
            }
            return(0);
        }
Ejemplo n.º 5
0
 public void SetNextCell(int x, int y, AutomataCell cell)
 {
     _nextMatrix [x, y] = cell;
 }
Ejemplo n.º 6
0
 public void SetCell(int x, int y, AutomataCell cell)
 {
     _matrix [x, y] = cell;
 }