Logo Search packages:      
Sourcecode: vdr-plugin-sudoku version File versions  Download package

Sudoku::Solver Class Reference

#include <solver.h>

Inheritance diagram for Sudoku::Solver:

BackTrack::Algorithm BackTrack::Solution

List of all members.


Detailed Description

Implementation of a backtracking algorithm to solve Sudoku puzzles

The algorithm tries to set numbers in all free cells of the puzzle sticking to the rules of Sudoku puzzles.

There are three ways to use this class:

1. Solve a Sudoku puzzle with some numbers given:

    Puzzle puzzle(36); // Generate a random puzzle with 36 givens.
    Solver solver(puzzle);
    solver.find_next_solution();
    if (solver.solution_is_valid())
    {
      // Do something with the puzzle.
      ...
    }
    solver.find_next_solution();
    bool more_than_one_solution = solver.solution_is_valid();

2. Search a random Sudoku solution:

    Puzzle puzzle; // Generate an empty puzzle without givens.
    Solver solver(puzzle, true);
    solver.find_next_solution();
    if (solver.solution_is_valid())
    {
      // Do something with the puzzle.
      ...
    }

3. Search all Sudoku solutions:

    Puzzle puzzle; // Generate an empty puzzle without givens.
    Solver solver(puzzle);
    solver.find_next_solution();
    while (solver.solution_is_valid())
    {
      // Do something with the puzzle.
      ...
      solver.find_next_solution();
    }

Definition at line 71 of file solver.h.


Public Member Functions

void find_next_solution ()
virtual bool is_last_at (unsigned int level) const
virtual bool is_last_level (int level) const
virtual bool is_valid_at (int level) const
void reset ()
virtual void reset_at (unsigned int level)
virtual void set_first_at (unsigned int level)
virtual void set_next_at (unsigned int level)
bool solution_is_valid ()
 Solver (Puzzle &puzzle, bool random_init=false, unsigned int max_iter=0)

Private Attributes

unsigned int free_count
Pos free_list [SDIM]
Puzzlepuzzle
bool random
bool random_init

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index