I'm trying to make a bot which plays "Don't tap the white tile". The code I have so far works just fine, but it's a bit slow and as the game speeds up the bot fails.
Right now I'm grabbing 4 images using PIL's ImageGrab.grab()
:
image_r = ImageGrab.grab(bbox=(160, 500, 180, 900))
image_cr = ImageGrab.grab(bbox=(600, 500, 620, 900))
image_cl = ImageGrab.grab(bbox=(1020, 500, 1040, 900))
image_l = ImageGrab.grab(bbox=(1440, 500, 1460, 900))
image_r ⇒ right image
image_cr ⇒ center right image
image_cl ⇒ center left image
image_l ⇒ left image
Below you can see the game with boxes indicating the images (approximately)
Then for each one, I check for black pixels with:
def get_black_px(image,x):
for y in range(image.size[1]-5, 5, -10):
R , G, B = image.getpixel((x,y))
if R < 40 or G < 40 or B < 40:
R, G, B = image.getpixel((x, y+2)) #this is done since the lines
if R < 40 or G < 40 or B < 40: #between the tiles are also black
return y
If this detects a tile, the mouse is moved there and clicked
if get_black_px(image_r, 10) != None:
Mouse.position = (170, get_black_px(image_r, 10)+500)
Mouse.click(Button.right, 1)
elif get_black_px(image_cr, 10) != None:
Mouse.position = (610, get_black_px(image_cr, 10)+500)
Mouse.click(Button.right, 1)
elif get_black_px(image_cl, 10) != None:
Mouse.position = (1030, get_black_px(image_cl, 10)+500)
Mouse.click(Button.right, 1)
elif get_black_px(image_l, 10) != None:
Mouse.position = (1440, get_black_px(image_l, 10)+500)
Mouse.click(Button.right, 1)
As I said before, this works but even when the game is slow it clicks at the middle of the tiles and not the bottom. So if you know of a faster way to do this or see a mistake or something please let me know.
Edit: added picture