(disclaimer: I am working on poker software, which in particular evaluates hands)
You give you 7 cards and splash out the value of hand equivalence.
There are several evaluators who do this, and if I'm not mistaken, some of them calculate more than one hundred million hands per second (!). These evaluators basically reduce to 7 array requests in a gigantic array, and only a few cycles are required to evaluate a hand (despite cache misses). I do not think that 14-15 million per second is anywhere. The CactusKev evaluator is 10 times faster if I'm not mistaken.
Now, to answer your question:
how do you get the best combination of 5 cards from 7 that you switched to it?
Well, this does not tell you, but once you have the strength of the hand, it can become very simple: you do not need to reinvent the wheel.
You can use force to simplify your "top five out of seven" calculations.
You can also use other libraries, giving you the five best cards at once (and not just their strength), or you can use the power to find the top five cards yourself.
I will give some examples ...
You know that you have a full house (aka “boat”), then you know that you are looking for three cards with the same rank, and then the best pairs (if there are two pairs, but you will definitely find at least one, because the evaluator told you that you have a boat).
You know that you have a straight line: find five cards that follow each other, starting with the best (beware of the case with a special case).
You can also take a little part in the stream: you could take on all the forces and compare the forces that the evaluator gives you. If it matches, say, ten high, just find any card T, 9, 8, 7 and 6 (no matter what suit).
You know you don't have a pair: just take the five highest cards you find
and etc.
There are only a few different ranks ... They can be, for example:
NO_PAIR ONE_PAIR TWO_PAIRS SET STRAIGHT FLUSH FULL_HOUSE FOUR_OF_A_KIND STRAIGHT_FLUSH
(you could, of course, create intermediate “direct wheels” and “direct flush wheels” and “royal flushes” if you like, etc.)
Once you know what type of hand you have (thanks to the quick evaluator you use), just switch to a piece of code that will find the top five out of seven for that particular hand.
I think this is a good way to continue working because you are using an ultrafast evaluator and then greatly simplify your logic.
At startup, you will need to evaluate strth once, for example, by computing:
HIGHEST_NO_PAIR_HAND = ultraFastEvaluator( "As Kd Qh Jc 9d 5s 2c" ); HIGHEST_FULL_HOUSE = ultraFastEvaluator( "As Ac Ad Kh Ks 8s 2h" );
I'm certainly not a proponent of using strings here. This is just an example ...
Then you could find the five best for each hand:
- calculate strength using a quick evaluator
- this is & lt; = HIGHEST_NO_PAIR_HAND?
- yes: take five high cards
- no: this is & lt; = HIGHEST_ONE_PAIR_HAND? yes: take the highest pair + the highest three cards no: this & lt; = HIGHEST_TWO_PAIRS_HAND?
So, in my opinion, you can reuse an API that immediately finds the five best of seven or completely rewrites your own, but it will be faster if you use the result of a quick analyzer to simplify your logic.
EDIT note that there is not necessarily one way to make the "five best of seven." For example, with As Ac on the Kc Kd Qh Qs 2c board, both As Ac Kc Kd Qh and As Ac Kc Kd Qs are the “five best” (the last queen costume doesn't matter).