Example #1
0
        internal int CurrentState(AreaPosition currentPosition)
        {
            if (!this.Board.AreaSize.InThisArea(currentPosition))
            {
                return(0);
            }

            return(this.Board[currentPosition] ? 1 : 0);
        }
Example #2
0
        internal int GetAliveNeighbors(AreaPosition currentPosition)
        {
            int aliveNeighbors = 0;

            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(-1, -1));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(0, -1));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(1, -1));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(-1, 0));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(1, 0));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(-1, 1));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(0, 1));
            aliveNeighbors += this.CurrentState(currentPosition.GetOffsetPosition(1, 1));

            return(aliveNeighbors);
        }
Example #3
0
        internal void ApplyCellRules(AreaPosition areaPosition, Board nextBoard)
        {
            int aliveNeighbors = this.GetAliveNeighbors(areaPosition);

            if (this.Board[areaPosition])
            {
                if (aliveNeighbors >= 2 && aliveNeighbors <= 3)
                {
                    nextBoard[areaPosition] = true;
                }
            }
            else
            {
                if (aliveNeighbors == 3)
                {
                    nextBoard[areaPosition] = true;
                }
            }
        }
Example #4
0
        public Board ImportComponent(AreaPosition componentOffset, Board component)
        {
            if (component is null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            this.Board.ForEachPositionInComponent(component,
                                                  componentOffset,
                                                  (boardPosition, componentPosition) =>
            {
                if (component[componentPosition])
                {
                    this.Board[boardPosition] = true;
                }
            });

            return(this.Board);
        }
Example #5
0
 public bool InThisArea(AreaPosition position)
 => position.X >= 0 && position.X < this.Width &&
 position.Y >= 0 && position.Y < this.Height;
Example #6
0
#pragma warning restore CA1819 // Properties should not return arrays

#pragma warning disable CA1043 // Use Integral Or String Argument For Indexers
        public bool this[AreaPosition areaPosition]
#pragma warning restore CA1043 // Use Integral Or String Argument For Indexers
        {
            get => this.Columns[areaPosition.X][areaPosition.Y];