How I Built a Working Online Poker Bot, Part 2: Interlude

Tuesday, May 20, 2008

[Update: two of the original authors of this post have moved on to greener pastures, and have asked us to mothball this content in preparation for an upcoming book. Thanks for all the feedback and stay tuned for more technical poker content in the future.]

Introduction

Last week, we posted about how we built a working, real-money online poker bot. This week, we'll discuss how to get started building your own bot, address some specific bot-building techniques, talk about the woeful state of online poker user privacy, respond to a few reader questions and comments, and close out with some recommended reading...

 

Tags: poker bot, C, Windows API, DLL Injection, input simulation, chess, Deep Blue, C++, online poker, poker

102 comment(s)

James - excellent post, I personally like it when you include a bunch of source code, but realize that might not be to every taste..but it's good to take a break too. I AM looking forward to the AI stuff. Keep up the good work.

Interesting vid.. do you have the code for it? Can you post the code or let us download the app. I've got a friend I'd love to use that on, lol

i'm not satisfied til i get the c++ code for the bot a.i. better yet, C# :-)

I've long wondered whether I was being taken for a ride by poker bots while playing online.

This is such a cool series. :)

very nice thanks for #2 good read like the first.

Ok, you got a major load on your servers. Really loved your first post but thisis going down the drain...

Seems like you went from an informative article with good content (#1) to no real content and a sales pitch for a few books on amazon to earn you some money (#2).

"Ironically, your profit would shrink to zero if the site stopped collecting rake! The thing that more than any other makes games tough to beat - the rake - makes it possible for your bot to turn a healthy profit. And that, as a long-time online poker player, makes me smile."

That's not true at all. In fact, the logic there is terrible. If your bot is breaking even at a raked table, and you remove the rake, it would become a winning player. Far more so, in fact, than it makes just taking 35% of the rake back. It would then be getting 100% rake back.

You need to rethink your paragraph on rakeback as Matt pointed out.

You're going to make a lot of poker sites very, very unhappy.

Like everyone else, I'm loving the articles. Keep 'em coming.

I'm guessing the final article will also mention how an online poker bot is capable of spotting a rival bot and how it uses that information to its advantage :)

Xirium, it may indirectly make lots of poker sites very unhappy when hundreds or even thousands of home-grown poker bots start sitting at their tables. Some of which will be weak and have obvious "bot-like tells" and therefore create a great many unhappy human players who will undoubtedly complain and take their business elsewhere!

Hi,

I would like to hire you to run a winning poker bot. How much would you charge ?

Thanks in advance

The poker sites are installing software that spies on you?

What kind of a complete and total retard are you?

I thought after this first post you were misguided, now I'm positive you're just retarded.

@Eric: And which poker site do you work for pray tell??

nyack nyack

shillz... lulz.. gotta love em

Hey James whats the IP lookup on that??

You might want to black out the names in the image, rather than blurring them -- as they stand now, some of them, at least, are retrievable with a bit of effort.

Expect the trolls to come out in force on this one James.. GOOD ARTICLE, fwiw, and about time somebody pointed this @#$$ out. The same thing with regard to privacy has been happening in WoW for too long..

http://www.kensavage.com/index.php/archives/world-of-warcraft-spyware/

Loic- I've got a poker bot I'll sell you for a mere $50 transfer on PStars ;-)

@Rich. Here the post where it broke.

"4.5 million copies of EULA-compliant spyware".. World of Warcraft spyware.

http://www.rootkit.com/blog.php?newsid=358

This is a great series. I would love to see more details on reading the text from the GUIs and changing the UI as shown in the video.

I have been looking at a .NET application that uses custom UI widgets instead of the standard controls etc. I tried using many API spying programs to get the text that is displayed on the custom controls, but the lpString parameter of ExtTextOut appeared to be garbled (unprintable characters). I need to do further testing and research.

Keep up the great work.

@Ethan - actually they wont take their business elsewhere. What will happen is a bunch of poorly coded bots will spring up and actually lose money to humans and better coded bots.

h4x

Adam, it would be interesting if players come to welcome bots because the only bots they really notice are the ones that are playing terribly and are beatable. What is probably inevitable though, is that a highly successful winning bot will get caught and possibly exposed to the public--then there would be chaos.

Why the poker sites don't really care about a few bots: bots just mean more hands are played, and since the poker sites get their moolah from the rake, they are happy more hands are played.

Why that isn't sustainable: I am sure most people don't like playing against bots. So basically, bots make the other players unhappy. Unhappy players leave. Poker sites then cry. So basically, if bots become widespread, they will inevitably wreck the game of online poker.

That said, I save have at it. It is cool stuff, and those poker sites that are worth their salt will figure out how to foil your bots. But you may soon end up seeing captchas sprinkled throughout the game to foil bots. Which is kinda sucky for everyone.

@James:

Strategy would shift toward playing a few % more hands. That would make the bot play more postflop, which is certainly it's weak point. So you won't get the 3.3x gain you would mathematically expect otherwise when going from 30% rakeback to 100%.

Pouring $100 or more per hour into the tables would also probably cause players to raise limits (the losing players now lose much less, and the winning players win more). So maybe you would get that 3x plus return. Maybe more.

Either way, adding that amount to the table is very significant, and I don't think it would be possible for someone to have an EV afterward that isn't significantly higher, even with rakeback and even if they don't adjust.

Very promission! Keep up the good work.

i agree with matt that the bot is likely to win with no rake if it breaks even with rake, but who cares?? like the sites will ever get rid of rake. non-issue

Poker bots are over-rated, but it's cool work you've done.

A human player using a decision support system showing expected value outcome statistics can crush Polaris quite easily, data are here:

http://forums.poker-academy.com/viewtopic.php?t=8061&highlight=hwt1

The advantage of poker bots is that they are better at the math. When humans are equated on this (i.e., outcome statistics for playing choices), humans, with their wily intelligences, can make better decisions than bots.

"assist with inter-bot collusion" ? !

Hold on there Hollywood. I'm not into that!

what do you think is the biggest advantage with code injection over proxying the SSL traffic and reading/injecting packets into the datastream directly? is it worh the extra work just to be able to use pre-defined datastructures?

Mr. Devlin, Thank you for these articles. Your explanations helped me better understand how coding with Windows API work. It has certainly sparked my interest and I am very grateful for that.

@anonymous

seems like the packet-injection approach is more work than code injection.. then again I'm a mere application developer with not much knowledge of network-related things. is this something you web guys do frequently? hack into SSL data streams?

Hello from Germany!!! Keep up the good work!!

Thank you for the effort you are putting into this James!

I started programming in 2004 (primarily got interested in it due to aimbots and such in fps games) and have always been interested in the very things you are talking about now. I have not had the time myself to research these topics, nor have I had the opportunity at work to work on a project that would encompass this type of development.

I am really looking forward to your explanations on ai and simulating user input, and if you are taking suggestions for language examples ("expressed in C++, C#, or the language of your choice"), I'd love to see some in c#.

"Building a bot is neither unethical nor cheating by any sensible definition of the word"

Here's a sensible definition: It is not allowed by the poker sites. The players do not want to play against bots. Those players play on sites which do not allow bots. Definition = Unethical.

I'm most looking forward to some sort of code on how you are grabbing the card values - be it via screenscrape or any of the other methods you mentioned.

I think that would be a lot more useful as any monkey can create a mouse click and auto-fold until they get top 10 hands and then hammer it preflop and on all streets. To be honest my lack of knowing an efficient way to gather the hole cards is the only thing that's been holding me back from building a poker bot over the past few years.

Can the next article go into more about the algorithm of the bot? How the bot plays? How the bot breaks even? I know how to figure out how to make the bot interact with the poker client (even though I would like to learn more about the DLL injection), I want to know how to make the bot play.

A very nice start to what we hope will be an interesting series.

Will you be describing a preflop "shove bot" based on hole cards and position, or a more sophisticated bot that reads the postflop board, and considers betting action, stack sizes, and player stats before it makes a decision?

Either one would be interesting, but the later one more so.

I don't like the collusion stuff either.

