Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Poker problem

by olus (Curate)
on Dec 03, 2008 at 13:34 UTC ( #727669=note: print w/ replies, xml ) Need Help??


in reply to Poker problem

gman1983

I don't fully understand your problem, but it seems that you are having problems dealing with having duplicate cards in players hands. To avoid that, I suggest that you deal with it right from the start, that is, right when you are dealing the cards to the players. So my suggestion is:

# build the original deck of cards my @card_values = (2, 3, 4, 5, 6, 7, 8, 9, 10, 'V', 'D', 'R', 'A'); my @hearts = map {$_." h"} @card_values; my @clubs = map {$_." c"} @card_values; my @diamonds = map {$_." d"} @card_values; my @spades = map {$_." s"} @card_values; # scramble the deck of cards sub scramble { my @original_deck = (@hearts, @clubs, @diamons, @spades); @deck = (); while (@original_deck) { push @deck, splice(@original_deck, rand(@original_deck), 1); } }

Now you have a pile (array) of 52 scrambled, and not repeated, cards that you can start shifting to deal them to the players. Whenever you want to give a card, you just shift one from the @deck. For instance, if you want to give me a hand of 5 cards:

my @hand = (); push @hand, shift @deck for 0..4;

That was my approach when I wrote the single player Place your bets


Comment on Re: Poker problem
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://727669]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2015-07-31 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (281 votes), past polls