Poker Bots

  1. Cached
  2. Poker Bots Online

This is the first part of Building a Poker Bot series where I describe my experience developing bot softwarefor online poker rooms. I’m building the bot with .NET framework and F# language which makes the task relativelyeasy and very enjoyable.

Play Texas Holdem vs Advanced Ai Bots. About What Is This? This is your opportunity to play heads up holdem against Cleverpiggy and Hibiscus Biscuit, two super duper awesome heads up poker playing agents. The poker bot operation algorithm is as follows:PokerRecorder scans the poker table, then sends the scanned elements of the poker table to recognition PokerRecorderOCR, then generates a hand history and sends it to the GTO+X, which controls, depending on the settings, PokerSnowie and/or ICMIZER, further PokerSnowie or ICMIZER analyzes the.

Screen recognition

For a human, the very first step to the ability to play poker is to understand the cards, what a hand is andwhat the value of your hand is. E.g. in Texas Holdem each player gets 2 hole cards which form a hand. Atthe showdown the player with the best hand wins.

Poker bots are no different, they also need to be taught the notion of cards and hands. A bot should “watch”the table and see which cards he is dealt with. There are several ways to achieve that but I go for a techniquecalled screen recognition, i.e. the bot makes a screenshot of a table and then reads the pixels to understandwhat’s going on. Very similar to what people do.

Image recognition in general is a tough task. Human beings are very good at interpreting vague images andrecognizing familiar objects. It’s much more difficult for computers. General image recognition (think showinga photo to your computer and asking whether there is an animal there) is very tough; corporations like Googleand Microsoft are spending numerous man-years and employ techniques like machine learning and neural networks.

Fortunately, poker table recognition is much easier. The images to be recognized are machine-generated, sothe same things are rendered more or less the same way all the time. It makes sense to keep the poker tablesize fixed to some predefined value which makes recognition task fairly easy.

Card recognition steps

There are 13 card faces (from Deuce to Ace) and 4 suits. All of them are just fixed-size images which we need to be able tomatch with. So we start with a screenshot of a poker table:

The table size is fixed, so are the left and the top pixel positions of hole cards. So, our first step is to extractthe small images of cards out of the big screenshot:

Now, we can take the recognition of card faces and suits separately. In our sample layout, suits are color coded.This is very friendly to humans and super simple for the bot. We pick the suit based on the color (ignoringthe white pixels):

This leaves us with the task of choosing between 13 card faces. The color information is not importanthere, we can make the image grey-scale. Moreover, we can reduce the color information to the single bit perpixel - call it white or black:

Now this mask is very simple, and we can compare it with 13 predefined masks for 13 cards pixel by pixel.The one with the biggest amount of matches wins.

Suit recognition

Poker Bots

Let’s put some code at the table. We start with suit recognition. getSuit function has typeColor -> string option and converts the color of a pixel into the suit name, if possible. Hearts (“h”)are red, Diamonds (“d”) are blue, Clubs (“c”) are green and Spades (“s”) are black:

This function is used by getCardSuit function of type (int -> int -> Color) -> int -> int -> string.Its first argument is a function which returns the color of a pixel based on (x, y)relative coordinates (starting with 0). The next two arguments are width and height of the cards. Result isthe same suit name that we described above. The function loops through all the pixels, gets a suit perpixel and then returns the suit which is the most popular among them. Alternatively, we could just returnthe first suit found, but my implementation looks more resilient:

Producing the black & white pattern

getCardPattern accepts the same parameters as getSuits but returns seq<BW> instead. This isa sequence of black or white pixels with a helper union type:

The function body enumerates the pixels and return black or white result as a flat sequence:

Card face recognition

Having a black and white pattern, we can compare it with the predefined patterns and pick themost similar one. A pattern is defined with a helper type

Pattern is a sequence which is equivalent to the sequence we got on the previous step.Card is a string of hand face value 2, 3, 4 .. A. getCardFace has the typeCardPattern[] -> seq<BW> -> string, it accepts an array of known patterns and a patternof the card to be recognized. It compares patterns pixel by pixel and returns the cardwhich has the biggest amount of matches:

Getting the known patterns

So how do we create an array of known patterns? It’s tedious to do manually, sowe use a bit of code generation.Basically we just take several screenshots of poker tables and feed them to the followinghelper function:

The function creates a string which can be copy-pasted into F# array of BW.

Putting it all together

Here is the facade function that will be called from the outside:

The calling code looks like this:

leftX, rightX, top, width and height are well-known parameters of cards locations within a screenshot,which are hard coded for a given table size.

Conclusion

The full code for card recognition can be found in my github repo. It’s just 75 lines of code which ismuch less that one could imagine for a task of image recognition. Similar code could be used to recognize otherfixed objects at poker table: dealer button location, action buttons, checkboxes etc. In the next part of thisseries I will show how to recognize non-fixed parts: text and numbers.

Cached

Proceed to Part 2 of Building a Poker Bot: String and Number Recognition.

NPR’s sites use cookies, similar tracking and storage technologies, and information about the device you use to access our sites (together, “cookies”) to enhance your viewing, listening and user experience, personalize content, personalize messages from NPR’s sponsors, provide social media features, and analyze NPR’s traffic. This information is shared with social media, sponsorship, analytics, and other vendors or service providers. See details.

Poker Bots Online

You may click on “Your Choices” below to learn about and use cookie management tools to limit use of cookies when you visit NPR’s sites. You can adjust your cookie choices in those tools at any time. If you click “Agree and Continue” below, you acknowledge that your cookie choices in those tools will be respected and that you otherwise agree to the use of cookies on NPR’s sites.