Mattia Barbon > Games-Mastermind-Solver-0.02 > Games::Mastermind::Solver

Download:
Games-Mastermind-Solver-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Games::Mastermind::Solver - a Master Mind puzzle solver

SYNOPSIS ^

    # 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";
    }

DESCRIPTION ^

Games::Mastermind::Solver is a base class for Master Mind solvers.

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 (optional)

    $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 (to be implemented in a subclass).

check

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

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.

syntax highlighting: