Here some ideas:

1) A better representation for a poker hand would be an array. So you might store the hands as strings, but to operate on them you should transform them first to a more suitable representation.

2) To analyze a hand you might first sort it. By number to find high cards, pairs, full houses and straights, by suit to detect flushes. Ok, sorting is not neccessary for flushes in poker, but in your obscure game it might help, for example when there are smaller flushes possible like 5 out of 8

3) Simple counting would suffice to find most poker hands. Use an array to count the number of 2s, 3s... and you can find most of the poker hands by simply checking the numbers and noting the highest single, the highest pair, the highest triple and the highest "foursome". A simple check for triple AND pair then finds a Full House.

4) If you categorize hands with a special identifier, you are able to compare winning hands by string comparision and sort them. The identifier aka key would be "ABCDEF", with A == 0 for High Card, 1 for Pair... up to 8 for Straight Flush. The rest would depend on A and might be even empty. For a pair B would be the rank of the pair, 02 for a 2, 13 for an ace. C would be the number of the highest single card apart from the pair. D the next highest and so on. Your example poker hand would be "61009". In this way a simple string comparision could rank arbitrary poker hands.


In reply to Re: Is Regexp::Grammars a suitable tool for recognising card game hands? by jethro
in thread Is Regexp::Grammars a suitable tool for recognising card game hands? by Anonymous Monk

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.