Version 1.2

New library
This commit is contained in:
Enrique Moran 2016-12-12 16:44:03 +01:00 committed by GitHub
parent 1e6816da3f
commit 7487c3455b

View file

@ -1,5 +1,6 @@
import pyautogui import pyautogui
import time import time
from ctypes import windll
class lumberjackBot(): class lumberjackBot():
@ -20,19 +21,30 @@ class lumberjackBot():
pyautogui.typewrite(['right']) pyautogui.typewrite(['right'])
pyautogui.typewrite(['right']) pyautogui.typewrite(['right'])
def get_color(self, rgb):
r = rgb & 0xff
g = (rgb >> 8) & 0xff
b = (rgb >> 16) & 0xff
return r,g,b
def play(self): def play(self):
while(1): cont = 0
branch = pyautogui.screenshot(region=(treeX - 30, treeY - 130, 1, 1)) # Pixel of tree left side while(1):
obstacle = branch.getpixel((0,0)) end = windll.user32.GetDC(0)
end = pyautogui.screenshot(region=(treeX - 30, treeY - 100, 1, 1)) rgb = windll.gdi32.GetPixel(end, treeX - 30, treeY - 130)
stop = end.getpixel((0,0)) stop = windll.gdi32.GetPixel(end, treeX - 30, treeY - 100)
if obstacle == (161, 116, 56): print(str(self.get_color(rgb)))
self.move("right") if self.get_color(rgb) == (161, 116, 56) or self.get_color(rgb) == (153, 110, 54):
else: pyautogui.typewrite(['right'])
self.move("left") pyautogui.typewrite(['right'])
time.sleep(0.1) # Speed of lumberjack elif self.get_color(rgb) != (161, 116, 56) and self.get_color(rgb) != (153, 110, 54):
if stop == (255,255,255): pyautogui.typewrite(['left'])
pyautogui.typewrite(['left'])
cont += 2
if self.get_color(stop) == (255,255,255) or cont >= 420:
return 0 return 0
time.sleep(0.075) # Speed of lumberjack
if __name__ == "__main__": if __name__ == "__main__":
@ -51,12 +63,13 @@ if __name__ == "__main__":
''' SCORE: ''' SCORE:
0.15 -> 180, 188, 180 0.15 -> 254, 254, 256
0.12 -> 246, 204, 72X, 222 0.12 -> 278X, 288, 42, 314, 314
0.11 -> 218X, 128X, 62X, 232, 6X 0.11 -> 314, 314, 314
0.1 -> 12X, 84X, 16X, 6X, 28X 0.1 -> 334, 334, 144X, 334, 334
0.099 -> 164X, 108X, 114X 0.099 -> 334, 334, 334
0.08 -> 24X, 34X, 6X, 4X, 24X 0.08 -> 354, 354, 352
0.07 -> 4X, 8X, 2X 0.075 -> 116X, 28X, 84X, 122X
0.07 -> 70X, 250X, 104X, 8X, 34X
''' '''