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. Games::Sudoku::Component 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:
Specifies the size of a puzzle board (table). The default is 9. Actually this value is assumed to be a square of another integer.
Specify the width/height of internal blocks, respectively. (block_width x block_height = size)
block_width
block_height
size
Generates a puzzle. Options are:
Specifies how many blanks are there in the puzzle. The default is (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:
Specifies a separator between table columns. The default is a whitespace (' ').
Specifies a separator between table rows. The default is a line break ("\n").
Almost same as above but returns an HTML table. Options are:
Specifies a size of the table borders. The default is 1.
Specifies a separator between table tags. The default is a line break ("\n").
If set true, each cell has an 'even' or 'odd' class attribute. If your prepare an appropriate CSS, the table will be two-toned.
There are many Sudoku implementations around there. I haven't seen them all yet, but the POD of Games::Sudoku::General is a good starting point.
As for the details of Games::Sudoku::Component 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.
To install Games::Sudoku::Component, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::Sudoku::Component
CPAN shell
perl -MCPAN -e shell install Games::Sudoku::Component
For more information on module installation, please visit the detailed CPAN module installation guide.