poker-evaluator
poker-evaluator copied to clipboard
Return winning hand
Would it be possible to return the 5 winning cards, when more than 5 cards are provided?
@coderholic were you able to return a winning hand?
No. It should be possible to send all of the 5 card combinations through yourself and pick the one with the best score. It'd be nice (and more efficient) if the winning 5 were just returned though.
yea I guess I need to do that : /
or maybe I can submit a patch after I am done with writing that code which internally uses Eval Hand and returns 5 best cards :3 :+1:
This was easy to do using combinations.js
as follows:
let fiveCardHands = k_combinations(sevenCardHand, 5);
let bestHand = { handType: 0, handRank: 0 };
for (let fiveCardHand of fiveCardHands) {
let currentHand = PokerEvaluator.evalHand(fiveCardHand);
if (currentHand.handType > bestHand.handType ||
(currentHand.handType === bestHand.handType && currentHand.handRank > bestHand.handRank)) {
bestHand = currentHand;
}
}
return bestHand;