Advertisement

Help with a poker program

Started by September 05, 2004 10:04 AM
12 comments, last by GameDev.net 20 years, 2 months ago
Quote: Original post by Predictor
Quote: Original post by Anonymous Poster
First start with a table of all combinartions of 5 cards (IIRC 52*51*50*49*48 = 311875200 Different possibilities).


That's actually the number of permutations.


Yep. To calculate combinations (where order doesn't matter) this is the formula:
n!
--------- = nCk
k!(n - k)!

52!
---------- = 52C5
5!(52 - 5)!

or 2598960 combinations
Of course in Texas Hold'em one has 7 cards (2 hole cards and 5 community cards) from which one cherry picks the best 5 card hand from so the above figure isn't very meaningful.

Hello theredpill99,
I'm working on the same problem. Some questions: is your game arbitrary limit, no limit or pot limit? Tournament(where you play until one person at the table has all the chips) or sit-and-go(people may enter and leave at any point in the game)? I'm trying to make my game have all these as options which is pretty ambitious considering that limit poker and a no limit poker are completely different games requiring radically different strategies.

Pre-Flop - You said you had your pre-flop evaluation done. Are you basing it on David Sklansky's starting hand chart(ie the 169 distinct starting hand combinations)? And before anyone asks, I know there are actually 1326 combinations (ie 52C2) but many of them have identical values, for example AhKd is worth the same as AhKs and AhAd is worth the same as AhAc pre-Flop. There are 169 distinct starting hands...
-----------------------------Total--Distinct----Odds of Happening
Pairs ------------------- XX = 78 = 13 ------- .058823529
Not-paired but suited --- XYs = 312 = 78 ------- .235294117
Not-paired and not suited XY = 936 = 78 ------- .705882352

Poker players agree that a good player should probally muck (fold pre-flop) at least half his hands if he is not in one of the blinds and isn't short-stacked. Sklansky and others have tried to rank the 169 hands to aid in hand selection.

I'm currently writing a little helper program which will randomly deal out tens of thousands of hands of Hold'em and keep track of which starting hands resulted in victory so that I can then mathematically order and weight them. For example I know that AA is better than AKs(suited) but how much better? Once I get a number for each starting hand combination then I can weight it with such factors as position, # of players still in the hand and chip count(the short stack can't be too picky).

Post-Flop - If I've got AhKd in my hand and the flop is Ad5sJc then I've got Aces with a King kicker. I know that at present the only hands that could be ahead of me are
AsAc,
AsJd, AsJs, AsJh, AcJd, AcJs, AcJh,
As5h, As5d, As5c, Ac5h, Ac5d, Ac5c,
JdJs, JdJh, JsJh,
Jd5c, Jd5d, Jd5h, Js5c, Js5d, Js5h, Jh5c, Jh5d, Jh5h,
5c5d, 5c5h, 5h5d,
or 25 hands out of a possible 1081 combinations(ie 47C2).
The way I've handled it is figure out how many hands are ahead of me and calculate a probability that someone at the table holds one of those hands. Eventually I will weight that probability with player tendencies(like how a tight player wouldn't play J5 unless he were in the big blind and had not been raised)

In addition to keeping track of which hands are ahead of me I also need to know the probability that hands not currently ahead of me could still beat me. For example if an opponent has 2 diamonds and the Turn and the River are both diamonds then he has an Ace high flush. This is a little more complicated than merely figuring which hands are ahead of me, I'm still working on this part but the final solution will probally take the form of linked nodes in some kind of tree structure(tracing all possible outcomes and the % of those outcomes which would beat my hand).

The Turn and the River are handled the same way. As each card is revealed then the tree gets trimmed back and the probabilities get adjusted.

During each betting round you have to decide whether to fold, check, call, raise or go all in. I'm still working on a formula to decide what action should be taken but variables include probability of winning the hand, # of people still in the pot, table position, amount in the pot vs. amount to be called, size of my stack, size of blinds and eventually player profile(but this is far off into the future). Put all info into the formula and then pump out a figure like...
if (formulaResult > 95)
raise()
else if(formulaResult > 75)
call()
etc......
I'd like to even include a bluff function. When a computer player object gets created then I randomly assign a value to a bluffModifier which figures into the formula and allows the computer player to bluff and/or semi-bluff at unpredictable intervals and to unpredictable degrees.

Of course at this point most of this is theoretical but I have given it a lot of thought. I'd love to compare notes with you.
Quote: Original post by Matt Apple
-----------------------------Total--Distinct----Odds of Happening
Pairs ------------------- XX = 78 = 13 ------- .058823529
Not-paired but suited --- XYs = 312 = 78 ------- .235294117
Not-paired and not suited XY = 936 = 78 ------- .705882352


Post-Flop - If I've got AhKd in my hand and the flop is Ad5sJc then I've got Aces with a King kicker. I know that at present the only hands that could be ahead of me are
AsAc,
AsJd, AsJs, AsJh, AcJd, AcJs, AcJh,
As5h, As5d, As5c, Ac5h, Ac5d, Ac5c,
JdJs, JdJh, JsJh,
Jd5c, Jd5d, Jd5h, Js5c, Js5d, Js5h, Jh5c, Jh5d, Jh5h,
5c5d, 5c5h, 5h5d,
or 25 hands out of a possible 1081 combinations(ie 47C2).
The way I've handled it is figure out how many hands are ahead of me and calculate a probability that someone at the table holds one of those hands. Eventually I will weight that probability with player tendencies(like how a tight player wouldn't play J5 unless he were in the big blind and had not been raised)


25 / 1081 = 2.312% chance of being beaten,
Say that the pot is $100
And you've put in $20,

And now to figure out what amount you would get *on average*.
pot = $97 = (1-(25 / 1081)) * 100 (that is on average how much you'd win)
Amount lost = $0.46 = (25 / 1081) * 20

And as such you go 91 / 0.56 and you end up with a number which can be used. (and shoudn't change as you add more money) which is 210. (which is a very good number, as it means that the bot should win the showdown)

This all assumes that all hands have the same probability... but that should be easy to fix.

Quote:
During each betting round you have to decide whether to fold, check, call, raise or go all in. I'm still working on a formula to decide what action should be taken but variables include probability of winning the hand, # of people still in the pot, table position, amount in the pot vs. amount to be called, size of my stack, size of blinds and eventually player profile(but this is far off into the future). Put all info into the formula
and then pump out a figure like...
if (formulaResult > 95)
raise()
else if(formulaResult > 75)
call()
etc......
.


Bad idea! it makes your poker player very predictable... (when its not bluffing, but your not going to get it to bluff every second or third hand... are you?)
maybe something like
if ((formularesult + rand()) > 0.75) {    raise()else if ((formularesult + rand()) > 0.95) {    call()}

^
|
Not the best egsample... but you get the idea.
I also find this idea very interesting...

From,
Nice coder (lets see if this time it lets me log on)
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Advertisement
Quote: Original post by Nice Coder

Bad idea! it makes your poker player very predictable... (when its not bluffing, but your not going to get it to bluff every second or third hand... are you?)
maybe something like


Actualy in small pots it *should* be bluffing every 2nd or 3rd hand :)

The odds of you bluffing versus betting the best hand should be precisely equal to the odds the pot is laying your opponent such that it no longer matters (to him) weather or not he calls your bet. This is based on straight game theory mathematics.


Well, all these things depend on what kind of game you are playing. Bluffing doesn't work well in .50 /1$ limit hold em.

This topic is closed to new replies.

Advertisement