poker-evaluator icon indicating copy to clipboard operation
poker-evaluator copied to clipboard

Return winning hand

Open coderholic opened this issue 11 years ago • 5 comments

Would it be possible to return the 5 winning cards, when more than 5 cards are provided?

coderholic avatar Feb 20 '14 04:02 coderholic

@coderholic were you able to return a winning hand?

pareshchouhan avatar Sep 23 '14 05:09 pareshchouhan

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.

coderholic avatar Sep 24 '14 06:09 coderholic

yea I guess I need to do that : /

pareshchouhan avatar Sep 25 '14 07:09 pareshchouhan

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:

pareshchouhan avatar Sep 25 '14 07:09 pareshchouhan

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;

CharlieHess avatar Jun 21 '15 01:06 CharlieHess