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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |