An automated bot that plays the Chrome dinosaur game by detecting obstacles and jumping over them using image processing and screen analysis.
The Chrome Dino Bot is an automation script that plays the popular Chrome dinosaur game that appears when you have no internet connection. The bot uses image processing techniques to detect obstacles in the game and automatically jumps over them by pressing the space key.
As the game progresses and the speed increases, the bot dynamically adjusts its detection area to look further ahead, ensuring it can react to obstacles in time.
The bot is implemented in Python and uses several libraries for screen capture and control:
import time
import pyautogui
from PIL import ImageGrab
# Constants
START_COORDS = (260, 445)
END_COORDS = (280, 500)
TARGET_COLOR = (172, 172, 172)
JUMP_DELAY = 0.0
def is_target_color_present():
# Capture screen within the specified coordinates range
screenshot = ImageGrab.grab(bbox=(START_COORDS[0], START_COORDS[1], END_COORDS[0], END_COORDS[1]))
pixels = screenshot.load()
# Check if any pixel matches the target color
for x in range(screenshot.width):
for y in range(screenshot.height):
if pixels[x, y] == TARGET_COLOR:
return True
return False
def jump():
for _ in range(3):
pyautogui.press('space')
time.sleep(0.01)
# Delay before starting the bot (gives time to focus on the game)
time.sleep(4)
start_time = time.time()
while True:
if is_target_color_present():
jump()
# Check if 8 seconds have passed - adjust detection area
if time.time() - start_time >= 8:
if START_COORDS[0] < 300:
# Increment the x-coordinate of START_COORDS and END_COORDS by 8
START_COORDS = (START_COORDS[0] + 8, START_COORDS[1])
END_COORDS = (END_COORDS[0] + 8, END_COORDS[1])
elif 300 < START_COORDS[0] < 400:
# Increment the x-coordinate by 25 (look further ahead)
START_COORDS = (START_COORDS[0] + 25, START_COORDS[1])
END_COORDS = (END_COORDS[0] + 25, END_COORDS[1])
else:
START_COORDS = (START_COORDS[0] + 15, START_COORDS[1])
END_COORDS = (END_COORDS[0] + 15, END_COORDS[1])
start_time = time.time()
print("Updated")
print(START_COORDS)
print(END_COORDS)
# Adjust the delay between each iteration if needed
time.sleep(JUMP_DELAY)
The development of this bot involved several key steps:
The Chrome Dino Bot successfully automates gameplay and can achieve high scores beyond what most human players can manage. The bot demonstrates how simple image processing techniques can be used to create effective game automation systems. It serves as an educational tool to understand basic principles of computer vision and automation.