Пример #1
0
        private bool Move(Position startPosition, out Position position)
        {
            var length = this.possibleDirections.Length;

            for (int i = 0; i < length; i++)
            {
                var possibleDirection = this.possibleDirections[this.currentDirection];
                var row = startPosition.Y + possibleDirection.Y;
                var column = startPosition.X + possibleDirection.X;

                if (this.matrix.IsValidCoordinate(row, column) && this.matrix[row, column] == 0)
                {
                    position = new Position(column, row);

                    return true;
                }

                this.currentDirection++;

                if (this.currentDirection == length)
                {
                    this.currentDirection = 0;
                }
            }

            position = default(Position);

            return false;
        }
Пример #2
0
        public void FirstOrDefaultZeroCellWithNotSetMatrix()
        {
            var matrix = new Matrix(3);
            var expected = new Position(0, 0);

            var actual = matrix.FirstOrDefaultZeroCell();

            Assert.AreEqual(expected.X, actual.X);
            Assert.AreEqual(expected.Y, actual.Y);
        }
Пример #3
0
        public void Start()
        {
            this.matrix = new Matrix(this.Size);

            Position currentPosition = new Position(0, 0);
            int cellValue = 0;

            do
            {
                this.currentDirection = 0;

                do
                {
                    this.matrix[currentPosition.Y, currentPosition.X] = ++cellValue;
                }
                while (this.Move(currentPosition, out currentPosition));

                currentPosition = this.matrix.FirstOrDefaultZeroCell();
            }
            while (currentPosition != null);
        }