The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Games::Cards::Pair - Interface to the Pelmanism (Pair) Card Game.

VERSION

Version 0.02

DESCRIPTION

A single-player game of Pelmanism, played by the program, as of now but very soon I would make it an interactive game so that human can also play with it. A pack of cards comprises each of the thirteen values ( 2, 3, 4, 6, 7, 8, 9, 10, Queen, King, Ace, Jack ) in each of the four suits ( Clubs, Diamonds, Hearts, Spades ) plus two jokers. The Joker will not have any suit.

METHODS

draw()

Returns a card randomly selected from the deck or undef if it is empty. If previously seen similar value card then returns that card. There are two flavours of this method, if it is called without any parameter then it simply returns the randomly picked card from the deck.And it if it's called passing a card then it checks whether we have seen any similar value card before or not.If yes then it picks that card and made the match otherwise picks another random card from the deck.

    use strict; use warnings;
    use Games::Cards::Pair;

    my $game = Games::Cards::Pair->new();
    my $card = $game->draw();
    print "Card picked: $card\n";

process()

Check if the two given cards are the same and act accordingly.

    use strict; use warnings;
    use Games::Cards::Pair;

    my ($game, $card1, $card2);
    $game  = Games::Cards::Pair->new();
    $card1 = $game->draw();
    $card2 = $game->draw($card1);
    $game->process($card1, $card2);

is_over()

Returns 1 or 0 depending if the deck is empty or not.

    use strict; use warnings;
    use Games::Cards::Pair;

    my $game = Games::Cards::Pair->new();
    print "Game is not over yet.\n" unless $game->is_over;

as_string()

Returns deck arranged as 6 x 9 blocks. This is overloaded as string context.

    use strict; use warnings;
    use Games::Cards::Pair;

    my $game = Games::Cards::Pair->new();
    print $game->as_string() . "\n";
    print "Is same as before:\n $game\n";

get_matched_pairs()

Returns all the matching pair, if any found, from the bank.

    use strict; use warnings;
    use Games::Cards::Pair;

    my $game = Games::Cards::Pair->new();
    do
    {
        my $card1 = $game->draw();
        my $card2 = $game->draw($card1);
        $game->process($card1, $card2);
    }
    until ($game->is_over());

    print "Matched cards:\n" . $game->get_matched_pairs();

AUTHOR

Mohammad S Anwar, <mohammad.anwar at yahoo.com>

BUGS

Please report any bugs / feature requests to bug-games-cards-pair at rt.cpan.org or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Cards-Pair.I will be notified & then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Games::Cards::Pair

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2012 Mohammad S Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

DISCLAIMER

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.