Esempio n. 1
0
 public void CompleteTask()
 {
     this.writer.AutoFlush = true;
     Matrix exampleMatrix = new Matrix();
     this.TraversePath(exampleMatrix, 1);
     this.ReplaceNonVisitedCells(exampleMatrix);
     System.Console.WriteLine(exampleMatrix.ToString());
     this.writer.WriteLine(exampleMatrix.ToString());
 }
Esempio n. 2
0
        public void CompleteTask()
        {
            this.writer.AutoFlush = true;
            Matrix exampleMatrix = new Matrix();

            this.TraversePath(exampleMatrix, 1);
            this.ReplaceNonVisitedCells(exampleMatrix);
            System.Console.WriteLine(exampleMatrix.ToString());
            this.writer.WriteLine(exampleMatrix.ToString());
        }
Esempio n. 3
0
        private void TraversePath(Matrix matrix, int counter)
        {
            int row = matrix.StartRow;
            int col = matrix.StartCol;

            //// System.Console.WriteLine(matrix.ToString());
            this.writer.WriteLine(matrix.ToString());

            //// up
            if (row - 1 >= 0 && !"x*".Contains(matrix.Content[row - 1, col]))
            {
                if (matrix.Content[row - 1, col] == "0" || int.Parse(matrix.Content[row - 1, col]) > counter)
                {
                    matrix.Content[row - 1, col] = counter.ToString();
                    matrix.StartRow = row - 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartRow = row;
                }
            }

            //// left
            if (col - 1 >= 0 && !"x*".Contains(matrix.Content[row, col - 1]))
            {
                if (matrix.Content[row, col - 1] == "0" || int.Parse(matrix.Content[row, col - 1]) > counter)
                {
                    matrix.Content[row, col - 1] = counter.ToString();
                    matrix.StartCol = col - 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartCol = col;
                }
            }

            //// right
            if (col + 1 < matrix.Content.GetLength(0) && !"x*".Contains(matrix.Content[row, col + 1]))
            {
                if (matrix.Content[row, col + 1] == "0" || int.Parse(matrix.Content[row, col + 1]) > counter)
                {
                    matrix.Content[row, col + 1] = counter.ToString();
                    matrix.StartCol = col + 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartCol = col;
                }
            }

            //// down
            if (row + 1 < matrix.Content.GetLength(1) && !"x*".Contains(matrix.Content[row + 1, col]))
            {
                if (matrix.Content[row + 1, col] == "0" || int.Parse(matrix.Content[row + 1, col]) > counter)
                {
                    matrix.Content[row + 1, col] = counter.ToString();
                    matrix.StartRow = row + 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartRow = row;
                }
            }
        }
Esempio n. 4
0
        private void TraversePath(Matrix matrix, int counter)
        {
            int row = matrix.StartRow;
            int col = matrix.StartCol;

            //// System.Console.WriteLine(matrix.ToString());
            this.writer.WriteLine(matrix.ToString());

            //// up
            if (row - 1 >= 0 && !"x*".Contains(matrix.Content[row - 1, col]))
            {
                if (matrix.Content[row - 1, col] == "0" || int.Parse(matrix.Content[row - 1, col]) > counter)
                {
                    matrix.Content[row - 1, col] = counter.ToString();
                    matrix.StartRow = row - 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartRow = row;
                }
            }

            //// left
            if (col - 1 >= 0 && !"x*".Contains(matrix.Content[row, col - 1]))
            {
                if (matrix.Content[row, col - 1] == "0" || int.Parse(matrix.Content[row, col - 1]) > counter)
                {
                    matrix.Content[row, col - 1] = counter.ToString();
                    matrix.StartCol = col - 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartCol = col;
                }
            }

            //// right
            if (col + 1 < matrix.Content.GetLength(0) && !"x*".Contains(matrix.Content[row, col + 1]))
            {
                if (matrix.Content[row, col + 1] == "0" || int.Parse(matrix.Content[row, col + 1]) > counter)
                {
                    matrix.Content[row, col + 1] = counter.ToString();
                    matrix.StartCol = col + 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartCol = col;
                }
            }

            //// down
            if (row + 1 < matrix.Content.GetLength(1) && !"x*".Contains(matrix.Content[row + 1, col]))
            {
                if (matrix.Content[row + 1, col] == "0" || int.Parse(matrix.Content[row + 1, col]) > counter)
                {
                    matrix.Content[row + 1, col] = counter.ToString();
                    matrix.StartRow = row + 1;
                    this.TraversePath(matrix, counter + 1);
                    matrix.StartRow = row;
                }
            }
        }