Shop OBEX P1 Docs P2 Docs Learn Events
Texas Hold'em poker probability calculator with the Propeller — Parallax Forums

Texas Hold'em poker probability calculator with the Propeller

cessnapilotcessnapilot Posts: 182
edited 2012-01-17 00:39 in Propeller 1
Hi,

To understand the chance of a given poker hand being the best hand at the table
is one of the three key elements of a good poker strategy. Usually it is the
first aspect that new poker players study and attempt to master. There are
online tools to calculate winning probability and my favorite is at
"www.pokerprobability.net". It generates, as I guess from the scattering of the
results, 1-2 thousands of random hands and community cards at the table against
multiple opponents for the estimations.

When watching poker on TV, you will often see a percentage next to the player's
card. That percentage let you know how often each player is going to win the
hand with the given hands of the other players and with the given, less than
five community cards. However, we are going to calculate only that probability
where you know only what you see: your 2 cards in hand and the community cards
so far dealt.

A pocket calculator sized handheld device to calculate that probability would
be useful to face an industry of online players. My design objective is to
calculate at least 10 thousand random dealings during 10 seconds for 2 digit
accurate probabilities. The final code should include the other two key elements
of the play , namely game theory and information theory. The hardware product of
the project with appropriate interfaces would be practical even for table poker
play.

Here I focus on the calculation of winning probabilities with the multicore
Propeller microcontroller. My first SPIN only trial uses standard Texas Hold'em
rules and can correctly evaluate 1000 random situations against 1 opponent in
18-22 seconds, depending on your hand strength. If you have a strong hand the
calculation takes longer time since the Propeller has to calculate all
combinations for the other players more often. Against 9 opponents it computes
and compares 1000 random dealings for 10 hands during ca 25 seconds. You can
find the code wrapped in a PST demo application at

http://obex.parallax.com/objects/831/

I devised a modulo based algorithm that uses primes to encode suits and ranks
of the cards. The product of the five suits and the five ranks are checked with
the MOD (//) operator and are simplified with the divide (/) operator to quickly
identify hand values including kickers. All possible hand strengths are paired
with unique integers. Comparison of two hands is simply a comparison of two
integers. The largest wins or there is a chop. See code for details.

Six COGs run parallel the same routine to generate random dealings against 1 to
9 opponents and the program can calculate probabilities for pre-flop, flop, turn
and river streets. The extension of the routine for Omaha Hold'em is almost
trivial but needs some coding and testing. The validated SPIN application for
Omaha will be uploaded, too.

The speed with SPIN is ok to test and optimize the algorithms, but when you do
not want to sacrifice accuracy, it is not enough for a practical handheld poker
player machine. I am working on the PASM version using the ultrafast PASM
multiplication and division algorithms that appeared in the "Fast, Faster,
Fastest Code" threads. From the conservative estimate of 30 times speed factor
of PASM vs SPIN I guess that evaluation of 10 thousand random poker hand
situations within 10 seconds can be realized with at least 4 COGs running
parallel for the job.

Any help or comment is welcome with this project. There is certainly room for
improvements in the SPIN code, to begin with. There may exist more SPIN tricks
to increase speed of execution of the tokenized expressions that I used. The
algorithm is correct, but it is a first draw from the idea of primes and
therefore probably not speed optimal. For example a quick identification of High
Card valued hands at the beginning would increase speed 3 times at least. The
published algorithm goes from top to down and starts the 5 card hand evaluation
with identifying flushes and straights which occur much less frequently then
High Cards. As for the PASM code, a fast modulo algorithm instead of full binary
division will improve speed, or a brand new method for poker hand value
evaluation using only additions and bit fields will be faster either.

Finally, if you find any bugs in the code (although that is not very probable:) )
please let me know.

-Istvan

