private void CreateRowsInPreviousState()
 {
     for (int row = 0; row < RowCount; row++)
     {
         PreviousState.Add(new List <ICell>());
     }
 }
コード例 #2
0
ファイル: FixedUniverse.cs プロジェクト: WiseErni/LifeInForms
        public override bool Update()
        {
            // Add the begining state
            if (PreviousState.Count == 0)
            {
                PreviousState.Add(getStateFromCells(CellMatrix));
            }
            // Checking which cells need to be updated
            // Doing so without inplace updates to exclude grid corruption
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    CellMatrix[i, j].CheckAliveState();
                }
            }
            // Update the changed cells
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (CellMatrix[i, j].NeedUpdate)
                    {
                        CellMatrix[i, j].IsAlive    = CellMatrix[i, j].NewState;
                        CellMatrix[i, j].NeedUpdate = false;
                    }
                }
            }

            if (CheckPreviousStates(getStateFromCells(CellMatrix)))
            {
                PreviousState.Add(getStateFromCells(CellMatrix));
                return(true);
            }
            else
            {
                return(false);
            }
        }