Search code examples
pythonmathstatisticssimulationpoker

Calculating 5 card draw outs in Texas Hold'em Poker


I am currently making a simulation about poker in python and I am stucked at calculating outs at post-flop, turn

I want to learn how to calculate the outs when flop is drawn. In other way I want to learn how to make my simulation recognize that I need one card to have straight. If the missing card is in the middle, my outs would be 4. If it is at the beginning or end of the straight my outs would be 8.

For Example:

I have in my pocket(hands) 5-Spades and 6-Diamond

The flop is: 9-Clubs , 8-Hearts , K-Hearts

So my 5-Card hand is like: 5s - 6d - 8h - 9c - Kh

In Poker this draw is a gutshot straight draw. If I draw any kind of 7 in turn or river, I will have straight draw. Since there are 4 7s in a deck, my outs are 4 to have the Straight.

This is only one and basic example about outs.

If anyone can guide me, I will be pleased.

Kind Regards


Solution

  • First, you need some code that can recognize the various hands (four-of-a-kind, straight flush, etc.). Then, your algorithm should take four cards at a time from the player's hand, and cycle through all of the remaining cards in the deck, one at a time, adding them to the player's hand and testing them to see which hands are possible with one draw.

    That is, given the hand A B C D E, so that cards X1, X2, ..., X47 constitute the possible draws, your algorithm will test:

    A B C D + (X1 ... X47) --> evaluate_hand()
    A B C E + (X1 ... X47) --> evaluate_hand()
    A B D E + (X1 ... X47) --> evaluate_hand()
    A C D E + (X1 ... X47) --> evaluate_hand()
    B C D E + (X1 ... X47) --> evaluate_hand()
    

    If one of these 235 hands evaluates to STRAIGHT_FLUSH, you will know that the player is one card away from a straight flush.