Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="Cell"/> instance using its location and state from an environment.
        /// </summary>
        /// <param name="location">The location of the state to be created.</param>
        /// <param name="environment">It is used to get the <see cref="Cell"/>`s state.</param>
        /// <returns>The initialized <see cref="Cell"/> object.</returns>
        public static Cell Create(Point location, CAEnvironment environment)
        {
            var c = new Cell(location);
            var key = c.GetKey();

            if (environment.States.Contains(key))
            {
                c.State = true;
            }

            return c;
        }
        /// <summary>
        /// Gets and sets the new <see cref="Cell.State"/> of particular <see cref="Cell"/>.
        /// </summary>
        /// <param name="cell">The <see cref="Cell"/>, which <see cref="Cell.State"/> is pregenerated.</param>
        public bool SetCellState(Cell cell)
        {
            long key = cell.GetKey();
            if (_rule.CanBeActivated(cell, _neighbourhood.GetNeighbours(cell.Location, this)))
            {
                cell.State = true;
                if (!StatesNew.Contains(key))
                {
                    StatesNew.Add(key);
                }
            }
            else
            {
                cell.State = false;
                if (StatesNew.Contains(key))
                {
                    StatesNew.Remove(key);
                }
            }

            return cell.State;
        }