Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Poker problem

by olus (Curate)
on Dec 03, 2008 at 13:34 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-20 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found