NAME

Games::Sudoku::PatternSolver::Generator - produces 9x9 Sudoku solution grids and 9x9 Sudoku puzzles

DESCRIPTION

This sub module uses the Games::Sudoku::PatternSolver's POM ability (Pattern Overlay Method) to build solution grids and enables PatternSolver::CPLogic to provide some indication of rating with the generated puzzles.

You may supply a grid of your liking to begin with, but it really doesn't matter because it is the (always) random order in which cell values are tried to be removed that make the essential difference, not the grid at launching point.

All Sudoku that are returned from the iterator builder are well-posed (have a unique solution) and reduced (removing any of the givens would lead to > 1 solution).

METHODS

get_sudoku_builder()

$sudoku_builder = get_sudoku_builder( start_grid, start_with, shuffle_symbols );

All 3 parameters are optional:

  • start_grid (default none)

    A grid string (81 chars) to start from, typically a complete solution as produced by the grid_builder.

    If a start grid is passed, the iterator will never replace it with another one. It will just be used over and over again, values removed in another random sequence. The generated puzzles in this case, despite being all different in nature, will all share the same solution.

    If you pass a grid with any missing values (a puzzle) it will just be checked and reported if the puzzle could be reduced any further and still be well-formed.

  • start_with (default 40)

    Number of random values to drop from the grid before checking the number of solutions for uniqueness kicks in. A smaller number could lead to more unnecessary solution checking up front. Too big a number might start the checking too often on a grid already overly reduced, which has more than one solution and has thus to start over.

  • shuffle_symbols (default true)

    If false (and no start_grid was given), all puzzle's solutions will have the first row '123456789'.

The return value $sudoku_builder is a subref which on every call will return a result hash from its last call to Patternsolver::solve():

while (my $puzzle = &$sudoku_builder()) { 
		... inspect and either reject or do something with $puzzle
		print $puzzle->{strPuzzle}; 
}

get_grid_builder()

$grid_builder = get_grid_builder();
$solution_string = &$grid_builder( <shuffle_symbols> ); 

The iterator returned from get_grid_builder() can produce fully filled sudoku grids at a fairly high rate. Like the solver, it also uses plain overlay of random patterns (POM) and no biased methods. (As the Latin Squares would.) The grids are spread absolutely randomly across the Sudoku space.

EXPORTS

The module optionally exports get_sudoku_builder(), get_grid_builder() and provides the import tag ':all'.

SCRIPTS

sudogen

After installation of Games::Sudoku::PatternSolver this command line script should be in your path. Flexible output options are available. Invoke >sudogen -h for details.

SEE ALSO

Games::Sudoku::Html to play entire lists of standard sudoku interactively in your browser

Games::Sudoku::Pdf to create pdf files from sixteen variants of 9x9 sudoku

AUTHOR

Steffen Heinrich

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.