Making Google's Dinosaur Bot (PYTHON)|| Part 2 || How to make a bot for any game in Python

The PC Geek · 143K views · 2017 · 7:42

Open on YouTube

Python, Ruby & scripting languagesGame programming & enginestutorialdated

Why Stack Overflow recommends it

Stack Overflow users cite it as the tutorial they followed when their copied dino-bot code fails with errors like an unreachable main function or a name clash on ImageGrab.

Recommended by 0 people across 0 different months, 2018 to 2020.

What it is

A short Python tutorial from The PC Geek, part 2 of a series on building an automatic player bot for Chrome's offline dinosaur game. It uses PIL screen grabs, pyautogui key presses and numpy pixel sums, and the author says the same technique works for bots in other games.

What people said

Cites user9611261 · 2018-05 · Stack Overflow · on “Game bot error (python chrome dinousor game error)”

I followed a tut Click me! [this video] and i get un-expected results: my code from PIL import ImageGrab, ImageOps import pyautogui import time from numpy import * class Cordinates(): replayBtn = (960,355) dinosaur = (784,375) #770x360, 770x365 def restartGame(): pyautogui.click(Cordinates.replayBtn) def pressSpace(): pyautogui.keyDown('space') time.sleep(0.05) print("Jump") pyautogui.keyUp('space') def imageGrab(): box = (Cordinates.dinosaur[0]+435, Cordinates.dinosaur[1]+25, Cordinates.dinosaur[1]+335, 10) image = ImageGrab.grab(box) grayImage = ImageOps.grayscale(image) a = array(grayImage.getcolors()) return a.sum() def main(): restartGame() while True: if imageGrab()!=1447: #pressSpace() pri

Cites Forge Ahead · 2019-06 · Stack Overflow · on “How to Fix: Main function is Unreachable - Python 3.5”

I'm trying to make a dead-simple bot according to this video: [this video] The main function that is supposed to be called when a part of the screen changes color simply is not being run at all. I've tried ending the program with "main()" and "if __name__ == '__main__': main()" respectively. Neither have allowed the code to run def restart_game(): time.sleep(1) pyautogui.click(Coordinates.replayBtn) def image_grab(): box = (290, 465, 305, 487) image = image_grab_lib.grab(box) grey = ImageOps.grayscale(image) a = array(grey.getcolors()) print(a.sum()) return a.sum() def main(): restart_game() print("blip") if image_grab() != 577: print("Jump") press_space() time.sleep(1) restart_game() if __name__

Cites Kyuujin · 2020-05 · Stack Overflow · on “'function' object has no attribute 'grab'”

I was searching how to make a basic bot on games and I found this video, however the video doesn't explain well and i've got a problem no one had. The video : [this video] my problem : enter image description here [LINK] from PIL import ImageGrab, ImageOps import pyautogui, time from numpy import * class cordinates(): replaybtn = (480,375) dino = (378,245) obstacle = (300,395) def restartgame(): pyautogui.click(cordinates.replaybtn) def pressspace(): pyautogui.keyDown("space") time.sleep(0.05) print('jump') pyautogui.keyUp('space') def ImageGrab(): box = (cordinates.dino[0]+78,cordinates.dino[1],cordinates.dino[0]+100,cordinates.dino[1]+30) image = ImageGrab.grab(box) grayimage = ImageOps.graysca