NAME
Games::Mastermind::Solver - a Master Mind puzzle solver
SYNOPSIS
# a trivial Mastermind solver
use Games::Mastermind;
use Games::Mastermind::Solver;
my $player = Games::Mastermind::Solver->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";
}
DESCRIPTION
Games::Mastermind::Solver
uses the classical brute-force algorithm for solving Master Mind puzzles.
METHODS
new
$player = Games::Mastermind::Solver->new( $game );
Constructor. Takes a Games::Mastermind
object as argument.
move
( $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
.
It is possible to pass an array reference as the move to make.
remaining
$number = $player->remaining;
The number of possible solutions given the knowledge the player has accumulated.
reset
$player->reset;
Resets the internal state of the player.
guess
$guess = $player->guess;
Guesses a solution.
check
$player->check( $guess, $result );
Given a guess and the result for the guess, determines which positions are still possible solutions for the game.
AUTHOR
Mattia Barbon <mbarbon@cpan.org>
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.