What would you see in the Chrome browser when there is no internet connection? Yes, everyone knows that dinosaur game that appears on the screen. So, in this article, we are going to create a simple python bot that will play the Chrome Dino Game without user intervention. We are not using any machine learning or artificial intelligence here to counter this problem, but we will use simple image / screen processing.

We will be working with Pyautogui
and PIL
(Python Imaging Library) for implementation. This project is very simple and only contains about 50 lines of code, but the result will surprise you.
Some libraries used:
- PIL : Python Imaging Library (PIL) — is a free library for the Python programming language that adds support for opening, manipulating and saving many different image file formats.
- Pyautogui: PyAutoGUI — is a Python module for programmatically controlling mouse and keyboard without any user intervention.
- Time: Python "Time" A module that allows us to perform various operations related to time, its transformations and the views that find its application in various applications in life.
- Numpy: NumPy — is a library for the Python programming language that adds support for large multidimensional arrays and matrices, as well as a large collection of high-level math functions for working with these arrays.
Algorithm —
- Click the reload button using the Pyautogui library using the coordinates "replaybutton".
- Calculate the sum of all white pixel values present in the field in front of the Dinosaur.
- If the sum of the pixel values present at any time in the field becomes less than the sum of the white pixel values, it means that a "bush" or "bird" is coming. So either we have to make our Dinosaur jump or bend over.
- To protect Dino from the Bush, we take a jump.
- To protect Dino from the Bird, we always suppress Dinosaur.
Below is the Python implementation —
< code class = "keyword"> while |
Output:
Improvements: Over time, Dino Bot gets faster. Birds and bushes begin to arrive very quickly. Thus, we do not force our Bot to learn all this, changing its speed based on past learning. Thus, our bot will run around 2000 points. To score more points, we must apply machine learning and artificial intelligence.