Пример #1
0
 public void InputIncorrectValue_ShouldThrowException()
 {
     Coordinates cellA = new Coordinates(-1, 0);
     Coordinates cellB = new Coordinates(0, -4);
 }
Пример #2
0
 public void InputRightValue_ShouldWorkCorrectly()
 {
     Coordinates cell = new Coordinates(1, 1);
 }
Пример #3
0
 public void InputBoundValue_ShouldWorkCorrectly()
 {
     Coordinates cellFirst = new Coordinates(0, 0);
 }
Пример #4
0
        private Coordinates FindFirstEmptyTarget()
        {
            int rows = this.Field.GetLength(0);
            int columns = this.Field.GetLength(1);

            Coordinates newTarget = new Coordinates(0, 0);

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < columns; col++)
                {
                    if (this.Field[row, col] == 0)
                    {
                        this.currentTargetIndex = 0;
                        newTarget.Row = row;
                        newTarget.Col = col;
                        return newTarget;
                    }
                }
            }

            return null;
        }
Пример #5
0
        private void FillMatrix()
        {
            var target = new Coordinates(0, 0);
            var accumulate = 1;

            while (target != null)
            {
                this.Field[target.Row, target.Col] = accumulate;
                target = this.Walk(target) ?? this.FindFirstEmptyTarget();
                accumulate++;
            }
        }
Пример #6
0
        private Coordinates Walk(Coordinates target)
        {
            for (int index = this.currentTargetIndex; index < NUMBERS_DIRECTIONS + this.currentTargetIndex; index++)
            {
                int newTargetIndex = index % NUMBERS_DIRECTIONS;
                Coordinates nextTarget = target + this.targetDirections[newTargetIndex];
                if (this.IsValidWalk(nextTarget))
                {
                    this.currentTargetIndex = newTargetIndex;
                    return nextTarget;
                }
            }

            return null;
        }
Пример #7
0
        private bool IsValidWalk(Coordinates checkTarget)
        {
            int size = this.Size;

            return checkTarget.Row >= 0 && checkTarget.Row < size &&
                    checkTarget.Col >= 0 && checkTarget.Col < size &&
                    this.Field[checkTarget.Row, checkTarget.Col] == 0;
        }