コード例 #1
0
ファイル: Matrix.cs プロジェクト: studware/Ange-Git
        /// <summary>
        /// Initializes static members of the <see cref="Matrix"/> class.
        /// </summary>
        static Matrix()
        {
            int directionsCount = Delta.DirectionsCount;
            deltas = new Delta[directionsCount];

            for (int i = 0; i < directionsCount; i++)
            {
                deltas[i] = new Delta((Direction)i);
            }
        }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: studware/Ange-Git
        /// <summary>
        /// Fills the matrix with consecutive integer values
        /// that correspond to the route of traversal.
        /// </summary>
        public void Traverse()
        {
            this.Clear();

            int counter = 1;
            Position position = new Position(0, 0);
            Delta delta = new Delta(Direction.Southeast);

            while (true)
            {
                this.matrix[position.Row, position.Col] = counter;

                if (!this.CanContinue(position))
                {
                    bool newPositionFound = this.TryFindNewPosition(out position);
                    if (newPositionFound)
                    {
                        counter++;
                        this.matrix[position.Row, position.Col] = counter;
                        delta.Direction = Direction.Southeast;
                    }
                    else
                    {
                        break;
                    }
                }

                while (!this.CanGoToPosition(position.Row + delta.Row, position.Col + delta.Col))
                {
                    delta.UpdateDirectionClockwise();
                }

                position.Update(delta);
                counter++;
            }
        }