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
1 changed files with 31 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import pyautogui
import time
from ctypes import windll
class lumberjackBot():
@ -20,19 +21,30 @@ class lumberjackBot():
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):
while(1):
branch = pyautogui.screenshot(region=(treeX - 30, treeY - 130, 1, 1)) # Pixel of tree left side
obstacle = branch.getpixel((0,0))
end = pyautogui.screenshot(region=(treeX - 30, treeY - 100, 1, 1))
stop = end.getpixel((0,0))
if obstacle == (161, 116, 56):
self.move("right")
else:
self.move("left")
time.sleep(0.1) # Speed of lumberjack
if stop == (255,255,255):
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:
return 0
time.sleep(0.075) # Speed of lumberjack
if __name__ == "__main__":
@ -51,12 +63,13 @@ if __name__ == "__main__":
''' SCORE:
0.15 -> 180, 188, 180
0.12 -> 246, 204, 72X, 222
0.11 -> 218X, 128X, 62X, 232, 6X
0.1 -> 12X, 84X, 16X, 6X, 28X
0.099 -> 164X, 108X, 114X
0.08 -> 24X, 34X, 6X, 4X, 24X
0.07 -> 4X, 8X, 2X
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
'''