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


In reply to Re: Poker problem by olus
in thread Poker problem by gman1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.