Hi, I think many of your readers will be interested in the artficial intelligence portion of the series. I was wondering how in-depth you will be discussing in those topics?

How does your bot determine position and number of players? Screen scrape? Previous HH? Action order?

Many have been asking for code to do the types of things mentioned in this article and the previous. There is an opensource poker bot engine/platform available here: http://code.google.com/p/openholdembot/

It very much uses the screen-scraping approach, but with a flexible "table map" external definition file that allows one to define how the screen scraper works with any given casino site, and which does not require binary recompilation. It also uses the SendInput API approach for mouse/keyboard event injection.

Being open source, full source code is available (of course). DLL injection for game state identification and alternative input stream hijacking is on the development agenda, and is just a matter of time. Feel free to stop by and help out.

Awesome articles! Thanks for doing this.

I'm more interested in the techniques you are using, more than I am in actually creating a poker bot to play poker for me. The application of the ideas are definitely beyond poker clients, and having experimented (lightly) with dll injection in the past, it is fun to see real world examples.

As to whether or not this is "bad", or will make poker sites mad... I think most developers that are capable of doing this just needed to hear "download Detours" or "use hooks". But chances are, they knew that already. Those that aren't may find the series interesting from a Win programming point of view, but probably shouldn't go invest a ton of money in their bot bankroll any time soon.

In fact, the number of people that are waiting around to copy and paste code are the comic relief portion of this article. Most will give up because it is too hard, and those that persevere will ultimately lose money trying to run a spectacularly awful bot. If you are an online poker player, you want this.

Personally, I'd love to sit at a table with someone's copy/paste bot. That is, unless their name is Chris Ferguson or Andy Bloch...

I am creating a c# poker interface library for commercial reasons. It will work with all sites, and is not affected by changing poker client graphics.

It allows a full object based system to track whats going on at the table, and has a seperate library for parsing Hand Histories into statistics.

Currently only working under Party-poker - drop me an email at unreal1987@hotmail.com if anyone is interested in beta-testing.

Wow, this is really great work you've got here and kudos on making it available! Can't wait to read the next few posts in your series.

yeah, great article by the way - gives people a head-start who wouldnt normally know where to start.

In terms of AI (I have studies a few different techniques) what would you say would be the most effective? It seems the serious programmers are all fairly confident with their neural networks.

Absolutely intriguing. I'm a poker player and a student of Computer Science, and this is probably the most interesting article I have found online in a long time. Keep up the great work

James, could you please specify what exact methods you hook in order to get the necessary information? Both DrawText and ExtTextOut do not give any information when detoured (only get called when resizing or minimizing the screen). This holds for both pokerstars and everes poker.

thanks james, I really appreciate this!!

An incredibly insightful article on poker bot methodology. Cheers.

I like.

I'm looking at a .NET application, and when I hook DrawTextA/W, DrawTextExA/W, TextOutA/W, ExtTextOutA/W, the string is garbled. Most of the time it is not ASCII. It appears the application is using DirectX. I'm stumped.

Color will win at this hands down. LOL and its all 2d painting, no 3d. I agree with the previous comments your just trying to sell books, everything you posted is known by thousands of people, perhaps post more private info or sources.

runscape he said that in the first article, basically saying that this information is wide spread on the internet. There is just no where that has it all in the same spot. he put it all together in 1 section for people to learn from it. so what if he makes some money on selling some books, he is only doing what he said he would in the first place.

bring all the info to 1 spot instead of it being all over the place and harder to find.

Hmm... I like the article, and there's a link to a book that might be useful to the subject matter. Oh the dilemma... if I click on the link to the book, the author (whose article I like, remember?) might actually get a little bit of an affiliate kick back.

What to do?? After all, I paid good money for this post... oh wait.

Question: You call this a "break-even" bot with rake - but how is it breaking even if there is a 5% rake - that means that it must be making a 5% profit in order to stay in business.. correct?

first off, great article! im also a bot builder and have built several bots myself (although theyre mostly used for my univ. AI research rather than making money) and i find them generally inefficient unless you use learning based AI and opp. modeling as proposed in the univ. alberta papers, or you exploit the fishes at the lo limit tables. but they do work! a simple EV calculating bot can make up to about $10 an hour at the $.10/$0.20 fixed holdem tables.

anyways, id like to add that poker sites DO have bot prevention measures and ive been caught several times despite having randomized click coords/speed (and i mean uniformly distributed randomization, not centered), hidden processes, etc etc. all the things a comp sci nerd can drum up, and i seriously do believe they go over play history and activities manually if your winnings get large so you cant let your guard down even if your bots seem sufficiently stealthy.

heres one i got from pokerstars:

--------------------------snip snip----------------------------- Hello XXX,

We at PokerStars have noticed that recently you have been running a program called a Poker Bot.

Perhaps you were unaware that this was against the rules, or were just curious about the program, but use of this software under any circumstances is against our terms of service. Those terms of service are located here:

http://www.pokerstars.com/poker/room/tos/

Among them are these terms:

5.5. AUTOMATIC PLAYERS (BOTS). The use of artificial intelligence including, without limitation, "robots" is strictly forbidden in connection with the Service. All actions taken in relation to the Service by a User must be executed personally by players through the user interface accessible by use of the Software.

5.6. You agree that PokerStars may take steps to detect and prevent the use of prohibited EPA Programs. These steps may include, but are not limited to, examination of software programs running concurrently with the PokerStars Software on the User's computer.

5.8. FRAUDULENT BEHAVIOR. In the event that PokerStars deems that a User has engaged .... in any of the activities set forth above or any other game manipulation ... PokerStars shall be entitled to take such action as it sees fit, including immediately blocking access to the Service, terminating such User's account with PokerStars, seizing all monies held in the User's PokerStars account...

PokerStars takes its obligation to the integrity of its games seriously, and cannot permit such programs as yours to operate.

We realize that you probably were unaware of the forbidden nature of this program, and therefore we will not take any of the above stern reactions due to this detection. Instead, all we ask is that you reply to this Email stating that you're now aware of the rule against bots, and that you won't use such programs on PokerStars again in the future.

Until we receive such an acknowledgement, we have temporarily suspended your PokerStars account. The account closure isn't intended as punishment nor anything other than to get your attention and to have your acknowledgement of the rules on record. Once you've acknowledged the above rules and agreed to refrain from the use of "bots", we will be pleased to restore your account to good standing.

Please don't protest that you didn't use a bot in your response or otherwise object to this mild warning. Any reply that doesn't include something like "I understand that bots are against the rules and I won't use them on PokerStars" will only delay the re-opening of your account.

Thank you for your cooperation in this matter.

Best Regards,

YYY PokerStars Game Security --------------------------snip snip-----------------------------

bwahaha. anyways, great article, cant wait for the next!

when can we expect the 3rd installment? so far all of have interesting reads and i for one would love to be able to see the next

it should be good

I dodge bullets baby!

this is scary stuff, baby

But can the bot beat the 10/20 at the Bellagio?

if you leave your bot at home, you cannot win, baby

So, in the end, it's just a war between bot builders and the poker site's bot detection software?

That's an awesome set up he's got in the first picture! I want 4 monitors!

I think that in time, if poker bots become more and more common, big sites like PokerStars and PartyPoker will use algorithms to spot the botters from the notters and bust them! (Hopefully). I posted an exert of this article here: http://www.pokerisrigged.com/showthread.php?p=3266#post3266. Hope that's ok with you!

Great work James. When do you expect the next articles to come out? Looking forward to them

Question.... How did you use detours to hook only the DrawText, TextOut, etc... api's for only the pokerstars process and more importantly for certain poker tables as to not get the information confused between tables?

This is probably the most important series of articles I've ever read. Thank you very much for this. (and more, I hope)

When I Hook API functions like DrawTextW, TextOutW, I can find out the Text, DC and Coordinates. But when 2 or more tables are opened, how to determinate in what window that happens. Most programs draw text and images on temporary Bitmap and then bitblt it to the window.

The second part was even more interesting! We used similar techniques for our poker bot, www.icmbot.com, if you want to check it out.

Free demo and download, full version is almost ready to be released.

I enjoyed the article, thanks!

PokerStar uses special (bitmap) fonts for user names and stack sizes. So only functions, that draw text in status window, can be hooked (See fig. James Devlin on 5/26/2008 9:13:00 AM).

Your instructions are lame and your motivation for writing this is so obvious. Most good players I know would love to play against bots.

Its obvious that you're posting controversial information on one of the most controversial and heated topics of online poker, which is extremely popular.

You seek to earn money from your repeated references to amazon.com books with your tagged links, you've got your google ads, and ofcourse you're creating a highly ranked site which you can obviously make a lot of money with.

So you're a hoodinie m#$(*^rf#$^%er. I kind of respect you, but hahahaha its just funny. Well done on your SEO and your plan.

the diagram in the early part of this installment goes beyond mere collusion, it's a roll-your-own superuser.Scary. I was a hardware debug tech in Silicon Valley for 15 years. This stuff looks way too doable [esp. for someone like myself, who has enuf knowledge of C to cause serious injury :)] Currently, there is an input-based offline simulator for Razz [we use this on 2+2 to analyze hand histories]. You punch the numbers in [your holecards, boardcards], it kicks out an estimated win percentage. Whole process takes 20-30 secs., too slow for a bot. However- If the holecard/boardcard data were dumped off to, let's say, a co-processor, perhaps a TI or Analog Devices DSP chip mounted on a PCI extender card... still using all the bot API processes, but with lightning fast simulation for razz/stud hands instead of a holdem lookup table... disregarding expenses [the hardware prototype could be functional for 500-1500$, including sw/reference books], is this a feasible approach?

$pike

P.S. may the the poker gods forgive me for speaking of such blasphemous things! I should not want to be forever cursed in my daily excursions to the triple draw games....

If any of you players or bot writers need hand histories for your stats (PT, HM etc) databases you should head to HandHQ.com.

is it true that when using the a poker bot, you have to get the other players to download it so you can use it against them? just asking.. ive been doing alittle looking around and reasing alot of forums looking for a good bot. i play poker all of the time....... and well.... it takes too long to make any good/real money. what are some suggestions for finding a good bot?

Hi, Tom.

"is it true that when using the a poker bot, you have to get the other players to download it so you can use it against them?" Not true. There are some bots that work that way, but I don't consider them bots but spyware.

"just asking.. ive been doing alittle looking around and reasing alot of forums looking for a good bot. i play poker all of the time....... and well.... it takes too long to make any good/real money. what are some suggestions for finding a good bot?" No good bots out there. When a bot is good, you don't give it to everybody: you keep it secret and make money stealthy.

You should make your own bot, following this series you can if you are a programmer. I have started less than a month ago and I already have a pre-flop bot.

Nice Article

Very interesting stuff.

I used a fairly basic poker bot on FT that I got for free somewhere. Low limits obviously, and it seemed to break even over about twenty hours play. I only ran it to see how it would work, and it didn't make enough on rakeback at those limits to interest me much. I can see the potential here though.

Aside from the main focus of the article on building a poker bot I think you gave some very good extra information on the parallel between a lot of poker clients and spyware, well done for that.

Yes, that info regarding the use of spyware by the poker clients was a bit of an eye opener. In the course of looking at various bots, and calculators, that are commercially available I was surprised at how developed this area of online poker has become. It would seem now that a significant percentage of the players at any table are using some form of software to help their game. Which leaves those of us that aren't using any (yet) at a bit of a disadvantage I think. Is this the future of online poker then?

Just curious...has anyone recently used this against Poker Stars? The API hooks into the chat window no longer work...

Man I sure wish I knew what the heck you're talking about.

I have the same problem, the API hook for PokerStars is not working anymore.

Joop,

Sorry to hear that you are having the same issues.

I noticed that the Stars client no longer uses the custom ActiveX control (i.e. Afx:400000:20). It appears to have been replaced with the control: PokerStarsChatClass.

