Skip to content

Instantly share code, notes, and snippets.

@luminousmen
Last active April 23, 2020 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luminousmen/09dec2e88048d8128a3ad3ebd33c72b2 to your computer and use it in GitHub Desktop.
Save luminousmen/09dec2e88048d8128a3ad3ebd33c72b2 to your computer and use it in GitHub Desktop.
T-Rex dino game script that will play for you, successfully
import numpy as np
import cv2
from mss import mss
import pyautogui as pg
# Please put here you location of t-rex, I used `$ xdotool getmouselocation` for that
MONITOR = {"top": 247, "left": 566, "width": 70, "height": 35}
def process_image(img):
"""Processing image using canny edge detection algorithm
:param img: original image
:returns: processed image
"""
processed_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
processed_image = cv2.Canny(processed_image, threshold1=200, threshold2=300)
return processed_image
def main():
while True:
with mss() as sct:
img = sct.grab(MONITOR)
img = np.array(img)
processed_image = process_image(img)
mean = np.mean(processed_image)
# maybe there is barrier ahead
if not mean == float(0):
pg.press("space")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment