Kenichi Ishigaki > Games-Sudoku-Component > Games::Sudoku::Component::Controller

Download:
Games-Sudoku-Component-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Games::Sudoku::Component::Controller

SYNOPSIS ^

  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.
  }

DESCRIPTION ^

This is a main controller.

ACCESSOR ^

table

history

status

Returns Games::Sudoku::Component::Table, Games::Sudoku::::Component::Controller::History, Games::Sudoku::::Component::Controller::Status object respectively.

METHODS ^

new (hash or hashref)

Creates an object. Options are:

size

Specifies the size of a puzzle board (table). The default is 9. Actually this value is assumed to be a square of another integer.

block_width
block_height

Specify the width/height of internal blocks, respectively. (block_width x block_height = size)

load (string or hash or hashref)

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).

next

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.

find_and_set

Finds a cell that has least value possibilities and decides which value should be set (or should be tried).

set (row, column, value)

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.

find_hints

Finds all the cells that have least value possibilities.

solve

Solves the puzzle that you generated or loaded. You can solve a 'blank' puzzle.

make_blank (integer)

Makes specified number of blanks for the (solved) puzzle randomly. This is useful but the puzzles made through this method may have several solutions.

rewind

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.

clear

Clears all (the generated or loaded puzzle, and history stack).

SEE ALSO ^

Games::Sudoku::Component
Games::Sudoku::Component::Controller::History
Games::Sudoku::Component::Controller::Loader
Games::Sudoku::Component::Controller::Status
Games::Sudoku::Component::Table

AUTHOR ^

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: