Sudoku::Generator Class Reference

Implementation of a backtracking algorithm to generate Sudoku puzzles. More...

#include <generator.h>

Inheritance diagram for Sudoku::Generator:
Inheritance graph
[legend]
Collaboration diagram for Sudoku::Generator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Generator (Puzzle &puzzle, unsigned int givens_count, bool symmetric=true, unsigned int max_iter=0)
 Constructor.
virtual void set_first_at (unsigned int level)
 Set the element to the first sibling.
virtual void set_next_at (unsigned int level)
 Set the element to the next sibling.
virtual void reset_at (unsigned int level)
 Reset the element.
virtual bool is_last_at (unsigned int level) const
 Check if the element is set to the last sibling.
virtual bool is_valid_at (int level) const
 Check if the element is valid (following elements ignored).
virtual bool is_last_level (int level) const
 Check if the level is the last possible level.

Private Attributes

Puzzlepuzzle
Puzzle sudoku
unsigned int free_list [SDIM]
unsigned int free_count
Pos pos_list [SDIM]
unsigned int pos_count
bool symmetric
bool free_center

Detailed Description

Implementation of a backtracking algorithm to generate Sudoku puzzles.

To generate Sudoku puzzles two nested backtracking algorithms are used. First a random Sudoku solution is searched. Then the algorithm tries to remove some numbers so that only the requested number of givens remains. Each puzzle is checked with the nested solver algorithm if there is only one solution.

Example:

 Puzzle puzzle;
 Generator generator(puzzle, 36);
 generator.find_next_solution();
 bool found = generator.solution_is_valid();

Definition at line 51 of file generator.h.


Constructor & Destructor Documentation

Generator::Generator ( Puzzle puzzle,
unsigned int  givens_count,
bool  symmetric = true,
unsigned int  max_iter = 0 
)

Member Function Documentation

bool Generator::is_last_at ( unsigned int  level  )  const [virtual]

Check if the element is set to the last sibling.

Implements BackTrack::Solution.

Definition at line 95 of file generator.cpp.

References free_count, free_list, and pos_count.

bool Generator::is_last_level ( int  level  )  const [virtual]

Check if the level is the last possible level.

Implements BackTrack::Solution.

Definition at line 137 of file generator.cpp.

References free_count.

bool Generator::is_valid_at ( int  level  )  const [virtual]
void Generator::reset_at ( unsigned int  level  )  [virtual]

Reset the element.

Implements BackTrack::Solution.

Definition at line 90 of file generator.cpp.

void Generator::set_first_at ( unsigned int  level  )  [virtual]

Set the element to the first sibling.

Implements BackTrack::Solution.

Definition at line 76 of file generator.cpp.

References free_count, and free_list.

void Generator::set_next_at ( unsigned int  level  )  [virtual]

Set the element to the next sibling.

Implements BackTrack::Solution.

Definition at line 83 of file generator.cpp.

References free_count, and free_list.


Member Data Documentation

Definition at line 60 of file generator.h.

Referenced by Generator(), and is_valid_at().

unsigned int Sudoku::Generator::free_count [private]

Definition at line 56 of file generator.h.

Referenced by Generator(), is_last_at(), is_last_level(), is_valid_at(), set_first_at(), and set_next_at().

unsigned int Sudoku::Generator::free_list[SDIM] [private]

Definition at line 55 of file generator.h.

Referenced by is_last_at(), is_valid_at(), set_first_at(), and set_next_at().

unsigned int Sudoku::Generator::pos_count [private]

Definition at line 58 of file generator.h.

Referenced by Generator(), is_last_at(), and is_valid_at().

Definition at line 57 of file generator.h.

Referenced by Generator(), and is_valid_at().

Definition at line 53 of file generator.h.

Referenced by is_valid_at().

Definition at line 54 of file generator.h.

Referenced by Generator(), and is_valid_at().

Definition at line 59 of file generator.h.

Referenced by is_valid_at().


The documentation for this class was generated from the following files:
Generated on Mon Apr 5 17:01:11 2010 for VDR plugin 'Sudoku' by  doxygen 1.6.3