|
Games::Sudoku::Component - provides APIs for Sudoku solver/generator |
Games::Sudoku::Component - provides APIs for Sudoku solver/generator
use Games::Sudoku::Component;
# Let's create a Sudoku object first.
my $sudoku = Games::Sudoku::Component->new(
size => 9,
);
# Then, generate a new Sudoku puzzle. This may take minutes.
$sudoku->generate(
blanks => 50,
);
# Or, you can load puzzle data from text file.
$sudoku->load(
filename => 'puzzle.txt',
);
# Let's see if the puzzle is created successfully.
print $sudoku->as_string(
separator => ' ',
linebreak => "\n",
);
# Then solve the puzzle. This may take minutes, too. # Solver may fail sometimes, especially the puzzle is large, # but it automatically tries another solution(s) if possible.
$sudoku->solve;
# Check the result.
print $sudoku->is_solved ? 'solved' : 'gave up';
# You can output the result as an HTML table, too.
print $sudoku->as_HTML;
This is yet another Sudoku (Numberplace) solver/generator. the Games::Sudoku::Component manpage provides common (but rather limited) methods to make it easy to play Sudoku -- just for example.
Actually, this module set is written to provide 'controller' APIs to other applications. You can easily integrate this with CGI or Perl/Tk application. See appropriate PODs for details.
Creates an object. Options are:
block_width x block_height = size)
Generates a puzzle. Options are:
size x size x 0.75).
Loads and parses puzzle data from file or string. If there is only one argument, it is assumed to be raw puzzle data.
$sudoku->load(<<'EOT'); 4 . . . . 1 2 1 . . 5 . 3 5 1 2 6 . 1 . . . 3 . 6 . . 5 1 2 5 . . . 4 6 EOT
If the argument seems to be a hash, data will be loaded from $hash{filename} (or $hash{file}, for short).
Solves the puzzle that you generated or loaded. You can solve a 'blank' puzzle. In fact, that is how it generates a new puzzle.
Returns true if the puzzle is solved.
Clears the generated or loaded puzzle.
Returns the stringified puzzle. Options are:
Almost same as above but returns an HTML table. Options are:
There are many Sudoku implementations around there. I haven't seen them all yet, but the POD of the Games::Sudoku::General manpage is a good starting point.
As for the details of the Games::Sudoku::Component manpage modules, see:
Kenichi Ishigaki, <ishigaki@cpan.org>
Copyright (C) 2006 by Kenichi Ishigaki
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Games::Sudoku::Component - provides APIs for Sudoku solver/generator |