public static int[,] Solve(int[,] sudoku) { SudokuBoard board = new SudokuBoard(sudoku); board = Solve(board); sudoku = board.GetAsMultidimentionalArray(); return(sudoku); }
public static int[,] Create(SudokuBoard.BoardProperty boardProperty = SudokuBoard.BoardProperty.NineByNine) { Random random = new Random(); SudokuBoard solution = new SudokuBoard(boardProperty); solution.SetField(); solution = Solve(solution); int[,] sudoku = solution.GetAsMultidimentionalArray(); List <int[]> fields = new List <int[]>(); for (int x = 0; x < sudoku.GetLength(0); x++) { for (int y = 0; y < sudoku.GetLength(0); y++) { fields.Add(new int[] { x, y }); } } while (fields.Count() != 0) { int[,] newSudokuAttempt = CreateCopyOfArray(sudoku); int[] randomField = fields[random.Next(fields.Count())]; newSudokuAttempt[randomField[0], randomField[1]] = 0; solution.SetField(newSudokuAttempt); solution = Solve(solution, false); if (solution.Finished) { sudoku = newSudokuAttempt; } fields.Remove(randomField); } return(sudoku); }