Texas Hold'em - how do they calculate odds on the fly?

When TV shows have the hole cards displayed, they often show the percentage chances those cards have of winning. There are also websites let you construct hands and gives you their odds. How do these work? The brute force algorithm is pretty straightforward where you deal out all the possible hands and figure out what percentage of those each hand wins. However, if you just have 2 players, with just the hole cards, i believe the number of combinations is 48c5, or 1.7 million hands that are getting evaluated, pretty much instantly. Is there a database they set up and they just do hand lookups? What wizardry is going on here?

You are over thinking it. If we have two guys heads up then we know what they both have, and what it takes to beat the other guy. In that case we just need to know what other cards each player needs to win that hand. If they need one specific card to close out the hand then they have a 1 in how many cards left in the deck chance of hitting. If they can win in with multiple cards, called outs, you add all the possible outs together and divide by the remaining cards.

Even if you don’t know the other player’s cards you’re underestimating the power of modern computers. Evaluating 1.7 million possible hands (= the possible hands the other player has from the 50 cards still in play?) pretty much instantly just isn’t that impressive these days. Chances are your phone could do it faster than a google search.

There are freeware equity calculators that you can use, as lisiate points out. I like pokerstove. Further, when playing, the rule of 2 and 4 is often sufficient to roughly calculate equities in one’s head. It’s a little tougher when you can’t see the other guy’s cards…but ranging (making educated guesses about the “range” of hands your opponent can have) is an essential skill in NLHE.

Omaha, OTOH…is a little more difficult to calculate in your head. Propokertools’ seems to be one the cool kids always cite to. I could never figure out Bobby Baldwin’s system cited in Super/System 2, but it looked like one that you could use in your head.

For obvious reasons, such shows do not run in real time - they are delayed at least hours and often much more than that. So even if it were difficult to calculate odds (and, as other have noted, it isn’t) they could have been inserted during show’s preparation.

Yeah, but it isn’t always obvious what those outs are. For example, lets say you have A5 going against 25. You can’t just say the second hand has 3 outs (the three other 2s), because if the flop is 234 the first hand hits his straight. Even THEN you aren’t done, because if you turn over an A you get a chop. There are a lot of twists like that, and I can’t think of an algorithm that handles them all without just dealing every card and seeing who won.

[Quote= lisiate]
Even if you don’t know the other player’s cards you’re underestimating the power of modern computers. Evaluating 1.7 million possible hands (= the possible hands the other player has from the 50 cards still in play?) pretty much instantly just isn’t that impressive these days. Chances are your phone could do it faster than a google search.
[/Quote]
The program I wrote to do this took 4 seconds to run the odds on a fairly top machine, POST FLOP. Thats where I am only doing 45c2, or 1081 combinations. Now I am sure they have written more optimized code than me, but the fact is analyzing and comparing poker hands is a non-trivial task. I find it hard to believe they are bruteforcing 1.7 million hands instantly. I think its more likely they have crunched all the possibilities ahead of time and put them in a database, and then just do lookups. THAT is super easy. The other possibility is that they have a non-bruteforce solution, and that is what I am trying to figure out.

[Quote=Gray Ghost]
There are freeware equity calculators that you can use, as lisiate points out. I like pokerstove. Further, when playing, the rule of 2 and 4 is often sufficient to roughly calculate equities in one’s head. It’s a little tougher when you can’t see the other guy’s cards…but ranging (making educated guesses about the “range” of hands your opponent can have) is an essential skill in NLHE.
[/Quote]
I’m not looking for rough estimates, I’m interested in knowing the exact percentages.

[Quote=Xema]
For obvious reasons, such shows do not run in real time
[/quote]
True, but the website I linked DOES do it in real time.

For a computer, it’s fairly easy to calculate. It’s all been done ahead of time and can be plugged in at a moment’s notice.
It’s even easier when you consider that Ah5h is the same as Ad5d or Ac5c or As5s preflop.

Yes it is easy. My point is that it isnt FAST, which is why I agree that it has been done ahead of time. But i was thinking maybe there is a slick solution that DOES do it in real time.

Preflop? It’s very difficult if not almost impossible to mentally calculate how two hands rank up to one another. That doesn’t mean good players haven’t committed many of them to memory or can approximate others.
For instance, it takes very little math to know that As5s is a better hand than As5h. I know that the best hand to go up against AA is 65s of a different suit than the AA, but even that’s something like 3-1 against. I know that KK vs AA is something like 7-1 against.
So there are things that players just memorize. For the announcers or computers, it’s already calculated.

