.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Games::LMSolve::Base 3" .TH Games::LMSolve::Base 3 "2007-08-27" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" Games::LMSolve::Base \- base class for puzzle solvers. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package MyPuzzle::Solver; .Ve .PP .Vb 1 \& use Games::LMSolve::Base; .Ve .PP .Vb 1 \& @ISA = qw(Games::LMSolve::Base); .Ve .PP .Vb 1 \& # Override these methods: .Ve .PP .Vb 7 \& sub input_board { ... } \& sub pack_state { ... } \& sub unpack_state { ... } \& sub display_state { ... } \& sub check_if_final_state { ... } \& sub enumerate_moves { ... } \& sub perform_move { ... } .Ve .PP .Vb 3 \& # Optionally: \& sub render_move { ... } \& sub check_if_unsolvable { ... } .Ve .PP .Vb 1 \& package main; .Ve .PP .Vb 1 \& my $self = MyPuzzle::Solver->new(); .Ve .PP .Vb 1 \& $self->solve_board($filename); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class implements a generic solver for single player games. In order to use it, one must inherit from it and implement some abstract methods. Afterwards, its interface functions can be invoked to actually solve the game. .SH "METHODS" .IX Header "METHODS" .Sh "\fInew()\fP" .IX Subsection "new()" The constructor. .Sh "$self\->\fIinitialize()\fP" .IX Subsection "$self->initialize()" Should be inherited to implement the construction. .Sh "$self\->\fImain()\fP" .IX Subsection "$self->main()" Actually solve the board based on the arguments in the command line. .SH "METHODS TO OVERRIDE" .IX Header "METHODS TO OVERRIDE" .ie n .Sh "input_board($self, $file_spec)" .el .Sh "input_board($self, \f(CW$file_spec\fP)" .IX Subsection "input_board($self, $file_spec)" This method is responsible to read the \*(L"board\*(R" (the permanent parameters) of the puzzle and its initial state. It should place the board in the object's keys, and return the initial state. (in unpacked format). .PP Note that \f(CW$file_spec\fR can be either a filename (if it's a string) or a reference to a filehandle, or a reference to the text of the board. \fIinput_board()\fR should handle all cases. .PP You can look at the Games::LMSolve::Input module for methods that facilitate inputting a board. .ie n .Sh "pack_state($self, $state_vector)" .el .Sh "pack_state($self, \f(CW$state_vector\fP)" .IX Subsection "pack_state($self, $state_vector)" This function accepts a state in unpacked form and should return it in packed format. A state in unpacked form can be any perl scalar (as complex as you like). A state in packed form must be a string. .ie n .Sh "unpack_state($self, $packed_state)" .el .Sh "unpack_state($self, \f(CW$packed_state\fP)" .IX Subsection "unpack_state($self, $packed_state)" This function accepts a state in a packed form and should return it in its expanded form. .ie n .Sh "display_state($self, $packed_state)" .el .Sh "display_state($self, \f(CW$packed_state\fP)" .IX Subsection "display_state($self, $packed_state)" Accepts a packed state and should return the user-readable string representation of the state. .ie n .Sh "check_if_final_state($self, $state_vector)" .el .Sh "check_if_final_state($self, \f(CW$state_vector\fP)" .IX Subsection "check_if_final_state($self, $state_vector)" This function should return 1 if the expanded state \f(CW$state_vector\fR is a final state, and the game is over. .ie n .Sh "enumerate_moves($self, $state_vector)" .el .Sh "enumerate_moves($self, \f(CW$state_vector\fP)" .IX Subsection "enumerate_moves($self, $state_vector)" This function accepts an expanded state and should return an array of moves that can be performed on this state. .ie n .Sh "perform_move($self, $state_vector\fP, \f(CW$move)" .el .Sh "perform_move($self, \f(CW$state_vector\fP, \f(CW$move\fP)" .IX Subsection "perform_move($self, $state_vector, $move)" This method accepts an expanded state and a move. It should try to peform the move on the state. If it is successful, it should return the new state. Else, it should return undef, to indicate that the move cannot be performed. .ie n .Sh "check_if_unsolvable($self, $state_vector) (optional over\-riding)" .el .Sh "check_if_unsolvable($self, \f(CW$state_vector\fP) (optional over\-riding)" .IX Subsection "check_if_unsolvable($self, $state_vector) (optional over-riding)" This method returns the verdict if \f(CW$state_vector\fR cannot be solved. This method defaults to returning 0, and it is usually safe to keep it that way. .ie n .Sh "render_move($self, $move) (optional overriding)" .el .Sh "render_move($self, \f(CW$move\fP) (optional overriding)" .IX Subsection "render_move($self, $move) (optional overriding)" This function returns the user-readable stringified represtantion of a move. .SH "API" .IX Header "API" .ie n .Sh "$self\->solve_board($file_spec, %args)" .el .Sh "$self\->solve_board($file_spec, \f(CW%args\fP)" .IX Subsection "$self->solve_board($file_spec, %args)" Solves the board specification specified in \f(CW$file_spec\fR. \f(CW%args\fR specifies optional arguments. Currently there is one: 'max_iters' that specifies the maximal iterations to run. .PP Returns whatever run_scan returns. .Sh "$self\->run_scan(%args)" .IX Subsection "$self->run_scan(%args)" Continues the current scan. \f(CW%args\fR may contain the 'max_iters' parameter to specify a maximal iterations limit. .PP Returns two values. The first is a progress indicator. \*(L"solved\*(R" means the puzzle was solved. \*(L"unsolved\*(R" means that all the states were covered and the puzzle was proven to be unsolvable. \*(L"interrupted\*(R" means that the scan was interrupted in the middle, and could be proved to be either solvable or unsolvable. .PP The second argument is the final state and is valid only if the progress value is \*(L"solved\*(R". .Sh "$self\->\fIget_num_iters()\fP" .IX Subsection "$self->get_num_iters()" Retrieves the current number of iterations. .ie n .Sh "$self\->display_solution($progress_code, $final_state)" .el .Sh "$self\->display_solution($progress_code, \f(CW$final_state\fP)" .IX Subsection "$self->display_solution($progress_code, $final_state)" If you input this message with the return value of \fIrun_scan()\fR you'll get a nice output of the moves to stdout. .Sh "$self\->set_run_time_states_display(\e&states_display_callback)" .IX Subsection "$self->set_run_time_states_display(&states_display_callback)" Sets the run time states display callback to \e&states_display_callback. .PP This display callback accepts a reference to the solver and also the following arguments in key => value pairs: .PP \&\*(L"state\*(R" \- the expanded state. \&\*(L"depth\*(R" \- the depth of the state. \&\*(L"move\*(R" \- the move leading to this state from its parent. .SH "SEE ALSO" .IX Header "SEE ALSO" Games::LMSolve::Input .SH "AUTHORS" .IX Header "AUTHORS" Shlomi Fish,