// Function to Contain Position Validity Checking bool isPositionValid(int * p, int val, int col, int row) { if (isBoxValid(p, val, col, row) && isRowValid(p, val, col, row) && isColValid(p, val, col)) return true; return false; }
/// /// \brief PuzzleGame::IsMovementLocallyPossible /// Verifies the feasibility of a movement /// \param row /// \param col /// \param num /// \return returns true if a movement is feasible within the board /// bool PuzzleGame::IsMovementLocallyPossible(int row, int col, int num) { if(isHorizontalNeighborGood(row,col,num) && isVerticalNeighborGood(row,col,num)) { pieces[row][col].setValue(num); if(isRowValid(row) && isColValid(col)) return true; setEmptyPiece(row,col); } return false; }
bool solve(vector<vector<char>>& board, int num) { if (num >= 81) return true; int row = num / 9; int col = num % 9; if (board[row][col] != '.') { return solve(board, num + 1); } else { for (char i = '1'; i <= '9'; i++) { if (isRowValid(board, row, i) && isColValid(board, col, i) && isBoardValid(board, row, col, i)) { board[row][col] = i; if (solve(board, num + 1) == true) return true; } } board[row][col] = '.'; } return false; }