-1

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?

EDIT:

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?

TacticalCoder
  • 6,275
  • 3
  • 31
  • 39
silverzx
  • 1,209
  • 4
  • 14
  • 18
  • We're here to provide help with specific problems. Unless you define best this question is too subjective. – thegrinner Mar 07 '13 at 16:24
  • You learn by doing. So try to do it yourself rather than using something someone else did. – Kakalokia Mar 07 '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 07 '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 07 '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 07 '13 at 16:39
  • This is a very real question and it has a definitive answer. Hadn't the question be closed I would have been able to provide said answer. There really is no justification for closing this as *"not a real question"*. – TacticalCoder Mar 07 '13 at 17:30
  • @silverzx: welcome to SO and don't worry... Typically people are not closing real question as *"not a real question"*. I can't answer seen that the question is closed but I can tell you that you do both: you *first* use a lookup table (at least if you want speed), once for each hand, and *then* you do a comparison between the two integers you get back. Note that it's always a tradeoff between speed and memory: the fastest evaluators out there (doing hundreds of millions of evaluation per second) do use quite a lot of memory. – TacticalCoder Mar 07 '13 at 17:34

1 Answers1

4

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.

Atif
  • 942
  • 1
  • 6
  • 19