Python Projects Rating 5 out of 5

Chrome Dino Bot

Chrome Dino Bot May 18, 2021

Intuition: 

  1. Start the game.
  2. Grab the Screenshot.
  3. Get the colors just after the dino.
  4. If the color is not white, Jump.

Note: Turn off other applications or start the  python file just after starting your game so alt+tab switch the main window to the game. Install PIL module by command-

pip install pillow
from time import sleep
from PIL import ImageGrab
import keyboard

keyboard.press_and_release('alt+tab')
sleep(0.5)
keyboard.press_and_release('space')
i = 0
img = ImageGrab.grab().convert('L')
x1 = int(0.21*img.size[0])
y1 = int(0.54*img.size[1])
while(not keyboard.is_pressed('q')):
    i+=1
    x = [x1,x1+50]
    y = [y1,y1+100]
    if(i%100):
        x[0]+=5
    img = ImageGrab.grab().convert('L')
    a = img.load()
    flag = 0
    for i in range(x[0],x[1]):
        for j in range(y[0],y[1]):
            if(a[i,j]!=255):                                                            
                keyboard.press_and_release('space')
                flag = 1
                break
        if(flag): break

Rate this post

Comments