# 5: Chrom Dino Game Bot(Robot play game )

 Chrome Dino game Bot Automation with Python

This project is a very interesting python project in this project I have made a bot that plays the dino game in the chrome infinitely long I want. This bot will play this game without getting out and it cannot stop playing till we stop the programme so this project is awesome and interesting python project.This project is done by using some library of python like pyautogui and python image library (PIL) etc.

The logic behind the project?
The logic of this programme is written in such a way that every fraction of seconds it is taking a screenshot of window and convert it in black and white. And there is rectangle drawn in the screen in the way of cactus and birds in the game which is not visible to you. Initially, the color of the window in the rectangle is white but when cactus or bird come, due to their black color the color of the rectangle will also become black and Tthe program is written in such a way that if the color in the rectangle becomes black then press jump so that dino can jump and save from getting out.
The result is that Whenever color inside the rectangle becomes black due to collision with birds and cactus the dino will jump.

Sample video of how the bot play the game itself so please watch the video till end.


Code For the Program
***********************************
import pyautogui
from PIL import Image, ImageGrab
import time
def hit(key):
pyautogui.keyDown(key)
def iscollide(data):

#for birds
for i in range(668,678):
for j in range(240,267):
if data[i,j] < 10:
hit('down')
return
#for cactus
for i in range(688,800):
for j in range(287,328):
if data[i,j] < 100:
hit('up')
return
return

if __name__ == "__main__":

time.sleep(2)
while True:
Image = ImageGrab.grab().convert('L')
data = Image.load()
iscollide(data)


***********************************

Comments

Popular posts from this blog

#6 Snake Game using Python (with gameplay)