|
-
Feb 7th, 2006, 06:59 AM
#1
Thread Starter
Hyperactive Member
Poker - Calculating odds
Hello all,
I am trying to make a poker game where you can play against the computer, however for the computer player to be any good it needs to know the chance of winning from its current hand (this is texas holdem poker so you know). I have been trying to make a chance calculator that gives the exact chance of winning, losing, and splitting the pot for any hand, however as there are so many combinations it takes a very long time to do it. I have looked at alternatives such as calculating the chance using the number of 'outs' but that only really gives an approximate chance.
Here is the basic outline of what i have at the moment (this is executed at the stage when all 5 community cards are face up)
Calculate the best hand for the player from the 7 cards avaliable
Loop through each combination of cards for an opponent
add one to the total count
calculate the best hand from the 7 cards avaliable to the opponent
compare the opponents hand with the players hand
add one to either the win count, the lose count, or the split count
(end of loop)
chance of winning = win count / total count
Here's the VB code to carry out this bit:
VB Code:
handScore = FindBestHandScore(pHand, pCommunity)
For i = 1 To pPack.Count - 1
For j = i + 1 To pPack.Count
fOpponent.Clear
fOpponent.Add pPack(i).suit, pPack(i).facevalue
fOpponent.Add pPack(j).suit, pPack(j).facevalue
opponentScore = FindBestHandScore(fOpponent, pCommunity)
CalculateChance.Total = CalculateChance.Total + 1
Select Case Sgn(opponentScore - handScore)
Case 1
CalculateChance.Loses = CalculateChance.Loses + 1
Case 0
CalculateChance.Splits = CalculateChance.Splits + 1
Case -1
CalculateChance.Wins = CalculateChance.Wins + 1
End Select
Next j
Next i
Last edited by Arachnid13; Feb 7th, 2006 at 07:17 AM.
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Feb 7th, 2006, 07:50 AM
#2
Re: Poker - Calculating odds
Moved to Games programming
-
Feb 7th, 2006, 10:08 AM
#3
Fanatic Member
Re: Poker - Calculating odds
ok i see what your saying, why not after every turn calculat the odds, If the comp has a good hand then he keeps playing. Dont compare with yours, then he would know and would probably win all the time.
I would see what hand the computer has, and if hes got a good one then let him play and maybe if he has no hand at all.... 1 in 10 times he bluffs!
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
-
Feb 7th, 2006, 03:19 PM
#4
Re: Poker - Calculating odds
I play Hold'em a lot and I use a commercial program called Turbo Texas Hold'em (which I helped test BTW) to practice, and what it does in showdown situations is to complete the dealing of 5000(?) hands in the background and then uses win percent from those hands as the odds. It's not exact but it's probably going to be a lot faster then any code that involves a loop.
-
Feb 7th, 2006, 03:56 PM
#5
Thread Starter
Hyperactive Member
Re: Poker - Calculating odds
@ damasterjo
It doesnt compare the computer hand with your hand, it compares the computer hand with all the possible hands that you could have so for example if there was a 4 of hearts, a 5 of hearts, a 6 of diamonds, a jack of hearts and a ten of clubs on the table and the computer had a ten of hearts and a 3 of spades then he would have a pair of tens, but the possibilities of the player winning are high as he/she could have a flush of hearts, a straight, three of a kind, or even just a pair higher than the tens. So it loops through each of the cards the player could have, thats why it takes so long which is causing the problem
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Feb 7th, 2006, 04:08 PM
#6
Thread Starter
Hyperactive Member
Re: Poker - Calculating odds
@MartinLiss
yea i have thought of doing just a kind of partial sample but id rather just find a way of cutting down the numbers without affecting the probabilities by finding a few patterns, like hands with different suits where the possibile outcomes are identical, like this:
Computer: 8 Spades, 8 Hearts
Player: ???, ???
Community: 8 Clubs, 8 Diamonds, J Clubs, ???, ???
obviously here there is a 100% chance of the computer winning but to calculate that it has to go through 148995 combinations... which takes about 13 mins
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Feb 7th, 2006, 07:01 PM
#7
Re: Poker - Calculating odds
When you get up into the thousands of hands I would guess that the real odds differ from the 5000-hand-odds differ only by thousandths of a percent or less. Do you need it to be that accurate?
-
Feb 9th, 2006, 11:50 AM
#8
Thread Starter
Hyperactive Member
Re: Poker - Calculating odds
i suppose so, i'll try it out and see how much i can reduce the time by without really affecting the odds... i will be posting the code when ive got it sorted out and the code tidied up.
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Feb 14th, 2006, 01:54 PM
#9
New Member
Re: Poker - Calculating odds
I don't think you need to run through 5,000 hands to find the odds you can calculate them.
For example if you are dealt down 2 hearts and there is 2 on the board after the flop, so that is a total of 4 out of 13 hearts. There are 9 hearts left with 47 cards left, so then you know the odds of hitting a flush. You can repeat the odds for every type of hands, some, for instance a Royal Flush can be eliminated. That is how I would have the computer decide the betting. Maybe all he has are pocket 2's with 3 over cards on the board. You are on the river and there isn't a 2 up what are the odds? What is the oppent betting? Is it worth the call? Are the implied odds high enough?
I would also have settings for the computer so that some of the AI is aggressive and some are really tight, to get variety in the game.
FYI get any discrete math book and it will help you calculate the odds.
-
Feb 20th, 2006, 04:59 AM
#10
Thread Starter
Hyperactive Member
Re: Poker - Calculating odds
Yea this is exactly what i was looking for, does anyone have any examples of how to calculate poker odds the way <213>>_Longhorn has mentioned? i dont have a lot of spare time at the moment but ill start trying to figure it out this evening probably.
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Feb 20th, 2006, 01:19 PM
#11
New Member
Re: Poker - Calculating odds
I started some Pseudo code for the odds, but then realized it is more involved. At a high level this is how you figure out the odds of a poker hand.
Figure out what cards can make a hand, and divided that by the total number of cards left in the deck.
For example, if you are dealt AA down what are the odds pre-flop of hitting a 3 of a kind? Since you have only seen 2 cards there are 50 possible left. Even though other people maybe at the table you don't know there cards and the next card could be any of the 50 left. There are 2 cards left you can catch out of that 50 to make a 3 of a kind, AA, so the odds are 2 / 50 or 1/25 or 4%. If the flop comes and no Ace is on the board then the odds are 2 / 47 possible left or 4.2%. If none comes on the turn, then the odds of you getting that Ace on the river are 2 / 48 or 4.2 % again. That will hold the same for any pocket pair the chance of hitting a set, or 3 of a kind, is about 4%.
Going on a flush example, lets say you were dealt the A3 of hearts. The flop comes there is the 10H and 6H. That means out of the 13 hearts there are 4 gone, the A, 3, 6, 10 with the 2, 4, 5, 7, 8, 9, J, Q, K or 9 left. What are the odds of hitting the flop on the turn? There are 47 cards gone, and 9 can give you a flush or 9 / 47 or 19 %, the turn comes as a 3 clubs, what are the odds of hitting the flush on the river? 9 / 46 or 19.5%. Preflop the odds of hitting a flush are 11 /50 or 22%. Lets assume a player has the KH then you odds fall to 8 /47 or 17% after the flop. If somebody has the Q of hearts and the King is also gone then your odds are 7 / 47 15%. You could then have the program play WHAT-IFs
Is this what you were looking for? I don't know how to code that great in VB other than Access, but I do know C++ I could take a shot if I have time.
-
Feb 20th, 2006, 01:36 PM
#12
Re: Poker - Calculating odds
The odds of, for example, of completing a flush when you have 2 of a suit pre-flop are as you say 22% but the problem is that he needs to know the odds of winning with a given 2 cards and that is much more complicated since obviously someone could for example be holding Ax of the same suit as him.
-
Feb 21st, 2006, 06:27 AM
#13
Thread Starter
Hyperactive Member
Re: Poker - Calculating odds
no C++ wouldn't be any help, and as Martin has said, your way would only calculate the odds of acheiving a certain hand, not the overall chance of winning. It's a shame as i thought you may have noticed a good way to do it. Thanks anyway tho
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Feb 22nd, 2006, 03:58 AM
#14
Re: Poker - Calculating odds
-
Feb 22nd, 2006, 01:36 PM
#15
Re: Poker - Calculating odds
Interesting and informative sites but again I believe what the poster wants is the ability to be able say that holding, say, the king and queen of hearts, that he will win x% of the time rather than that he will complete the flush 22% of the time.
-
Mar 13th, 2006, 05:03 AM
#16
Lively Member
Re: Poker - Calculating odds
-
Mar 13th, 2006, 05:09 AM
#17
Thread Starter
Hyperactive Member
Re: Poker - Calculating odds
yep thanks
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|