Comments

  • idbruceidbruce Posts: 6,197
    edited 2012-01-14 16:11
    @cessnapilot

    I also enjoy poker :)

    But wouldn't this be considered cheating :) However, as you say, it would be nice for online games :)

    It would be nice to get some of the older guys in the forum to form a friendly poker game. :)

    We could play for Prop "Chips" :)

    Bruce
  • cessnapilotcessnapilot Posts: 182
    edited 2012-01-14 22:54
    Bruce:

    There are hundreds of poker software tools that people can use when playing
    online tournaments. Consider that cheating or not?

    My point in this thread is that Propeller (even 1) with its parallel processing ability
    can provide useful poker assistance without using a MAC or PC.

    The preliminary speed results with the PASM version are fulfilling the expectations
    I mentioned in the post.

    The novel feature of the propeller based poker assistant would be an effective
    game theory solution for long term efficient play.

    I tested that random numbers based strategy against poker playing PC, Mac and
    iPhone programs with 90% success. I won 9 tournaments (1000 chips, no limit) of 10,
    on average.

    I asked my family and friends whether I can use a MacBook Air at the table to test
    my program. They said: "Your program could not see the cards, why not?". Since then
    I won 12 of 15 tournament plays against 1 to 8 opponents. That plays helped me a lot
    to refine the game theory solution agains human opponents. The last 7 tournaments
    were won by the MacBook. Then I was kindly asked to remove the computer from the
    table, but they started to show definite interest in such a device.

    For a while I do not loose too much money with online poker, to say the least.

    Anyway, if anyone considers this Propeller project as cheating :), I apologize and stop
    uploading applications in this topic.

    Cheers,

    -Istvan
  • idbruceidbruce Posts: 6,197
    edited 2012-01-14 23:38
    cessnapilot

    I did not mean to offend you, I was just teasing. It sounds like a very nice project, please don't let my joking keep you from having fun and sharing with the others. I would like to have something like that myself.

    That being said, glad to hear that you are doing well with it. :)

    Bruce
  • TtailspinTtailspin Posts: 1,326
    edited 2012-01-15 07:53
    It's only cheating if you get caught..:cool:

    I think the true test of your calculator will be when everyone around the table has one crunching the numbers...
    would be kinda funny to see four or five players going all in.. before the flop...:smile:


    And, I am in for the poker game..:thumb:


    -Tommy
  • potatoheadpotatohead Posts: 10,261
    edited 2012-01-15 10:00
    As am I.

    Frankly, being married to a woman who is ranked online, and who does very well at the tables, I've learned the other element of the game which is knowing the other player. Using that device consistently may be a disadvantage. What the other experienced player will do is leverage predictable behavior to their advantage. Some players, at some times will play based almost entirely on their perception of the state of the other player. In simple terms, they simply know they can take the chips and just do, regardless of the cards in their hands. Seeing this is pretty amazing frankly.

    They do it by cultivating a table image, presenting strength or weakness to some advantage, rather than a real expression of their relative state in that moment of the game, attempt to get into the other players heads, and all manner of subtle things.

    PARTY POT! (in response to the comment above)

    All that said, I think it's a great project. Lots to be learned using it. Very cool.
  • idbruceidbruce Posts: 6,197
    edited 2012-01-15 10:19
    After hearing all this talk about poker, I just wasted two hours at pokerstars.net :) Fun, but non-productive.
  • cessnapilotcessnapilot Posts: 182
    edited 2012-01-15 10:25
    Bruce:

    I am not offended at all. Beside, I have seen the smilies in your sentences. But I do not want to hurt
    anyone's feelings who might think that computers and poker game should not mix. I even understand
    such attitude. For me chess lost most of its beauty after Deep Blue won the rematch agains Kasparov.

    Ttailspin:

    I checked your assumption with the current strategy, which is under development to change itself agains
    different kind of play. The game theory approximate solution is based on random numbers. The highest
    pre-flop winning probability hand is about 56% for 5 players game. The average strategy selects this time
    the all in only in the 0.5% of the cases. Only two players can have such cards (AA), the others highest
    winning probability is only 50%-45%. All 5 players going all in will happen only in 1 in 1EXP12 of the cases.

    In a 2 players game, where both having AA, the 2 al ins can happen together in only 5% of the cases.
    In the sequence of betting, the second one will respond by calling in all of the cases with AA in hand.


    Cheers,

    -Istvan
  • Heater.Heater. Posts: 21,230
    edited 2012-01-15 14:45
    cessnapilot,
    For me chess lost most of its beauty after Deep Blue won the rematch agains Kasparov.

    That's an interesting statement. Perhaps you could elaborate.

    The game of chess iteself did not change at the moment Deep Blue won. It's the same today as it was for centuries.

    Only issue I can see is that it is no longer possible to be sure are playing against a human that's not sitting in front of you. Online, or even by post, you cannot be sure they don't have their own "Deep Blue".

    (Yes, Chess by post, I have friends who did that for years while living on opposite sides of the planet, before the arrival of the internet)
  • cessnapilotcessnapilot Posts: 182
    edited 2012-01-16 01:59
    Heater. wrote: »

    "For me chess lost most of its beauty after Deep Blue won the rematch agains Kasparov."

    That's an interesting statement. Perhaps you could elaborate.

    Heater:

    That time I had the illusion that human intuition and intelligence in problem solving is so far superior
    to machine intelligence, that in a complex game like chess a world champion would allways win a
    tournament against a machine.

    For me poker is even more complex than chess and has many properties that chess has not. In poker
    you have to cope with hidden information, bluffing, multiple opponents. You have to use good risk
    management, you have to notice deceptions and have to learn the styles of other players to exploit
    their weakness. So, I have the illusion that machine intelligence could never beat top human players on
    the long term because of that complexity.

    You may ask, that with all of that illusion why am I developing a poker playing machine with the propeller.
    Poker is a recreation, and you have to pay for recreation. It would be nice to pay a negative amount
    of money for that recreation sometimes. The planned device would help the user to play fewer and less severe
    misplays than the opponents and ensure success in the long term against, at least, the avarege players.

    Why propeller? Beacuse I think that if you program it in the proper (parallel) way, it has enough computing
    power to tackle with such a complex task like efficient poker play :). The task is enormous, but I treat
    poker&propeller like a serious hobby, where you keep learning and look to improve.

    -Istvan
  • Heater.Heater. Posts: 21,230
    edited 2012-01-16 04:51
    cessnapilot,

    Interesting,
    That time I had the illusion that human intuition and intelligence in problem solving is so far superior to machine intelligence,...

    It may well be an illusion that human intuition/intelligence/thinking is fundamentally different than what a machine could do. That is to say it might be an illusion that we are not just machines. For a long time humans have held ideas about self awareness, consciousness, free will etc that are supposed to set us apart from machines, or even animals, in some mystical/spiritual non-material way. Perhaps that's all wrong. I have been unable to make a decision one way or the other.

    However, despite the existence of Deep Blue and other AI feats it's clear that humans are still far ahead of machine intelligence. After all it was humans that
    programmed the thing.
    ...that in a complex game like chess a world champion would always win a tournament against a machine.

    Actually I take the opposite view. Chess is actually a very simple game. It has a few things that can move. It has a small space in which they can move. It has
    a few very simple rules about how they can move. Clearly the game can be brute forced given enough time/memory without any intelligence required. Logically
    it's not much harder than getting a computer to compute.

    Practically of course we don't have a machine with the speed and memory to be useful with the brute force approach so we now have to program some short cuts
    into its search space. Heuristics or what ever they might be called. But wait a minute. Where did those short cuts come from? From the humans who programmed the
    thing.
    For me poker is even more complex...

    I know nothing about poker but I can't really see the difference. There is a small finite number of cards and a small finite number of rules. There is only so many states the system can be in. Yes there is an element of randomness that just means that you are dealing with probabilities and have to accept that sometimes you just can't win.
    ...you have to cope with hidden information...

    That's were the probabilities come in.
    ...bluffing...

    Isn't it possible the machine has the upper hand here. The only bluffing it might handle are the actions you take in the game, that's just part of the game. It can't bluff you with its table manner or personality but then neither can you bluff it with anything external to the game logic.

    Anyway it's all interesting stuff.
  • Heater.Heater. Posts: 21,230
    edited 2012-01-16 08:21
    Just for fun, here is a nice story about how badly some online Texas Holdem was compromised http://www.developer.com/sdtech/article/0,,12065_616221_1,00.html
  • cessnapilotcessnapilot Posts: 182
    edited 2012-01-17 00:39
    Heater:

    Bluffing is inside the game logic. Table manner, personality or loosing pokerface may help in that,
    but not too much in online play, where bluffing is important and frequently used. For example millions of
    hands of Texas Hold ’em played at Pokerstars.com were analysed, and it was found that 76%
    of them ended before a showdown. It was further found that in a showdown only slightly more
    than half the hands were won by the table’s best possible five-card hand. In 49.7% of the cases
    the player who could have made the best possible hand folded before the showdown.

    Computer can bluff against you and you can bluff against her if you accept a simple definition:
    You bluff when your money ratio in the pot is (would be) higher than the actual winning probability
    of your hand. The amount of the rise is an important factor for a human player, but the (experimental)
    poker calculator rises allways with the same amout (100 in a 1000 chip tournament) or with the
    minimum rise if 100 is not enough. In this way the amount of the rise does not convey information about
    the actual hand strength towards the opponents.

    -Istvan
Sign In or Register to comment.