Take the 2-minute tour ×

What would be the best way to compare two (and only two) players hands in Java using the best combination for 5 cards out of 7 cards (texas hold'em)?

If each card is assigned a value or enum then is there an alogirthm that can be used to decide who has the strongest hand?

I imagine you could either do an integer comparison to see who has the highest value hand or use some form of lookup table.

Having a look around there is a hand evaluator called SpecialKPokerEval: http://code.google.com/p/specialkpokereval/

Would this be suitable and painless to implement into an existing project or should I look at doing something from scratch?


How do the hand evaluators that use integer values work?

How does a lookup table work - does each possible hand have a value assigned to it?

share|improve this question

closed as not a real question by woodchips, Andrew, Andrew Aylett, Jaguar, P.T. Mar 7 '13 at 16:53


We're here to provide help with specific problems. Unless you define best this question is too subjective. –  thegrinner Mar 7 '13 at 16:24
You learn by doing. So try to do it yourself rather than using something someone else did. –  Ali Alamiri Mar 7 '13 at 16:24
It seems to me that there is probably a standard scoring method for poker hands. Something like 3 digits - high digit for 1,2,3,4 of a kind, straight, flush, straight flush. Low 2 digits for high card. –  Hot Licks Mar 7 '13 at 16:29
@HotLicks That doesn't work for double pairs since you need to specify both card heights to be able to break ties on the highest value. –  Khaur Mar 7 '13 at 16:35
@Khaur - True (the scheme was just off the top of my head and I forgot two pair), but there's most certainly a simple scheme that covers that, and that poker experts would know. –  Hot Licks Mar 7 '13 at 16:39

1 Answer 1

I suggest doing it from scratch as it's a good exercise. In fact, it's problem 54 in "Project Euler" and you could look for solutions to that exercise.

share|improve this answer
+1 for the project euler link –  Dilum Ranatunga Mar 7 '13 at 16:27
Thanks for the link Atif. –  silverzx Mar 7 '13 at 16:35
