Created
February 17, 2019 14:54
-
-
Save joaovarelas/73471d547d958d6d9aa97dc5f02c7e3b to your computer and use it in GitHub Desktop.
Lumberjack Bot for Telegram game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from mss import mss | |
from PIL import Image | |
import pyautogui | |
import time | |
import math | |
# google chrome fullscreen | |
# 1366x768, web.telegram.org | |
coords = {'top': 287, 'left': 580, 'width': 200, 'height': 50} | |
#brown | |
branch_color = [67, 116, 162] | |
play_right = True | |
sct = mss() | |
i = 0 | |
while True: | |
sct.get_pixels(coords) | |
RGB_img = Image.frombytes("RGB", (sct.width, sct.height), sct.image) | |
#RGB_img = pyautogui.screenshot() | |
img = np.array(cv2.cvtColor(np.array(RGB_img), cv2.COLOR_BGR2RGB)) | |
# branch pixel | |
left = img[1, 50] | |
right = img[1, 150] | |
branch = right if play_right else left | |
if np.array_equal(branch, branch_color): | |
if play_right: | |
pyautogui.press('left') | |
play_right = False | |
else: | |
pyautogui.press('right') | |
play_right = True | |
if play_right: | |
pyautogui.press('right') | |
else: | |
pyautogui.press('left') | |
i += 1 | |
#time.sleep(math.exp(-i*(1/10))) | |
time.sleep(0.051) | |
cv2.imshow('lumberjack', img ) | |
if cv2.waitKey(25) & 0xFF == ord('q'): | |
cv2.destroyAllWindows() | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment