lumberjackBot/lumberjackBot.py

75 lines
2.2 KiB
Python
Raw Normal View History

2016-12-07 00:46:29 +08:00
import pyautogui
import time
2016-12-12 23:44:03 +08:00
from ctypes import windll
2016-12-07 00:46:29 +08:00
class lumberjackBot():
2016-12-08 23:12:27 +08:00
__author__ = "EnriqueMoran"
def __init__(self, playX, playY, treeX, treeY):
self.playX = playX
self.playY = playY
self.treeX = treeX
self.treeY = treeY
def move(self, direction):
if direction == "left":
pyautogui.typewrite(['left'])
pyautogui.typewrite(['left'])
elif direction == "right":
pyautogui.typewrite(['right'])
pyautogui.typewrite(['right'])
2016-12-12 23:44:03 +08:00
def get_color(self, rgb):
r = rgb & 0xff
g = (rgb >> 8) & 0xff
b = (rgb >> 16) & 0xff
return r,g,b
2016-12-08 23:12:27 +08:00
def play(self):
2016-12-12 23:44:03 +08:00
cont = 0
while(1):
end = windll.user32.GetDC(0)
rgb = windll.gdi32.GetPixel(end, treeX - 30, treeY - 130)
stop = windll.gdi32.GetPixel(end, treeX - 30, treeY - 100)
print(str(self.get_color(rgb)))
if self.get_color(rgb) == (161, 116, 56) or self.get_color(rgb) == (153, 110, 54):
pyautogui.typewrite(['right'])
pyautogui.typewrite(['right'])
elif self.get_color(rgb) != (161, 116, 56) and self.get_color(rgb) != (153, 110, 54):
pyautogui.typewrite(['left'])
pyautogui.typewrite(['left'])
cont += 2
if self.get_color(stop) == (255,255,255) or cont >= 420:
2016-12-08 23:12:27 +08:00
return 0
2016-12-12 23:44:03 +08:00
time.sleep(0.075) # Speed of lumberjack
2016-12-07 00:46:29 +08:00
if __name__ == "__main__":
2016-12-08 23:12:27 +08:00
# LUMBERJACK WINDOWS MUST BE CLEAR
playX, playY = pyautogui.locateCenterOnScreen('playButton.png')
pyautogui.moveTo(playX, playY) # Start the game by pressing play button
pyautogui.click()
time.sleep(1)
treeX, treeY = pyautogui.locateCenterOnScreen('tree.png') # Recognize tree position
time.sleep(1)
print("Im playing...")
lumberjackBot(playX, playY, treeX, treeY).play()
''' SCORE:
2016-12-12 23:44:03 +08:00
0.15 -> 254, 254, 256
0.12 -> 278X, 288, 42, 314, 314
0.11 -> 314, 314, 314
0.1 -> 334, 334, 144X, 334, 334
0.099 -> 334, 334, 334
0.08 -> 354, 354, 352
0.075 -> 116X, 28X, 84X, 122X
0.07 -> 70X, 250X, 104X, 8X, 34X
2016-12-08 23:12:27 +08:00
'''