Welcome to a C# development series about creating a poker bot to compete against players online for play money. This will be partly an experimental post, trying different techniques to make the bot's AI, as well as an instructional series showing different snippits of Code Iv'e put together to make the bot work.
The first thing I've decided to start with is to setup how the bot can determine which cards are in play. This seems like a logical place to start because a bot playing blind wouln't be too great :P This can be done by searching through a library of 52 bitmaps of each card
to see which exists within a certain area of the game screen. These bitmaps were obtained by manually taking screenshots of multiple games in a PartyPoker table, I've attached them here so you don't have to go through the work:
52CardBitmaps.zip
Here's a bit of code to take a screenshot of the current game screen. I was using PokerStars in this example, but you could pretty much do the same for any game:

52CardBitmaps.zip
Here's a bit of code to take a screenshot of the current game screen. I was using PokerStars in this example, but you could pretty much do the same for any game:
using System.Diagnostics; using System.Runtime.InteropServices; private class User32 { [StructLayout(LayoutKind.Sequential)] public struct Rect { public int left; public int top; public int right; public int bottom; } [DllImport("user32.dll")] public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect); [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); } public Bitmap CaptureApplication(string procName) { var proc = Process.GetProcessesByName(procName)[0]; var rect = new User32.Rect(); User32.GetWindowRect(proc.MainWindowHandle, ref rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bmp); User32.SetForegroundWindow(proc.MainWindowHandle); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); return bmp; }
I started with this function that captures a screenshot of a windows application and returns it as a Bitmap. This code basically gets the height, width, and location of the Pokerstars window and captures that area of the screen using Windows CopyFromScreen() method. the process name string that you need can be found in task manager:
So to call the CaptureApplication for the PokerStars Process method the code would be:
CaptureApplication("PokerStars")To test whether its working properly you can make a quick Form with a PictureBox and a button. In the buttons Click event code put this:
private void button1_Click(object sender, EventArgs e) { Bitmap PokerStarsWindow = CaptureApplication("PokerStars"); pictureBox1.Width = PokerStarsWindow.Width; pictureBox1.Height = PokerStarsWindow.Height; pictureBox1.BackgroundImage = PokerStarsWindow; }
With the PokerStars window open, if you click the button you should see a live screenshot of the pokerstars window come up in your application like this:
Good start! Next time we will narrow down the windows in which the program is searching for cards, and show how to make a function that tells whether a smaller bitmap is contained in a larger bitmap for card identification.
Any comments are appriciated!
I want to know, can take a picture of the form 2? thanks you!
ReplyDeletevery good tutorial;)
ReplyDeleteExtra focuses if website additionally offers great program based, no download online poker diversion. qqpokeronline
ReplyDeleteTechnically, a pillow and a calculator can be a tool for online poker.bitcoin betting More poker tools are to be used before, during or after the match.
ReplyDelete