Games::Mastermind::Solver - a Master Mind puzzle solver
# a trivial Mastermind solver use Games::Mastermind; use Games::Mastermind::Solver::BruteForce; my $player = Games::Mastermind::Solver::BruteForce ->new( Games::Mastermind->new ); my $try; print join( ' ', @{$player->game->code} ), "\n\n"; until( $player->won || ++$try > 10 ) { my( $win, $guess, $result ) = $player->move; print join( ' ', @$guess ), ' ', 'B' x $result->[0], 'W' x $result->[1], "\n"; }
Games::Mastermind::Solver is a base class for Master Mind solvers.
Games::Mastermind::Solver
$player = Games::Mastermind::Solver->new( $game );
Constructor. Takes a Games::Mastermind object as argument.
Games::Mastermind
( $won, $guess, $result ) = $player->move; ( $won, $guess, $result ) = $player->move( $guess );
The player chooses a suitable move to continue the game, plays it against the game object passed as constructor and updates its knowledge of the solution. The $won return value is a boolean, $guess is an array reference holding the value passed to Games::Mastermind::play and $result is the value returned by play.
$won
$guess
Games::Mastermind::play
$result
play
It is possible to pass an array reference as the move to make.
$number = $player->remaining;
The number of possible solutions given the knowledge the player has accumulated.
$player->reset;
Resets the internal state of the player.
$guess = $player->guess;
Guesses a solution (to be implemented in a subclass).
$player->check( $guess, $result );
Given a guess and the result for the guess, determines which positions are still possible solutions for the game (to be implemented in a subclass).
Mattia Barbon <mbarbon@cpan.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Games::Mastermind::Solver, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::Mastermind::Solver
CPAN shell
perl -MCPAN -e shell install Games::Mastermind::Solver
For more information on module installation, please visit the detailed CPAN module installation guide.