Skip to content

felixschwebel/GoogleDinosaurGameBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoogleDinosaurGameBot

A project using the selenium web driver and the Python Imaging Library PIL Fork Pillow.

Current HIGH SCORE: 2234

Screenshot 2023-03-19 at 14 25 28

To use the code you have to use the web driver for Chrome because the game is launched directly from the Chrome browser.

Run python3 main.py

Screenshot 2022-12-02 at 21 44 24

I decided to use a class for the GameBot to I could specify some methods for the bot. In the init-function the web driver is started. Unfortunately an error occurs after the game is launched, I assume because the URL doesn't refer to a real web address. That's why I used the exception handling to continue after the WebDriverException is raised. The game is started by pressing the space bar. Then it waits for 4 seconds using the time module before the bot starts.

Screenshot 2022-12-02 at 21 53 43

I used the ImageGrab from PIL to grab a little piece of the screen right above the ground but just as high that it doesn’t detect the high-flying birds. The values that I got came from trying. To see if there’s an obstacle the colors of the snippet are checked for dark grey (172, 172, 172).

Screenshot 2022-12-02 at 21 58 05

When an obstacle is detected the jump function is triggered. I decided to not use the ducking functionality because I would have to check for the lower ground and the middle ground separately. This would slow down the checking process and the reaction time of the Dino. I just used the ARROW-DOWN to get the Dino faster back on the ground. Because the speed of the game is changing with time, this switched from a 0.19 s wait to a 0.16 s wait after 50 seconds.

Screenshot 2022-12-02 at 22 02 51

At this stage, the automation is far from perfect, but the basic functionality - detecting an obstacle and reacting to it - is implemented. To improve the GameBot in the future the values of the detection box xmax, width, ymax, height and the time before the ARROW_DOWN Key is sent, would have to be fine-tuned and changed over time. For now, the Dino only reaches scores of around 400 to 500 consistently.

About

An automation of the Google Dinosaur Game.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages