Games::Sudoku::Component::Controller
use Games::Sudoku::Component::Controller; # Let's create a default 9x9 puzzle. my $c = Games::Sudoku::Component::Controller->new; # Solve the (currently blank) puzzle $c->solve; # Then, make blanks $c->make_blank(50); # Voila! Let's see. $c->table->as_HTML; # If all you want is the result, just solve. $c->solve; # If you want to do something, then try this loop. until ($c->status->is_solved) { # Solve only one step forward (or backward) $c->next; # do something, such as updating a session file, printing # a result, etc. }
This is a main controller.
Returns Games::Sudoku::Component::Table, Games::Sudoku::::Component::Controller::History, Games::Sudoku::::Component::Controller::Status object respectively.
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
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).
Does what should be done next, i.e. finds a cell that has least value possibilities, decides which value should be set (or should be tried), rewinds a step while rewinding.
Finds a cell that has least value possibilities and decides which value should be set (or should be tried).
Tries to set a value of cell(row, column) to value. Though the value is not allowed in fact, the cell stores the value temporarily.
Finds all the cells that have least value possibilities.
Solves the puzzle that you generated or loaded. You can solve a 'blank' puzzle.
Makes specified number of blanks for the (solved) puzzle randomly. This is useful but the puzzles made through this method may have several solutions.
Rewinds a stacked step. Mainly used when the solver is stuck. However, this is only useful when possible solutions are few. When there are too much solutions, rewind_all may be a better choice.
rewind_all
Rewinds all the steps stacked in the history stack, i.e. restores the generated or loaded puzzle afresh. Mainly used when the solver is stuck several times. As next (or find_and_set) sets values a bit randomly, it tends to be faster to retry from the start than to rewind again and again.
next
find_and_set
Clears all (the generated or loaded puzzle, and history stack).
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.