LEVEL SudokuSolverWrapper::getGameLevel(const string game) { SudokuSolverEngine sudokuSolver(game, false); if (sudokuSolver.checkIfHasSolution()) { sudokuSolver.Solve(); return sudokuSolver.getLevel(); } return INVALID; }
vector<int> SudokuSolverWrapper::solveGame(const string game) { SudokuSolverEngine sudokuSolver(game, false); if (sudokuSolver.checkIfHasSolution()) { sudokuSolver.Solve(); return sudokuSolver.getSolution(); } else return vector<int>(0); }
// Backtracking algorithm bool sudokuSolver(vector<vector<char> > &board) { for (int i = 0; i < 9; ++ i) { for (int j = 0; j < 9; ++ j) { if (board[i][j] == '.') { for (int k = 0; k < 9; ++ k) { board[i][j] = k + '1'; if (isValidSudoku(board, i, j) && sudokuSolver(board)) return true; board[i][j] = '.'; } return false; } } } return true; }
void solveSudoku(vector<vector<char> > &board) { sudokuSolver(board); }