Beispiel #1
0
void printAndSolve( Puzzle sudoku ) {

  cout << "\nThe given puzzle looks like this: \n\n";

  sudoku.printBoard();

  if (!sudoku.solve()) {
    printf("Cannot solve puzzle\n");
    exit(0);
  }
    
  cout << "\n\nThe solved puzzle looks like this: \n\n";

  sudoku.printBoard();
  cout << "\n\n";
}
Beispiel #2
0
int main(){
   Puzzle sudoku;
   cin >> sudoku;
   cout << "Unsolved Puzzle:" << endl;
   sudoku.display();
   cout << endl;
   //Solve returns true if solved, false if not.
   if (sudoku.solve(0, 0)) {
      cout << "Solved Puzzle:" << endl;
      sudoku.display();
      cout << endl;
   }
   else {
      cout << "Puzzle is unsolvable." << endl;
   }
   return 0;
}
void PartialSolver::solve()
{
    while(!puzzles.empty())
    {
        Puzzle& front = puzzles.front();
        ///Clear points to find points for next puzzle
        points.clear();
        findPoints(front.puzzle);
        list< pair<int,int> >::iterator it = points.begin();
        for(;it!=points.end(); it++)
        {
            int row = (*it).first;
            int col = (*it).second;
            Puzzle back = Puzzle(front);
            try
            {
                back.set(row, col, variable);
                back.solve();
                if(back.complete())
                {
                    if(back.correct())
                    {
                            solved.push_back(back);
                    }
                    else
                    {
                            incorrect.push_back(back);
                    }
                }
                else
                {
                    ///If the puzzle is still partially correct continue search
                    if(partiallyCorrect(back))
                        puzzles.push_back(back);
                }
            } catch (bool& value) {
                //incorrect.push_back(back);
            }
        }
        puzzles.pop_front();
    }
}