Pokersource Poker-Eval, the open-source poker hand evaluation library, takes a lot of flack for being "low-level". In The Great Poker Hand Evaluator Roundup, I wrote:
The Poker-Eval library is implemented in highly optimized, heavily macro'd C for unadulterated speed, but language mappings for .NET, Java, and Python are provided. Now, I'll be honest. The first time I saw the poker-eval source code, I immediately unlearned about sixty-two months of best-practices software development...
That statement was a little tongue-in-cheek, but still: it seems like every time someone suggests Pokersource Poker-Eval, a disclaimer immediately follows:
Don't use this library unless you're a competent C programmer! Danger, Will Robinson!
Just the other day, for example, I was looking at poker-related questions on Stack Overflow when I came across this: How Do I Programatically Calculate Poker Odds?
Hello, I'm trying to write a simple game/utility to calculate poker odds. I know there's plenty of resources that talk about the formulas to do so, but I guess I'm having trouble translating that to code. Particularly, I'm interested in Texas Hold-em ...
I understand that there are several different approaches, one being that you can calculate the odds that you will draw some hand based on the cards you can see. The other approach is calculating the odds that you will win a certain hand. The second approach seems much more complex as you'd have to enter more data (how many players, etc.)
I'm not asking that you write it for me, but some nudges in the right direction would help :-)
One of the answers suggested using Pokersource:
Take a look at pokersource if you have reasonably strong C abilities. It's not simple, I'm afraid, but some of the things you're looking for are complex. The poker-eval program that uses the library will probably do much of what you want if you can get the input format correct (not easy either). Sites such as this one or this also use this library AFAIK.
Still, it could be worse, you could be wanting to calculate something tricky like Omaha Hi-lo...
Again with the disclaimer! And it occurred to me: you know what? All this FUD is really kind of bogus. As of this writing, Pokersource is still the best and most complete library of publically available poker-related code in the world. Period. What's more: the Pokersource evaluator is extremely easy to use provided you understand the Pokersource way of doing things.
So I thought, why not put together a brief Pokersource Poker-Eval primer?
The Pokersource evaluator represents a collection of N cards as a sequence of 52 bits, one bit for each card in the deck. This structure is called a mask and in code it's represented by the StdDeck_CardMask type. A single StdDeck_CardMask value can store a single card, an entire N-card poker hand, or any other arbitrary collection of between 0 and 52 cards. Typically, StdDeck_CardMask values will be used to store player hands, board cards, and/or dead cards:
Pokersource also allows a card to be addressed/identified by index—as an integer between 0 and 51. A given card index can be converted to an StdDeck_CardMask by using the StdDeck_MASK macro:
You can clear a given Pokersource mask (removing all cards from the mask) via the StdDeck_CardMask_RESET macro. It's a good idea to do this before using the mask (similar to initializing a numeric variable to 0).
You can combine Pokersource masks together to create a single mask containing all cards from both masks by using the StdDeck_CardMask_OR macro.
Since a single StdDeck_CardMask can "contain" between 0 and 52 cards, sometimes it's helpful to be able to count the cards present in a particular mask. For this, you can use the StdDeck_numCards macro:
Now you might be wondering: can the Pokersource evaluator handle text? The answer is yes. You can convert a textual description of a card (such as "Ah" or "2d") into the proper index value by using the StdDeck_stringToCard macro:
Which means that you can convert a textual description of a card into its corresponding mask value by using StdDeck_stringToCard followed by StdDeck_MASK:
This, of course, can be generalized to a function allowing you to convert text representing any number of cards into a single StdDeck_CardMask value:
Going in the opposite direction, we can convert a Pokersource mask value to text by using the StdDeck_maskString and StdDeck_maskToString macros. The difference is that StdDeck_maskString manages the memory for the string internally, whereas StdDeck_maskToString copies the text to a user-supplied string buffer.
Similarly, we can take a card index and get a text value representing that card using the StdDeck_cardToString macro:
Another popular way of representing card values is as a combination of rank and suit. Pokersource allows you to create an StdDeck_CardMask value for a specific card by specifying its rank and suit in the StdDeck_MAKE_CARD macro, which returns the card's index:
Note that Pokersource has a specific numeric definition of each card rank:
As well as each suit. Pokersource bucks convention here by ordering suits Hearts-Diamonds-Clubs-Spades rather than Clubs-Diamonds-Hearts-Spades but it doesn't really matter.
Pokersource Poker-Eval is, first and foremost, a hand evaluator. It takes a given N-card poker hand and returns a number which can be compared with the number returned for other hands to determine the winner. There are two evaluation macros you'll typically use:
So in order to determine the winner in a game of Texas Hold'em where Player 1 has "AhAd" and Player 2 has "KcKs" on a board of "2d4c4sKh9d", you'll write code similar to this:
Using the StdDeck_StdRules_EVAL_TYPE evaluator is exactly the same, except the value returned is an integer representing the category of the hand.
That's literally all there is to it.
It's a little-known fact, but Pokersource ships with built-in support for both Monte Carlo simulation and Exhaustive Enumeration. In fact, we can leverage the Pokersource enumeration library to build a full-fledged poker calculator with support for multiple opponents with arbitrary hand ranges or distributions.
Pokersource provides Monte Carlo and Exhaustive Enumeration functionality through the following macros, all of which live in the enumerate.h header file.
Using these macros is extremely simple provided you understand the format. Basically, each macro is going to "visit" or "generate" certain cards, repeatedly, using either exhaustive enumeration or Monte Carlo. For each set of visited/generated cards, the macro is going to execute a piece of arbitrary code provided by you.
This will be clearer if we look at some source code. Here's how you'd calculate the equity of a typical preflop matchup...
...using exhaustive enumeration of all possible outcomes.
The above code exhaustively enumerates all 1,712,304 possible outcomes (the number of unique 5-card boards that can be drawn from the 48 remaining cards in the deck) and runs the evaluator for each, tallying per-player wins which are then converted into percentage equities. If you wanted to use Monte Carlo instead, you'd use DECK_MONTECARLO_N_CARDS_D.
The other enumeration macros all have this same structure: you tell Pokersource what you want enumerated or randomly sampled, and it does the grunt work, executing your user-provided code once for each enumerated/sampled outcome.
The ability to generically enumerate/randomly sample specific subsets of cards in the presence of dead cards is enough firepower to build a full-fledged poker calculator such as the one we built in Multiway Isometric Ranged Equity Calculation in Poker, Part 1. And yet this post has really only scratched the surface of what is possible with Pokersource. We haven't discussed Pokersource's support for other poker variants (Omaha, Stud, etc.), or how the Pokersource evaluator can be extended to support still other variants.
In conclusion, when looking for poker evaluation / calculation code, Pokersource should always be your first stop. I'm not saying it's always the right library for the job, but you won't find another publically available library that has equivalent functionality. I encourage you to explore the Pokersource library and who knows, perhaps join the Pokersource email distribution list and say hello to Loic Dachary, Michael Maurer, and some of the other maintainers.
Long live Pokersource!
38 comment(s)
Thank you for this introduction to poker-eval, it's a great way to start with pokersource. I would like to mention that we (pokersource developers) are looking for help to implement new features in [url=http://pokersource.info/]pokersource[/url]. If you are interested, please send a mail to [url=mailto:pokersource-users@gna.org]pokersource-users@gna.org[/url] or come visit the chat room at [url]http://irc.freenode.net/[/url] #pokersource
Loic Dachary on Monday, April 20, 2009Hey James, one of your 2+2 'fans' here. I stumble across every once in a while some Pokersource code in the software forum. never quite could figure out just what the hell all the different macros meant. (and I'm a C programmer). This will come in handy for me.
To Loic: I really think the pokersource would benefit from a good set of docs. Ive searched and searched for an 'API guide' but have never found one. Just bits and pieces on different forums.
Anonymous on Monday, April 20, 2009What about including this post (or part of it) in poker-eval future releases, as TUTORIAL.txt for example ?
@James Devlin, would you agree to release this tutorial under a permissive License ?
proppy on Monday, April 20, 2009I agree that pokersource needs documentation. The best documentation at the moment are the test cases (poker-engine is fully covered and poker-network will soon be). But it's difficult for a beginner. I would love to see a native english speaker bootstrap this effort.
Loic Dachary on Monday, April 20, 2009Long ago I modified hcmpn.c to make it into a nice quick command-line calculator I could use in-game; unfortunately I seem to have lost the code. I can't believe I didn't think to release it!
Bill Mill on Monday, April 20, 2009I am with affiliate programs pokersource , just reffer that team for all :) Thay have great offer's. Regards
Darmo on Tuesday, April 21, 2009I have no problem with that. Most of the content on this site is under the Do What the F--k You Want To Public License by fiat. But I think Pokersource deserves a formal set of docs!
@Bill Mill: Ah, good old hcmpn.c. I know it well.
James Devlin on Tuesday, April 21, 2009@James, trying to make a poker table simulation in a first step at developing a poker bot. Can I use "StdDeck_ StdRules _EVAL" to find the best hand for one player out of a given set of cards? Ie, if I passed all 5 combinations of 7 cards, from a TexasHoldEm table, would I get the best hand the player can make? Also, can I use pokereval to figure out the probability of making a certain hand, assuming that the next card dealt is random and my hole cards and the table cards are dead?
Anonymous on Thursday, April 29, 2010I am so convinced he had found this post because I've been looking for some information on the Epic Mickey almost two hours. You really helped me and reading this article that I found many new and useful information about it. Well, I'll definitely bookmark your site and wait for other useful and informative messages like this in the future. logo design & website design
Alex on Wednesday, June 23, 2010Introduced in 1990 as the Nike Air Max III, the Nike Air Max 90 turned more heads with an even larger visible Air unit and greater stability and cushioning. It has been re-released as a retro version with an immeasurable amount of colorways and themes. The Air Max 90 was referred to as the Air Max or the Air Max III until 2000, when it was reissued. It takes its current name from its launch year, 1990.The first colourway produced was the men¡¯s white / black / cool grey / red. It was striking to say the least: the radiant red around the visible Air window exaggerated the thickness of the midsole, and the matching thermoplastic straps and rubber heel patch added to the overall effect. The upper was made of Duromesh, synthetic suede and synthetic leather. The clean lines and dazzling colours made the Air Max a higly sought-after.
Nike Air Max 90 on Thursday, July 08, 2010nice article. keep post like this...
Ebel replica watches on Tuesday, July 20, 2010nice article. keep post like this...
Tonino Lamborghini replica watches on Saturday, July 24, 2010PerformingGraham for sale that will create a one-wayswiss watches backlink to your website whichMaurice Lacroix watches is a good point to have. It is Patek Philippe watchesa time-consuming Tag Heuer for saleprocess even though it produces good outcomes U-boat for saleand works. You can also swiss watchespost comments on blogs alongMaurice Lacroix watches together with your link, but make sureGraham watches these blogs are do-follow, which dolce & gabbana handbagsindicates the link that youreplica coach handbags simply post will probably be replica handbagscounted by the search engines jimmy choo replicaas a backlink.There are many thingsversace replica handbags that contribute to online businessjuicy couture replica failure, and the lack of good action thomas wyldeis surely one of the deadliest business-killersdolce gabbana handbags on the net. Take action like by no means chloe handbags replicaprior to, and don’t get struck by analysis paralysisburberry replica. Your achievement lies in your rapid actionchanel replica and how well you apply numerous strategies.
replica watches on Saturday, July 24, 2010nike air jordan 2010 nike air jordan 5 nike air jordan 3 nike air jordan 11 cheap nike air jordan 2 nike air jordan 1 nike air jordan shoes discount nike air jordan shoes nike air jordan 6 wholesale nike air jordan 1 discount nike air jordan 6 nike air jordan 7 nike air jordan 8 top quality nike air jordan shoes 23 nike air jordan 21 nike air jordan 22 nike air jordan 6 rings cheap nike air jordan 22 nike air lebron james shoes nike air lebron james shoes nike air jordan 2010 nike air joredan lebron james nike air jordan 2009 discount nike air jordan 2009 nike lebron james wholesale nike air jordan 2010 cheap nike air jordan 2009 discount nike air jordan 19 cheap nike air jordan 3 discount nike air jordan 18 brand nike air jordan 12 wholesale nike air jordan 2 nike air jordan 13 nike air jordan 14 nike air jordan 6 rings discount jordan shoes7 discount jordan shoes1 jordan shoes2010 jordan shoes 6 rings cheap jordan shoes2 discountjordan shoes3 discount jordan shoes4 jordan shoes uk23 jordan shoes classic bw22 cheap jordan shoes 21 ltd discount jordan shoes20 discountjordan shoes19 jordan shoes 18 uk nike air jordan shoes 17 cheap nike air jordan shoes 16 discount air jordan shoes 15 discount air jordan shoes 14 nike air jordan shoes 3 uk nike air jordan shoes 13 cheap nike air jordan shoes 11 discount air jordan shoes 6 discount jordan shoes 10 nike air jordan shoes 8 nike air jordan shoes 7 cheap louis vuitton bags cheap kobe bryant shoes cheap lebron james shoes .
cheapjordan on Saturday, July 24, 2010I will keep visiting this blog very often. Blu ray ripper /
ipad converter on Sunday, July 25, 2010The variety links of london items bearing depends on the occasion. You are plain, but you are elegant. links of London sweetie braceletIf presence a groove, especially nightfall outfit, you are allowed to be very gentle in truth. What you should do is to links of london charms choose some delicate sweetie bracelets with your subtle sensation of fashion on Christmas Day, Easter, Halloween and Valentines Day. Discovering links of London friendship bracelet on the net is an excellent choice for your needs and can also assure you may benefit from the best insurance coverage at the best price tag. The links of London braceletis one kind of those brands that basically level the start a time honored design and style and design untreated. links of london necklace and links of london earringswill be the consultant of level and higher personal taste; so many people contain the hopes for donning links of London sweetie bracelets. Nevertheless, in the large price, so most of us cannot pay the big money. links of London friendship bracelets charm bracelets links of london sale charm bracelet silver friendship bracelets links of london charm bracelet
links of london on Monday, July 26, 2010ed hardy, cheap ed hardy, ed hardy clothing, ed hardy outlet, ed hardy jeans, ed hardy bags, ed hardy swimwear, ed hardy shirts, ed hardy tee, ed hardy caps, ed hardy purse, ed hardy board shorts, ed hardy shoes, ed hardy for men, ed hardy for women, ed hardy jeans for women.
cheap ed hardy on Tuesday, July 27, 2010ed hardy, cheap ed hardy, ed hardy clothing, ed hardy outlet, ed hardy jeans, ed hardy bags, ed hardy swimwear, ed hardy shirts, ed hardy tee, ed hardy caps, ed hardy purse, ed hardy board shorts, ed hardy shoes, ed hardy for men, ed hardy for women, ed hardy jeans for women.
cheap ed hardy on Tuesday, July 27, 2010Porsche did not specify a production start-up date or a price tag, although widespread media reports in Europe have suggested the sticker could exceed $600,000.
ブランド腕時計;ロレックス時計;オメガ時計;IWC腕時計 ロレックスデイトナ;ロレックスエクスプローラー;ロレックスGMTマスターII オメガスピードマスター;オメガシーマスター;オメガアクアテラ;オメガデ・ヴィル IWCアクアタイマー;IWCインヂュニア;IWCスピットファイアー;IWCポルトギーゼ ロレックスサブマリーナ;ロレックスヨットマスター;ロレックスターノグラフ ロレックスミルガウス;ロレックスエアキング;ロレックスパーペチュアルデイト ロレックスチェリーニ チェリニウム;ロレックスデイデイト;ロレックスプリンス オメガコンステレーション;IWCクラシックパイロット;IWCポートフィノ;ロレックスデイトジャスト
Michael Macht, Porsche AG president and chairman of the board of management, said: "Production of the 918 Spyder in a limited series proves that we are taking the right approach with Porsche Intelligent Performance,
バッグ コピー、財布 コピー グッチ;グッチ バッグ;グッチ コインケース・キーケース・ポーチ・小物;グッチ 財布;シャネル;シャネル バッグ;シャネル 財布;ベルト;グッチ ベルト;ルイ・ヴィトン ベルト;エルメス ベルト;シャネル ベルト;フェンディ ベルト;バーバリー ベルト;ディオール ベルト;ブルガリ ベルト;ミュウミュウ;ミュウミュウ バッグ;ミュウミュウ 財布;プラダ;プラダ バッグ;プラダ 財布;バーバリー;バーバリー バッグ;バーバリー 財布;バレンシアガ;バレンシアガ バッグ;バレンシアガ 財布;ディオール;ディオール バッグ ;ディオール 財布;クロエ;クロエ バッグ;クロエ 財布;フェンディ;フェンディ バッグ;フェンディ 財布
featuring the combination of supreme performance and efficient drivetrain concepts."
グッチコピー|グッチバッグ|グッチ財布 グッチ ハンドバッグ;グッチ ショルダーバッグ;グッチ ボストンバッグ;グッチ トートバッグ; グッチ 二ツ折り財布;グッチ 長財布;グッチ wホック財布
ブランド腕時計 on Thursday, July 29, 2010Hey i'm off to new york this year and thinking about getting a Louis Vuitton online store It really depends on
your budget. Since you don't like the speedy ...
We provide the best quality and attractive price. No sale tax , Buy now , Free shipping! Welcome Guest! Would you like
tItlE="Louis Vuitton Replica">Louis Vuitton Replica
yourself in?Best Deals From Louis Vuitton Purses Collection Guranteed !! Louis Vuitton - I would have to admit that at first I wasn't
really sure how to pronounce ...
louis vuitton on Thursday, July 29, 2010Wholesale NFL Jerseys
Cheap NFL Jerseys
NFL Jerseys
NFL Football Jerseys
Women NFL Jerseys
Kid NFL Jerseys
Super Bowl Jerseys
Super Bowl NFL Jerseys
Throwback Jerseys
Throwback NFL Jerseys
Cheap Throwback Jerseys
Wholesale Throwback Jerseys
Cheap Super Bowl Jerseys
Wholesale Super Bowl Jerseys
youth nfl jerseys wholesale
youth nfl jerseys cheap
nfl youth jerseys
Baltimore Ravens Jerseys
Chicago Bears Jerseys
Cincinnati Bengals Jerseys
Denver Broncos Jerseys
Dallas Cowboys Jerseys
Green Bay Packers Jerseys
Indianapolis Colts Jerseys
Minnesota Vikings Jerseys
New England Patriots Jerseys
New Orleans Saints Jerseys
New York Jets Jerseys
Arizona Cardinals Jerseys
Buffalo Bills Jerseys
Atlanta Falcons Jerseys
Carolina Panthers Jerseys
Cleveland Browns Jerseys
Houston Texans Jerseys
Detroit Lions Jerseys
Jacksonville Jaguars Jerseys
Kansas City Chiefs Jerseys
Miami Dolphins Jerseys
New York Giants Jerseys
Philadelphia Eagles Jerseys
San Francisco 49ers Jerseys
Oakland Raiders Jerseys
Seattle Seahawks Jerseys
Pittsburgh Steelers Jerseys
St Louis Rams Jerseys
San Diego Chargers Jerseys
Tampa Bay Buccaneers Jerseys
Tennessee Titans Jerseys
Washington Redskins Jerseys
Ray Lewis Jerseys
Ed Reed Jerseys
Joe Flacco Jerseys
Terrell Suggs Jerseys
Dick Butkus Jerseys
Greg Olsen Jerseys
Matt Forte Jerseys
Devin Hester Jerseys
Walter Payton Jerseys
Brian Urlacher Jerseys
Lance Briggs Jerseys
Jay Cutler Jerseys
Carson Palmer Jerseys
Rey Maualuga Jerseys
Chad Johnson Jerseys
Demarcus Ware Jerseys
Jason Witten Jerseys
Terrell Owens Jerseys
Felix Jones Jerseys
Marion Barber Navy Jerseys
Marion Barber Jerseys
Emmitt Smith Jerseys
Miles Austin Jerseys
Roger Staubach Jerseys
Troy Aikman Jerseys
Tony Romo Jerseys
Eddie Royal Jerseys
Brandon Marshall Jerseys
Aaron Rodgers Jerseys
A.J. Hawk Jerseys
Donald Driver Jerseys
Greg Jennings Jerseys
Peyton Manning Jerseys
Dallas Clark Jerseys
Robert Mathis Jerseys
Marvin Harrison Jerseys
Drew Brees Jerseys
Marques Colston Jerseys
Pierre Thomas Jerseys
Reggie Bush Jerseys
Jeremy Shockey Jerseys
Tarvaris Jackson Jerseys
Adrian Peterson Jerseys
Jared Allen Jerseys
Mark Sanchez Jerseys
Thomas Jones Jerseys
Leon Washington Jerseys
Brett Favre Jerseys
buynflshop on Thursday, July 29, 2010Share your knowledge to continue a timeless tradition;
DVD Ripper on Friday, July 30, 2010Life will change what you are but not who you are;
Blu-ray Ripper on Friday, July 30, 2010Marry a person who likes talking; because when you get old, you’ll find that chatting to be a great advantage
blu-ray ripper on Friday, July 30, 2010Live a noble and honest life. Reviving past times in your old age will help you to enjoy your life again;
DVD Ripper on Friday, July 30, 2010essay essay writing essay writing service essay writing service uk
jane on Friday, July 30, 2010I like your article. Will always support you!He is quite a good reading. i'd appreciate it. time to realize his.
DVD Ripper on Friday, July 30, 2010Pool Temperature Madera Jobs Madera Pest Control Madera Dentist Merced Dentist Visalia Dentist Modesto Dentist Fresno Limousine Fresno Granite briefcases leather leather briefcases prospect solution | prospect solutions | prospectsolution | prospectsolutions | prospectsolution.com prospect solution | prospect solutions | prospectsolution | prospectsolutions | prospectsolution.com prospect solution | prospect solutions | prospectsolution | prospectsolutions | prospectsolution.com
carmi on Friday, July 30, 2010In your article I found very different things. Very characteristic. I've never seen before.Thank you very much the share. you are very creative.
DVD to iPod on Friday, July 30, 2010Choosing the right tiffany jewelry accessory will turn an ordinary outfit into a fashion statement before you buy it from one mall or others, you can budget from our mall; christian louboutin as being beautiful and making us feel sexy Italian research has shown that a good pair of heels can help tone the body, condition muscles and improve the wearer's sex life, buy it please click the link; Look for ed hardy clothing, just click the link and you will have a great surprise; Finding beautiful cartier jewelry as gifts, we provide different styles for your reference; Choose the different links of london jewellery from our site, enjoy free and fast shopping worldwide; If you plan on shopping for NFL jerseys, you can purchase nfl jerseys online at our mall. We will do our best to serve for you. Welcome you!
tiffany jewelry on Friday, July 30, 2010Your article is very appealing to me.I like this article, this article that i learned a lot of knowledge.
Video Converter on Friday, July 30, 2010You have a unique perspective.Thank you for sharing. it is wonderful super classic. I admire you.
DVD Cloner on Friday, July 30, 2010Replica miu miu handbags are not just beautiful and elegant, but it is also at excellent quality and similar design as the real. You will like it once you see it. Now attention please, at our shop, we are holding a promotion. You can buy replica miu miu bags of high quality with the lowest price. Meanwhile, miu miu handbags buying from here you can enjoy free and fast delivery shipping. Welcome to our shop!
miu miu bags on Friday, July 30, 2010Want to get Ed hardy at home? No hesitation, get them at with big discount. We are promise you that all the ed hardy clothing are good in qualities. Meanwhile, buying ed hardy clothing online, that’s never a bad idea. By the way, whenever and wherever you need us, we will be there for you. Ed Hardy T-Shirts are waiting for you now, welcome you!
ed hardy on Friday, July 30, 2010www.thesuitshoes.com can provide you the best MBT shoes to choice.
mbt shoes on Friday, July 30, 2010www.thesuitshoes.com can provide you the best MBT shoes to choice.
mbt shoes on Friday, July 30, 2010good news
hermes birkin on Friday, July 30, 2010thanks for your kindly sharing
abercrombie and fitch on Friday, July 30, 2010