in reply to Checking for a special matching
Testing for pairs is easy: see if there are two card with the same rank (considering that in most poker forms, a hand has 5 or 7 cards, you don't have to be smart, even a brute force algorithm runs fast enough on anything produced since Babbage). You could, for instance, use a hash for ranks, and a hash for suits. If the ranks values are "2, 1, 1, 1", it's a pair. If it's "2, 2, 1", it's two pair. If it's "3, 1, 1", it's three of a kind. It it's "3, 2", it's a full house. If it's "4, 1", it's four of a kind. If it's "5", it's five of a kind. For the suits, if all the suits are the same (easy to find out with a hash), you have a flush. To find out straights, sort the cards (by rank). If the result is a sequence, you have a straight (an ace high straight needs an extra check).
Instead of hashes, you can sort right away, and determine pairs, etc, by inspecting the sorted hand.
But regexes seems like the wrong way to do it. In fact, if you need a regex to inspect an internal representation 100 out of 99 times, you're doing it wrong.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Checking for a special matching
by heatblazer (Scribe) on Apr 02, 2012 at 16:43 UTC | |
by JavaFan (Canon) on Apr 02, 2012 at 18:13 UTC | |
|
Re^2: Checking for a special matching
by heatblazer (Scribe) on Apr 03, 2012 at 14:33 UTC |