Post-flop it’s a lot easier to figure things out and many good players can figure out, down to the exact percentage, how two hands stack up against one another with two cards left to go.

It’s not that tough of a problem for a computer-based calculator. Again, from pokerstove, which is free. I don’t know if there’s an elegant mathematical solution, or if it just brute forces its way through each combination.

E.g: your Ac5c v 5s2s (BTW, the answer to this one usually is, ‘Fold pre’. “But they were suited!..”) Or pick another hand, if you want.

Those are the odds, exactly. Note the time it took the computer to get the answer.

For more complicated situations, like, let’s suppose our 52s opponent isn’t totally brain-dead, and is defending our open with ‘only’ a 30% range, you can go through each solution for each of the possible hands in a 30% range (~370 hands), or you can pseudo-Monte Carlo arrive at a solution.

Exact:

Aside, I’m really surprised the computer was able to come to an exact numerical solution this fast. Other times I’ve tried a similar calculation—though, usually with more than two players in the hand—and it grinds forever. Thinking it’s just pulling the results from a table. I tried this identical calculation just now, only adding a 3rd player with KQo, and it took not quite 8 seconds to churn through ~5 billion hands and spit out the equities. So, not instantaneously, but pretty quick.

OTOH, I tried a 6 way calculation with specified cards (like how ESPN would have it, knowing the exact hole cards) and the computer kicked out the result practically instantly. It’s only when working with ranges (even if the ranges are as small as the 12 hands in KQo) that my calculator bogs a little.
In short, as Enderw24 points out, it’s not that hard for modern computers to do the math in a quick manner. Even though, as you note, the problems have already been solved for two players, and it’s just a matter of grabbing the results from a look-up table. Clicking stop after the first iteration (about a second or less) while doing it by their version of Monte Carlo (and after only 2 million hands) yields an answer that’s only 5/100ths of a percent different than the final answer.

My estimation method was for how you can do it in your head at the table, assuming you’re not going to baldly cheat and run a calculator on your phone. Now, if I could only figure out Nash equilibrium ICM push/fold ranges in my head… Though there are calculators that will do that in about a half-second too.

For Ender’s PF point, Harrington on Hold 'Em has a section in one of the books where the author goes through a tournament hand and makes odds estimates of the hero’s hand vs. villain’s range using fairly easy math. Basically, you:

[ol]
[li]Assign a range to the villain[/li][li]Determine the number of combinations of different types of hands in that range (those that have two higher unpaired cards than hero’s hand; one higher, one lower; both inbetween, a pair inbetween the cards of hero’s hand, and so on…) [*]Find the average odds for each of those sub-ranges against hero’s hand, and[/li][li]Calculate a weighted average odds for that range against hero’s hand.[/li][/ol]
It’s a lot easier than I’ve just made it sound. Phil Gordon’s Little Gold Book, goes into some detail into these types of combinatoric odds calculations, and again, they’re not insanely hard to do. They aren’t going to be that exact, but then again, you don’t need them to be: knowing that you’ve ~37% vs his range, and you need 44% to call her pf shove, is often sufficient. Practice helps.

I think people are misunderstanding my intentions here. I am not interested in being able to, at the table, determine my chances of winning with any hand. I am looking to write a program that does this for every hand, more or less instantly. And I would prefer a solution that doesn’t involve creating a database of every hand combination if I can avoid it. I looked around a bit on poker stove and found this which gives some idea of the computation involved, but I couldn’t find the actual algorithm they are using for percentage calcualtions. I can download their app and use it, but I have no idea how it is working under the hood.

Elsewhere at their site, the guy mentions that his source code isn’t available, but that you might have a look at these guys’ code. (It’s eventually the same link cited within the post you cite.) He has made some of his old java libraries available, as mentioned in his FAQ. Perhaps you could take a look at them, decompile them (or whatever CS incantation is appropriate) and see if you can extract anything useful?

But as far as actual algorithms, that’s way past my level of computer expertise. Or statistics, for that matter. Fun to read about though. Good luck!

Additional question: do the odds displayed on screen take into account cards that are known to have been in other players’ folded hands, and thus are no longer possible outs? Sometimes they show these on camera, sometimes they don’t - and sometimes the TV show doesn’t show the whole hand, just the final rounds, so you don’t necessarily know what cards have been mucked early on.

I’ve never known them to add those in. The only calculations we see on screen only take into account those players that are currently in the hand and the communal cards.
Most TV shows’ calculations don’t even account for the odds of a tie occurring.

In TV coverage of the WSOP Main Event, they do. For an example, check out the hand that starts at 16:15 in this video.

Here’s a brief example of using the 2/4 rule along with a range of hands.