Games::Poker::HandEvaluator - Evaluate poker hands


Games-Poker-HandEvaluator documentation Contained in the Games-Poker-HandEvaluator distribution.

Index


Code Index:

NAME

Top

Games::Poker::HandEvaluator - Evaluate poker hands

SYNOPSIS

Top

   use Games::Poker::HandEvaluator qw(handval evaluate);
   use Games::Cards;
   my $Poker = new Games::Cards::Game;
   my $Deck = new Games::Cards::Deck ($Poker, "Deck");
   $Deck->shuffle;

   # Deal out the hands
   my $hand = Games::Cards::Hand->new($Poker, "Hand") ;
   $Deck->give_cards($hand, 7);

   print $hand->print("short"), "\n";
   # Hand:  JC   7C   8C   JH   3C   7S   5C  

   print handval(evaluate($hand)), "\n";
   # Flush (J 8 7 5 3)

Or just:

   my $hand_a = evaluate("Jc 7c 8c Jh 3c 7s 5c");
   my $hand_b = evaluate("9d 5d Ks 7h 5s 7s 4c");
   if ($hand_a > $hand_b) {
      print handval($hand_a), " beats ", handval($hand_b);
      # Flush (J 8 7 5 3) beats TwoPair (7 5 K)
   }

DESCRIPTION

Top

This is an XS wrapper around the libpoker library, found at http://www.pokersource.org/.

It provides two functions, which are not exported by default, evaluate and handval. evaluate turns a hand, as described either by a Games::Card::CardSet object or a simple string, into an integer representing the best poker play for that hand. If the hand cannot be parsed, 0 is returned. This integer value can be compared with other hand evaluations; the higher the integer, the better the hand.

handval turns that value into a short textual description.

SEE ALSO

Top

http://www.pokersource.org/

AUTHOR

Top

Simon Cozens, <simon@kasei.com>

COPYRIGHT AND LICENSE

Top


Games-Poker-HandEvaluator documentation Contained in the Games-Poker-HandEvaluator distribution.

package Games::Poker::HandEvaluator;

use 5.006;
use strict;
use warnings;

require Exporter;

our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw(
	evaluate handval
) ] );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '1.1';

require XSLoader;
XSLoader::load('Games::Poker::HandEvaluator', $VERSION);

sub evaluate {
    my $hand = shift;
    if (UNIVERSAL::isa($hand, "Games::Cards::CardSet")) {
        $hand = $hand->print;
        $hand =~ s/.*://; $hand =~ s/\s+/ /g;
        $hand =~ s/10/T/g;
    }
    return 0 unless $hand;
    _evaluate($hand);
}

# Preloaded methods go here.

1;
__END__
# Below is stub documentation for your module. You'd better edit it!