robertw has asked for the wisdom of the Perl Monks concerning the following question:
Dear perl monks, I have this module which has a sub that calculates the score of the poker hand (ScoreHand) it is in this link http://search.cpan.org/~pip/Games-Cards-Poker-1.2.565CHh5/Poker.pm, the synopsis goes like this:
use Games::Cards::Poker; # Deal Four (4) players hands and score them... my $players = 4; # number of players to get hands dealt my $hand_size = 5; # number of cards to deal to each player my @hands = ();# player hand data my @deck = Shuffle(Deck()); while($players--) { push(@{$hands[$players]}, pop(@deck)) foreach(1..$hand_size); printf("Player$players score:%4d hand:@{$hands[$players]}\n", ScoreHand(@{$hands[$players]})); }
what i want to know is how to use scorehand in this way:
#!/usr/bin/perl @userinput = <STDIN>; #What i will type e.g.: As,Qc,Td,6c,3h $score = ScoreHand(@userinput);
so far that only gives me the top score for everything I do, I don't fully get what exact form (scalar, hash , array) ScoreHand desires neither if it is supposed to be in string form. I also have the ScoreHand sub code:
Thank you so much in advance, I will of course be willing to supply much more information if that is necessary. Robsub ScoreHand { # returns the score of the passed in @hand or ShortHan +d my @hand = @_; return(7462) unless(@hand == 1 || @hand == 5); my $sh +rt; my $aflg = 0; $aflg = 1 if(ref($hand[0]) eq 'ARRAY'); my $aref; if( $aflg ) { $aref = $hand[0]; } else { $aref = \@hand; } if(@{$aref} == 1) { $shrt = $aref->[0]; } else { $shrt = ShortHand($aref); } if( $slow ) { return(SlowScoreHand($shrt)); } else { return( $zdnh{$shrt}); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Poker module question
by jwkrahn (Abbot) on Jul 14, 2012 at 04:27 UTC | |
|
Re: Poker module question
by frozenwithjoy (Priest) on Jul 14, 2012 at 04:23 UTC |