#include <puzzle.h>
Public Member Functions | |
Puzzle (const char *dump=0) | |
Constructor. | |
Puzzle (unsigned int givens_count, bool symmetric=true) | |
Constructor with generation of a random puzzle. | |
virtual | ~Puzzle () |
Destructor. | |
virtual const char * | get_dump () const |
Get the puzzle as dump. | |
virtual void | reset () |
Reset the puzzle (including marks). | |
virtual void | reset (bool clear_marks) |
Reset the puzzle (either with or without marks). | |
virtual void | set (Pos pos, unsigned int number) |
Set the number into this cell. | |
virtual void | load_from_dump (const char *dump) |
Load a puzzle from a dump. | |
void | generate (unsigned int givens_count, bool symmetric=true) |
Generate a new puzzle. | |
void | set_givens (const Numbers &sudoku, const bool given_marks[SDIM]) |
Set givens from contents of sudoku if marked in given_marks. | |
void | clear_givens () |
Remove all givens. | |
bool | untouched () const |
No cells set? | |
bool | given (Pos pos) const |
Is the number in this cell given? | |
bool | error (Pos pos) const |
Is there an error on this position? | |
bool | ambiguous (Pos pos) const |
Is the number in this cell ambiguous? | |
bool | solved () const |
All cells set and no errors? | |
bool | marked (Pos pos) const |
Is this cell marked? | |
void | toggle_mark (Pos pos) |
Toggle the mark for this cell. | |
Pos | next_cell (Pos pos=Pos::last()) const |
Get the next free cell with minimal possible numbers. | |
unsigned int | next_number (Pos pos) const |
Get the next possible number for this cell. | |
unsigned int | numbers_count (Pos pos) const |
Get the count of possible numbers for this cell. | |
bool | possible_number (Pos pos, unsigned int number) const |
Is this number in this cell a possible number? | |
Private Member Functions | |
Puzzle (const Puzzle &other) | |
Puzzle & | operator= (const Puzzle &other) |
void | compute_numbers (Pos pos) |
Compute all possible numbers for this cell. | |
bool | correct (Pos pos) const |
Is the number in this cell a possible number? | |
Private Attributes | |
Numbers | givens |
Numbers | marks |
bool | numbers [SDIM][DIM+1] |
unsigned int | count [SDIM] |
char * | puzzle_dump |
Sudoku puzzle.
Definition at line 122 of file puzzle.h.
Sudoku::Puzzle::Puzzle | ( | const Puzzle & | other | ) | [private] |
Puzzle::Puzzle | ( | const char * | dump = 0 |
) |
Constructor.
Definition at line 114 of file puzzle.cpp.
References load_from_dump(), and puzzle_dump.
Puzzle::Puzzle | ( | unsigned int | givens_count, | |
bool | symmetric = true | |||
) |
Constructor with generation of a random puzzle.
Definition at line 123 of file puzzle.cpp.
References clear_givens(), generate(), and puzzle_dump.
Puzzle::~Puzzle | ( | ) | [virtual] |
bool Puzzle::ambiguous | ( | Pos | pos | ) | const |
Is the number in this cell ambiguous?
Definition at line 281 of file puzzle.cpp.
References count, and Sudoku::Pos::last().
Referenced by SudokuPlugin::Menu::paint().
void Puzzle::clear_givens | ( | ) |
Remove all givens.
Definition at line 250 of file puzzle.cpp.
References givens, reset(), and Sudoku::Numbers::reset().
Referenced by Puzzle().
void Puzzle::compute_numbers | ( | Pos | pos | ) | [private] |
Compute all possible numbers for this cell.
Definition at line 354 of file puzzle.cpp.
References count, Sudoku::DIM, Sudoku::Pos::first(), Sudoku::Pos::last(), and numbers.
bool Puzzle::correct | ( | Pos | pos | ) | const [private] |
Is the number in this cell a possible number?
Definition at line 379 of file puzzle.cpp.
References count, Sudoku::Pos::last(), and numbers.
bool Puzzle::error | ( | Pos | pos | ) | const |
Is there an error on this position?
Definition at line 274 of file puzzle.cpp.
References correct(), and Sudoku::Pos::last().
Referenced by Sudoku::Solver::is_valid_at(), and SudokuPlugin::Menu::paint().
void Puzzle::generate | ( | unsigned int | givens_count, | |
bool | symmetric = true | |||
) |
Generate a new puzzle.
Definition at line 230 of file puzzle.cpp.
References BackTrack::Algorithm::find_next_solution(), reset(), and BackTrack::Algorithm::solution_is_valid().
Referenced by SudokuPlugin::Menu::generate(), and Puzzle().
const char * Puzzle::get_dump | ( | ) | const [virtual] |
Get the puzzle as dump.
Reimplemented from Sudoku::Numbers.
Definition at line 141 of file puzzle.cpp.
References Sudoku::DIM, Sudoku::Numbers::get_dump(), givens, marks, puzzle_dump, Sudoku::SDIM, and untouched().
Referenced by SudokuPlugin::Menu::save(), Test_Solver::test_SearchFirstSudoku(), and Test_Solver::test_SolveHardSudoku().
bool Puzzle::given | ( | Pos | pos | ) | const |
Is the number in this cell given?
Definition at line 267 of file puzzle.cpp.
References Sudoku::Numbers::get(), givens, and Sudoku::Pos::last().
Referenced by next_number(), SudokuPlugin::Menu::paint(), set(), Sudoku::PuzzleGame::set_with_history(), Sudoku::Solver::Solver(), Test_Puzzle::test_PuzzleEmpty(), and Test_Puzzle::test_PuzzleNumbers().
void Puzzle::load_from_dump | ( | const char * | dump | ) | [virtual] |
Load a puzzle from a dump.
Reimplemented from Sudoku::Numbers.
Definition at line 205 of file puzzle.cpp.
References Sudoku::Numbers::get(), givens, Sudoku::Numbers::load_from_dump(), marks, numbers, reset(), and Sudoku::SDIM.
Referenced by SudokuPlugin::Menu::ProcessKey(), and Puzzle().
bool Puzzle::marked | ( | Pos | pos | ) | const |
Is this cell marked?
Definition at line 298 of file puzzle.cpp.
References Sudoku::Numbers::get(), Sudoku::Pos::last(), and marks.
Referenced by SudokuPlugin::Menu::paint().
Get the next free cell with minimal possible numbers.
Definition at line 312 of file puzzle.cpp.
References count, Sudoku::DIM, and Sudoku::SDIM.
Referenced by SudokuPlugin::Menu::next_cell(), and Sudoku::Solver::set_first_at().
unsigned int Puzzle::next_number | ( | Pos | pos | ) | const |
Get the next possible number for this cell.
Definition at line 324 of file puzzle.cpp.
References Sudoku::DIM, given(), Sudoku::Pos::last(), and numbers.
Referenced by Sudoku::Solver::is_last_at(), SudokuPlugin::Menu::next_number(), Sudoku::Solver::set_first_at(), and Sudoku::Solver::set_next_at().
unsigned int Puzzle::numbers_count | ( | Pos | pos | ) | const |
Get the count of possible numbers for this cell.
Definition at line 339 of file puzzle.cpp.
References count, and Sudoku::Pos::last().
Referenced by Sudoku::Solver::set_first_at().
bool Puzzle::possible_number | ( | Pos | pos, | |
unsigned int | number | |||
) | const |
Is this number in this cell a possible number?
Definition at line 346 of file puzzle.cpp.
References Sudoku::DIM, Sudoku::Pos::last(), and numbers.
Referenced by SudokuPlugin::Menu::paint().
void Puzzle::reset | ( | bool | clear_marks | ) | [virtual] |
Reset the puzzle (either with or without marks).
Reimplemented in Sudoku::PuzzleGame.
Definition at line 170 of file puzzle.cpp.
References compute_numbers(), Sudoku::Numbers::get(), givens, marks, Sudoku::Numbers::reset(), Sudoku::SDIM, and Sudoku::Numbers::set().
void Puzzle::reset | ( | ) | [virtual] |
Reset the puzzle (including marks).
Reimplemented from Sudoku::Numbers.
Reimplemented in Sudoku::PuzzleGame.
Definition at line 164 of file puzzle.cpp.
Referenced by clear_givens(), generate(), Sudoku::Generator::Generator(), load_from_dump(), and set_givens().
void Puzzle::set | ( | Pos | pos, | |
unsigned int | number | |||
) | [virtual] |
Set the number into this cell.
Reimplemented from Sudoku::Numbers.
Definition at line 188 of file puzzle.cpp.
References compute_numbers(), Sudoku::DIM, Sudoku::Pos::first(), given(), and Sudoku::Pos::last().
Referenced by Sudoku::SetMove::execute(), Sudoku::Solver::reset_at(), Sudoku::Solver::set_first_at(), Sudoku::Solver::set_next_at(), and Sudoku::SetMove::takeBack().
void Puzzle::set_givens | ( | const Numbers & | sudoku, | |
const bool | given_marks[SDIM] | |||
) |
Set givens from contents of sudoku if marked in given_marks.
Definition at line 243 of file puzzle.cpp.
References givens, reset(), and Sudoku::Numbers::set_contents().
Referenced by Sudoku::Generator::is_valid_at(), and solve_puzzle().
bool Puzzle::solved | ( | ) | const |
All cells set and no errors?
Definition at line 288 of file puzzle.cpp.
References correct(), and Sudoku::SDIM.
Referenced by Sudoku::Solver::is_valid_at(), and SudokuPlugin::Menu::ProcessKey().
void Puzzle::toggle_mark | ( | Pos | pos | ) |
Toggle the mark for this cell.
Definition at line 305 of file puzzle.cpp.
References Sudoku::Numbers::get(), Sudoku::Pos::last(), marks, and Sudoku::Numbers::set().
Referenced by SudokuPlugin::Menu::toggle_mark().
bool Puzzle::untouched | ( | ) | const |
No cells set?
Definition at line 257 of file puzzle.cpp.
References Sudoku::Numbers::get(), givens, and Sudoku::SDIM.
Referenced by get_dump().
unsigned int Sudoku::Puzzle::count[SDIM] [private] |
Definition at line 127 of file puzzle.h.
Referenced by ambiguous(), compute_numbers(), correct(), next_cell(), and numbers_count().
Numbers Sudoku::Puzzle::givens [private] |
Definition at line 124 of file puzzle.h.
Referenced by clear_givens(), get_dump(), given(), load_from_dump(), reset(), set_givens(), and untouched().
Numbers Sudoku::Puzzle::marks [private] |
Definition at line 125 of file puzzle.h.
Referenced by get_dump(), load_from_dump(), marked(), reset(), and toggle_mark().
bool Sudoku::Puzzle::numbers[SDIM][DIM+1] [private] |
Definition at line 126 of file puzzle.h.
Referenced by compute_numbers(), correct(), load_from_dump(), next_number(), and possible_number().
char* Sudoku::Puzzle::puzzle_dump [mutable, private] |
Definition at line 128 of file puzzle.h.
Referenced by get_dump(), Puzzle(), and ~Puzzle().