コード例 #1
0
ファイル: Game.cs プロジェクト: ChrisTorng/GameOfLife
        internal int CurrentState(AreaPosition currentPosition)
        {
            if (!this.Board.AreaSize.InThisArea(currentPosition))
            {
                return(0);
            }

            return(this.Board[currentPosition] ? 1 : 0);
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: ChrisTorng/GameOfLife
        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);
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: ChrisTorng/GameOfLife
        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;
                }
            }
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: ChrisTorng/GameOfLife
        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);
        }
コード例 #5
0
 public bool InThisArea(AreaPosition position)
 => position.X >= 0 && position.X < this.Width &&
 position.Y >= 0 && position.Y < this.Height;
コード例 #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];