robolson / ruby-poker

Ruby library for comparing poker hands and determining the winner.
BSD 3-Clause "New" or "Revised" License
99 stars 42 forks source link

Support for 7-card hands #8

Open garbo999 opened 7 years ago

garbo999 commented 7 years ago

I wonder if ruby-poker was designed to support 7-card hands (2-card hand + 5-card board, like in Texas Holdem)?

The gems does seem to support 7-card hands. But then I came across this case, which appears incorrect:

> hand1 = PokerHand.new("TS TH 2S 3S 2H 3H 3D") # i.e. = 3S 3H 3D TS TH
> hand2 = PokerHand.new("9S 9H 2S 3S 2H 3H 3D") # i.e. = 3S 3H 3D 9S 9H

> hand1.rank
 => "Full house" 
> hand2.rank
 => "Full house" 

> hand1 > hand2
 => false # but should be true?

> hand1 == hand2
 => true # but should not be a tie?

I should mention that I have been using ruby-poker to test my own program. So far it has behaved perfectly, but I wonder about this one case. :-)

garbo999 commented 7 years ago

Here are two more cases I found that are possibly giving the wrong result:

> hand1 = PokerHand.new("Jh 6d Jd 6c Jc Ts Th") 
> hand2 = PokerHand.new("Jh 6d Jd 6c Jc 9s 9h") 

> hand1.rank
 => "Full house" 
> hand2.rank
 => "Full house" 

> hand1 > hand2
 => false 

> hand1 == hand2
 => true
> hand1.just_cards
 => "Ah Kd Ad Kc Ac Ts Th" 
> hand2.just_cards
 => "Ah Kd Ad Kc Ac 9s 9h" 

> hand1.rank
 => "Full house" 
> hand2.rank
 => "Full house" 

> hand1 > hand2
 => true 
> hand1 == hand2
 => false # should be a tie?
robolson commented 2 years ago

Hi @garbo999. Sorry I haven't looked at this project in a long time. I can confirm that ruby-poker is intended to support 7 card hands. Therefore I think this is a real bug in the full house rank algorithm. I am not sure what the problem is though. I am unlikely to spend time on this but I will review pull requests.