Beispiel #1
0
        private ICAConfig BuildConfiguration(IProjection <ICell> grid)
        {
            CAConfig configuration = new CAConfig(_memory.GetObjects().Count, grid.GetObjects()[0].GetDefaultState());

            foreach (ICell cell in grid.GetObjects())
            {
                configuration.AddCellState(cell, cell.GetState());
            }

            return(configuration);
        }
Beispiel #2
0
        /**
         * The CA evolves to a new state, according to the behavior of each cell.
         * The old generations is archieved in the list of generations
         */
        public ICAConfig Update()
        {
            currentTime++;
            CAConfig nextConfiguration = new CAConfig(_memory.GetObjects().Count, grid.GetObjects()[0].GetDefaultState());

            foreach (ICell cell in grid.GetObjects())
            {
                //do not alter the cells' states directly
                //as the states affect the evolution
                //the result of the evolution is saved
                //and the cells are updated when all cells evolved
                CellState evolvedCellState = cell.UpdateState();
                nextConfiguration.AddCellState(cell, evolvedCellState);
            }
            //update the cells's states according to the evolution
            foreach (ICell cell in grid.GetObjects())
            {
                cell.SetState(nextConfiguration.GetCellState(cell));
            }

            return(nextConfiguration);
        }