1

I've written a Naive Poker Evaluation algorithm for a Hold 'Em Poker game I'm developing and I'm wondering what would be the best way to evaluate Jokers within these hands.

A thought I had would be to replace the joker with each card from the deck and reevaluate the hand iteratively to find the best possible hand. However there can be upto 3 jokers and it doesn't seem to be the most efficient way to do this? Thoughts?

P.S. - Yes I am aware that there are several faster poker hand evaluators available but these cards are slightly different and I have been unable to find one to suit my needs(Jokers etc), hence have written one from scratch.

Prat
  • 495
  • 7
  • 19
  • I would write code that tries each hand type from best to worst (straight flush down to highest card) asking 'can I make this work with the jokers?' e.g. special code for each hand type is needed, such as 'I can make a full house with three jokers and anything, two jokers and a pair/better, a three of a kind and a joker or two pairs and a joker' – Patashu May 08 '13 at 06:40
  • I tried developing that sort of logic but the possibilities are too vast, especially with 3 jokers. – Prat May 08 '13 at 06:44
  • You don't have to think of it in terms of 'what are all the ways I could use three jokers' but more in terms of 'if I have X jokers, what are the new minimum requirements to be able to complete a hand type?' e.g. you can make a flush if all your non-jokers are the same suit, a straight if 1) you have five cards in order 2) you have four cards and one joker and the highest and lowest cards are either 4 or 5 difference 3) you have three cards and two jokers and the highest and lowest cards are 3-5 difference 5) you have two cards and three jokers and the cards are 2-5 difference... – Patashu May 08 '13 at 06:55
  • 1
    +1 because the titles rhyme! – Thihara May 08 '13 at 06:58

2 Answers2

3

Note that to try every combination of five cards from seven means trying 21 combinations, which isn't so bad.

For each of the hands, #: where # is a number indicates the # jokers in hand case.

Also note that once you've found a hand, you don't have to look for hands that are worse than that in any of the other combinations out of seven cards - you can stop early.

You can form a straight flush if:

0: All of the cards are the same suit and the highest and lowest card have a difference of 4 (which implies the other three cards must be in between those)

1: All of the non-jokers are the same suit and the highest and lowest card have a difference of 4 or 3. (which implies the other cards fill in the straight, with one gap - which the joker fills)

2: All of the non-jokers are the same suit and the highest and lowest card have a difference of 4, 3 or 2.

3: All of the non-jokers are the same suit and the highest and lowest card have a difference of 4, 3, 2 or 1.

You can form a four of a kind if:

0: You have four cards the same rank.

1: You have three cards the same rank.

2: You have two cards the same rank.

3: You have a four of a kind - stop evaluating.

You can form a full house if:

0: You have a three of a kind and a pair.

1: You have a three of a kind, or you have two pairs.

2: You have a three of a kind, or you have a pair.

You can form a flush if:

All non-jokers are the same suit.

You can form a straight if:

See straight flush logic but take away the flush requirement.

You can form a three of a kind if:

0: You have three cards the same rank.

1: You have two cards the same rank.

2: You have a three of a kind - stop evaluating.

You can form a two pair if:

0: You have two cards the same rank, for two different ranks.

1: You have two cards the same rank (one pair).

You can form a pair if:

0: You have two cards the same rank.

1: You have a pair - stop evaluating.

You have highest card - stop evaluating

Patashu
  • 21,443
  • 3
  • 45
  • 53
  • This logic though is for a 5 Card Hand, It gets more complicated for Hold 'Em. I'll try and work through the logic for Hold 'Em and post an update – Prat May 09 '13 at 07:38
  • @Prat You can do that, or you can iterate over all 5C7 = 21 possible combinations of five cards from seven. Only if that is NOTICABLY slow would I strive to optimize further. – Patashu May 09 '13 at 08:30
0

This logic of comparing top-bottom differences doesn't work.

Consider that you have 9 - J - J - K - Joker. That would yield a difference of 4 but is not a straight.

FIX: The non-joker numbers all have to be different as well.

Rubicon
  • 1
  • 2