private bool TryVisitCell(string[,] matrix, Cell cell) { if (this.IsCellAccessible(matrix, cell)) { matrix[cell.X, cell.Y] = cell.Value.ToString(); return true; } return false; }
private bool IsCellAccessible(string[,] matrix, Cell cell) { long rows = matrix.GetLongLength(0), cols = matrix.GetLongLength(1); int row = cell.X, col = cell.Y; if (row < 0 || row >= rows || col < 0 || col >= cols || matrix[row, col] != EmptySign) { return false; } return true; }
private void FindPathsRecursively(string[,] matrix, Cell cell) { var currentCell = cell; int x = currentCell.X, y = currentCell.Y, nextValue = currentCell.Value + 1; // Bottom of recursion if (!this.TryVisitCell(matrix, currentCell) && currentCell.Value != 0) { return; } this.FindPathsRecursively(matrix, new Cell(x + 1, y, nextValue)); this.FindPathsRecursively(matrix, new Cell(x - 1, y, nextValue)); this.FindPathsRecursively(matrix, new Cell(x, y + 1, nextValue)); this.FindPathsRecursively(matrix, new Cell(x, y - 1, nextValue)); }