Algorithm-MasterMind
view release on metacpan or search on metacpan
lib/Algorithm/MasterMind.pm view on Meta::CPAN
my $played_string = $solver->issue_next;
$solver->feedback( check_combination( $secret_code, $played_string) );
#And so on until solution is found
=head1 DESCRIPTION
Includes common functions used in Mastermind solvers; it should not be
used directly, but from derived classes. See examples in
L<Algorithm::MasterMind::Random>, for instance.
=head1 INTERFACE
=head2 new ( $options )
Normally to be called from derived classes
=head2 add_rule( $combination, $result)
Adds a rule (set of combination and its result as a hash) to the set
of rules. These rules represent the information we've got on the
secret code.
=head2 check_combination( $secret_code, $combination )
Checks a combination against the secret code, returning a hashref with
the number of blacks (correct in position) and whites (correct in
color, not position)
=head2 distance( $object )
Computes distance to a consistent combination, computed as the number
of blacks and whites that need change to become a consistent
combination.
=head2 check_combination_old ( $secret_code,
$combination )
Old way of checking combinations, eliminated after profiling
=head2 check_rule ($rule, $combination)
Same as C<check_combination>, except that a rule contains a
combination and how it scored against the secret code
=head2 issue_first ()
Issues the first combination, which might be generated in a particular
way
=head2 start_from ()
Used when you want to create an solver once it's been partially
solved; it contains partial solutions.
=head2 issue_first_Knuth
First combination looking like AABC for the normal
mastermind. Proposed by Knuth in one of his original papers.
=head2 issue_next()
Issues the next combination
=head2 feedback()
Obtain the result to the last combination played
=head2 guesses()
Total number of guesses
=head2 evaluated()
Total number of combinations checked to issue result
=head2 number_of_rules ()
Returns the number of rules in the algorithm
=head2 rules()
Returns the rules (combinations, blacks, whites played so far) as a
reference to array
=head2 matches( $string )
Returns a hash with the number of matches, and whether it matches
every rule with the number of blacks and whites it obtains with each
of them
=head2 hashify ( $string )
Turns a string into a hash, to help with comparisons. Used internally,
mainly.
=head2 not_in_combination( $string)
Returns the letters from the alphabet that are _not_ in this
combination. Might be useful for certain strategies.
=head2 random_combination
Combines randomly the alphabet, issuing, you guessed it, a random
combination.
=head2 partitions
From a set of combinations, returns the "partitions", that is, the
number of combinations that would return every set of black and white
response. Inputs an array, returns a hash keyed to the combination,
each key containing a value corresponding to the number of elements in
each partition.
=head2 all_combinations
Returns all possible combinations of the current alphabet and length
in an array. Be careful with that, it could very easily fill up your
memory, depending on length and alphabet size.
( run in 1.012 second using v1.01-cache-2.11-cpan-524268b4103 )