As part of a course I’m on, one of the tasks is to make a program that automatically plays the google dino game. I have tried to check if the pixels are white or not in certain areas of each screenshot that is taken regularly, if they are not white I know there is an obstacle so I want the player to jump by pressing space.
However, the dinosaur only sometimes detects an object and jumps.
How can I get the program to detect the obstacles more consistently?
I’ve tried checking more pixels and have changed the values many times.
import pyautogui
import time
while True:
im = pyautogui.screenshot()
get colour of screen background
screen = im.getpixel((300, 300))
x1 = im.getpixel((1400, 627))
x2 = im.getpixel((1420, 627))
x3 = im.getpixel((1440, 627))
x4 = im.getpixel((1460, 627))
if screen[0] == 247:
if x1[0] != 247 or x2[0] != 247 or x3[0] != 247 or x4[0] != 247:
pyautogui.press("space")
time.sleep(0.0001)
Lemon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.