Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poker Hands in Java

Tags:

java

poker

Is there any easy method to compare two poker hands? I'm going about this pretty naively, so if anybody has experience doing this, it could be helpful.

like image 643
Ben B. Avatar asked Mar 05 '11 18:03

Ben B.


People also ask

How do you compare poker hands in Java?

First sort your cards from lowest to highest 2 to Ace regardless of suit. Then do comparing. If card[0]==card[3] or card[1]==card[4], you have 4 of a kind, ignore next 2 lines. If card[0]==card[2] or card[1]==card[3] or card[2]==card[4], you have 3 of a kind, ignore the next line.


3 Answers

There isn't an easy (and performant) way to do this, especially if you want to evaluate five-card subsets of seven-card hands, like in Texas Hold 'em.

You might want to check out pokersource which has some Java bindings.

Edit - an additional resource is the pokerai forums. I found quite a few Java algorithms there. They are regularly run through benchmarks and are often accompanied by enumeration algorithms for Monte Carlo simulation. This appears to be the main post.

like image 81
Matthew Willis Avatar answered Oct 18 '22 07:10

Matthew Willis


I found this which seems promising.

You can also roll your own.

like image 3
hvgotcodes Avatar answered Oct 18 '22 09:10

hvgotcodes


An example of a ready made Texas Hold'em 7- and 5-card evaluator can be found here with documentation and further explained here. All feedback welcome at the e-mail address found therein.

like image 2
SK9 Avatar answered Oct 18 '22 08:10

SK9