Пример #1
0
        private static void FindPath(int row, int col)
        {
            if (SinglePath.isPossible)
            {
                return;
            }

            if (row == SinglePath.goalRowCoordinate && col == SinglePath.goalColCoordinate)
            {
                SinglePath.isPossible = true;
                return;
            }

            if (row + 1 < SinglePath.MatrixSize && !SinglePath.matrix[row + 1, col])
            {
                SinglePath.matrix[row + 1, col] = true;
                SinglePath.FindPath(row + 1, col);
                SinglePath.matrix[row + 1, col] = false;
            }

            if (col + 1 < SinglePath.MatrixSize && !SinglePath.matrix[row, col + 1])
            {
                SinglePath.matrix[row, col + 1] = true;
                SinglePath.FindPath(row, col + 1);
                SinglePath.matrix[row, col + 1] = false;
            }

            if (row - 1 >= 0 && !SinglePath.matrix[row - 1, col])
            {
                SinglePath.matrix[row - 1, col] = true;
                SinglePath.FindPath(row - 1, col);
                SinglePath.matrix[row - 1, col] = false;
            }

            if (col - 1 >= 0 && !SinglePath.matrix[row, col - 1])
            {
                SinglePath.matrix[row, col - 1] = true;
                SinglePath.FindPath(row, col - 1);
                SinglePath.matrix[row, col - 1] = false;
            }
        }
Пример #2
0
        public static void Main()
        {
            SinglePath.FindPath(0, 0);

            Console.WriteLine(SinglePath.isPossible);
        }