foxfan20
foxfan20
  • Threads: 6
  • Posts: 27
Joined: Oct 5, 2010
June 3rd, 2011 at 10:40:11 AM permalink
I'm writing a flop poker analyzer. The hand scoring is driving me just a tad nuts because of the presence of an unscored card. Any tips on how to handle that?
PerpetualNewbie
PerpetualNewbie
  • Threads: 3
  • Posts: 88
Joined: Nov 30, 2009
June 3rd, 2011 at 11:03:11 AM permalink
Brute force - at the onset of looking at any given hand, you have no idea what the best hand will be. Because of the low number of evaluations, it doesn't make sense to try and pre-figure-out hands. There are C(6,5) (That is... 6) combinations of hands that can be made. Each 5-card combination must be analyzed and the highest of those 6 chosen as the played value.

Ah 2h 3h 4h 5s 6h has 6 potential values:

{Ah 2h 3h 4h 5s} {6h} - 5-high straight (Wheel)
{Ah 2h 3h 4h 6h} {5s} - A6432 flush
{Ah 2h 3h 5s 6h} {4h} - A6532 high card
{Ah 2h 4h 5s 6h} {3h} - A6542 high card
{Ah 3h 4h 5s 6h} {2h} - A6543 high card
{2h 3h 4h 5s 6h} {Ah} - 6-high straight

The best of this is the A6432 flush and that would be the represented high-hand

If I were to program it, I'd follow this pseudo-code:

CardsInHand = Array(6)

Hand1 = {CardsInHand(1),CardsInHand(2),CardsInHand(3),CardsInHand(4),CardsInHand(5)}
Hand2 = {CardsInHand(1),CardsInHand(2),CardsInHand(3),CardsInHand(4),CardsInHand(6)}
Hand3 = {CardsInHand(1),CardsInHand(2),CardsInHand(3),CardsInHand(5),CardsInHand(6)}
Hand4 = {CardsInHand(1),CardsInHand(2),CardsInHand(4),CardsInHand(5),CardsInHand(6)}
Hand5 = {CardsInHand(1),CardsInHand(3),CardsInHand(4),CardsInHand(5),CardsInHand(6)}
Hand6 = {CardsInHand(2),CardsInHand(3),CardsInHand(4),CardsInHand(5),CardsInHand(6)}

Analysis of Hand1 = BestHand
Analyze Hand3
If Hand2 > BestHand
Hand2 = BestHand
Analyze Hand3
If Hand3 > BestHand
Hand3 = BestHand
Analyze Hand 4
If Hand4 > BestHand
Hand4 = BestHand
Analyze Hand5
If Hand5 > BestHand
Hand5 = BestHand
Analyze Hand6
If Hand6 > BestHand
Hand6 = BestHand

Return BestHand

You can optimize that with a loop and some creative infixed subroutines, but I'm not a (real) coder.
  • Jump to: