HOME

II - Reading the screen


Different techniques

The first problem when constructing a bot is getting the input. This can be done in different ways.
Here we will describe how to read the information directly of the screen. This technique is easy to implement for any type of bot and will not limit it to only reading HTML-code.
What I mean by read is that they scan different pixels on the screen and let algorithms decide how to interpret the meaning of their RGB-value.
Using Java this can be done with the java.awt.Robot library.




Finding an object

Knowing what to scan is not the difficult part. Programming the functions that retrieve this data is. This is probably the most time consuming part of creating a poker bot.
To find objects that can be located at different positions on the screen you need to use some type of scanning algorithm. This can be done by searching the screen for a distinct set of pixels that are unique for the object you are looking for.
One way of doing this is to scan the screen pixel by pixel from top to bottom, column by column. When the series of unique pixels appear you have found your object.
Depicted in the figure below is a selection of three pixels that uniquely describes the example object on the screen.

If objects are placed at specific distances from each other that do not change, it will save computing time to only search for one object and then use this as a reference point for the others.



Identifying an object


Sometimes different objcts will appear at a specific position, which you will want to identify. If you have a limited number of differnet objects (for instance playing card suites, 4) you can determine which one it is by reading different pixels.
The pseudo-code below illustrates how this is possible.


...
var card;
var pix;

pix = getpix(263, 217);

if (pix == black)
card = SpadesOrClubs;
else
card = HeartsOrDiamonds;
...



Using this technique systematically you can identify almost anything displayed on the screen.


A smart way of reading numbers or letters is to sum the number of occurrences of the specific colour by columns. (see image below)



This gives different numbers an unique ID that is easy to isolate in an if-statement.




Preparing for changes in graphics

This method of gathering input leads to a problem. The software that your bot will interact with is seldom constant. It will most likely be updated or changed in different ways in the future. It is very good to be aware of this already when you start programming. The best way to deal with this problem is just to use smart object oriented programming. Try to make the different scanning functions as easy to modify as possible.

It would be clever to implement a control function that continously checks a number of pixels to detect changes in graphics, so that you can avoid that your bot runs wild.




Rev. 3 (11 Jan. -09)





<<<Chapter IChapter III>>>