For Stars, I used to be able to API hook on the user32.dll API (DrawTextW), but this no longer works. However, my API hook on the gdi32.dll API (ExtTextOutW) still works for Full Tilt, so I might have to switch over to that site.

Have tried the following hooks on Stars and "none" of them return information from the latest Stars chat window...assuming I have them coded correctly:

User32.dll

DrawText DrawTextA DrawTextW DrawTextEx DrawTextExA DrawTextExW

GDI32.dll

TextOut TextOutA TextOutW ExtTextOut ExtTextOutA ExtTextOutW PolyTextOut PolyTextOutA PolyTextOutW

If anyone else has any insight or suggestions, they are greatly appreciated!

More information in regards to not being able to capture the text from the Stars Chat window. Dug up a related link issued on December 12, 2008...about the same time I noticed that my API hooks stopped working for Poker Stars.

http://www.pokercalculatorreport.com/Poker-Calculator-Tournament-Strategy/poker-stars-slam-hammer-on-3rd-party-software-industry.html

Hey,

Im trying to make a bot for CDPoker but having the problem trying to obtain the chat window.

its a "internet explorer_server" class window.

Nice job!

We did something similar here: http://www.pokerbot-smart.com/

You should write a book on this. Ever think about the viral marketing effect this could have ? Your posts already have lots of quality information, so you could amalgamate them and create a one of a kind book.

Hey guys, can anyone here tellme how to create a bot for Zynga's Texas Hold'em Poker?

I lost like billions of dollars like that. There are bots available but i cannot afford one, I am just a student. I am not aware of much of computer language but i can get help from my Brother who is a computer designer but he is not sure what i want.

Please reply at broken_89@live.com

Hey guys, can anyone here tellme how to create a bot for Zynga's Texas Hold'em Poker?

Please reply at spilja_vip@live.com

Hack free for pokerstars????link

Since online poker players are playing against each other to win each other's money, pray tell how the site is affected? At the most, maybe in a free roll tournament, if you are lucky. If its a buy-in, you are still taking other player's money, not to mention paying to get in anyway. Tournament fees are already collected by the site separately. So this is not something that makes one smarter by taking a higher moral ground saying bots are taking on the poker sites, just other innocent players? If you refer to Ring Tables, thats again taking other player's money. Unless I missed the very premise of this article?

great post! I have long been a fan of the CPRG's work. i guess the goal is to write the 'middle bit' - or processing bit - in a way that it can deal with scraped input from any number of sources/poker clients, and likewise output something that can be translated by any number of interfaces.

@ erik I wouldnt be suprised at all if they installed spyware to detect known cheats. If you think this isnt possible look at spyware like punkbuster ( Call of duty + a series of other games) Warden in World of warcraft is another example of spyware to stop cheating. As described it can take screenshots look at your running processes and has the capacity to look at basically anything on your PC.

This isnt fiction its fact.

Common guys !No one on this earth will give you a ,,free poker bot" or information how to do it...Even here - the ,,how to make " guide is so difficult that i have the feeling i need to give all my life to make a bot xD Programming?C++ ,mathematic theorems, algorithms bla bla bla , i need to be a professor, genius studding and studding and studding... So,thats just life guys-nothing is free or worthless...

Well, not a whole life. I have needed less than a year to make a bot, and I started by reading this blog. It's not a winner bot yet, and I need to improve its stealth, but it's a start. And, in the meanwhile, it already helps me showing information and advice while I play.

Comments for this post are closed.

Coding the Wheel has appeared on the New York Time's Freakonomics blog, Jeff Atwood's Coding Horror, and the front page of Reddit, Slashdot, Digg.

On Twitter

Thanks for reading!

If you enjoyed this post, consider subscribing to Coding the Wheel by RSS or email. You can also follow us on Twitter and Facebook. And even if you didn't enjoy this post, better subscribe anyway. Keep an eye on us.

Question? Ask us.

About

Poker

Coding the Wheel =
Code, poker, technology, games, design, geekery.


Hire

You've read our technical articles, you've tolerated our rants and raves. Now you can hire us anytime, day or night, for any project large or small.

Learn more

We Like

Speculation, by Edmund Jorgensen.