Version 1.3
Multithreading added. Sleep on playing has been removed. Efficiency highly increased. Lumberjack no longer gets hit.
This commit is contained in:
parent
7487c3455b
commit
a815dc4b16
1 changed files with 41 additions and 40 deletions
|
@ -1,6 +1,7 @@
|
||||||
import pyautogui
|
import pyautogui
|
||||||
import time
|
import time
|
||||||
from ctypes import windll
|
from ctypes import windll
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
class lumberjackBot():
|
class lumberjackBot():
|
||||||
|
@ -12,6 +13,13 @@ class lumberjackBot():
|
||||||
self.playY = playY
|
self.playY = playY
|
||||||
self.treeX = treeX
|
self.treeX = treeX
|
||||||
self.treeY = treeY
|
self.treeY = treeY
|
||||||
|
# Those attributes has been placed here in order to save calcs:
|
||||||
|
self.pixelL = (0,0,0) # Left side branch color
|
||||||
|
self.pixelR = (0,0,0) # Right side branch color
|
||||||
|
self.lX = treeX - 30 # Left side branch X location
|
||||||
|
self.rX = treeX + 30 # Right side branch X location
|
||||||
|
self.y = treeY - 130 # Both side branch Y location
|
||||||
|
|
||||||
|
|
||||||
def move(self, direction):
|
def move(self, direction):
|
||||||
if direction == "left":
|
if direction == "left":
|
||||||
|
@ -27,49 +35,42 @@ class lumberjackBot():
|
||||||
b = (rgb >> 16) & 0xff
|
b = (rgb >> 16) & 0xff
|
||||||
return r,g,b
|
return r,g,b
|
||||||
|
|
||||||
|
def get_pixel(self, x, y, side): # Modify class atribute
|
||||||
|
screen = windll.user32.GetDC(0)
|
||||||
|
rgb = windll.gdi32.GetPixel(screen, x, y)
|
||||||
|
if side == 'L':
|
||||||
|
self.pixelL = self.get_color(rgb)
|
||||||
|
elif side == 'R':
|
||||||
|
self.pixelR = self.get_color(rgb)
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
cont = 0
|
self.move("right")
|
||||||
while(1):
|
while True:
|
||||||
end = windll.user32.GetDC(0)
|
if self.pixelL == (161, 116, 56): # or self.pixelL == (153, 110, 54):
|
||||||
rgb = windll.gdi32.GetPixel(end, treeX - 30, treeY - 130)
|
self.move("right")
|
||||||
stop = windll.gdi32.GetPixel(end, treeX - 30, treeY - 100)
|
elif self.pixelR == (161, 116, 56): # or self.pixelR == (153, 110, 54):
|
||||||
print(str(self.get_color(rgb)))
|
self.move("left")
|
||||||
if self.get_color(rgb) == (161, 116, 56) or self.get_color(rgb) == (153, 110, 54):
|
|
||||||
pyautogui.typewrite(['right'])
|
def pixelThreadL(self):
|
||||||
pyautogui.typewrite(['right'])
|
while True:
|
||||||
elif self.get_color(rgb) != (161, 116, 56) and self.get_color(rgb) != (153, 110, 54):
|
self.get_pixel(self.lX, self.y, 'L')
|
||||||
pyautogui.typewrite(['left'])
|
|
||||||
pyautogui.typewrite(['left'])
|
def pixelThreadR(self):
|
||||||
cont += 2
|
while True:
|
||||||
if self.get_color(stop) == (255,255,255) or cont >= 420:
|
self.get_pixel(self.rX, self.y, 'R')
|
||||||
return 0
|
|
||||||
time.sleep(0.075) # Speed of lumberjack
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# LUMBERJACK WINDOWS MUST BE CLEAR
|
|
||||||
playX, playY = pyautogui.locateCenterOnScreen('playButton.png')
|
playX, playY = pyautogui.locateCenterOnScreen('playButton.png')
|
||||||
pyautogui.moveTo(playX, playY) # Start the game by pressing play button
|
pyautogui.moveTo(playX, playY)
|
||||||
pyautogui.click()
|
pyautogui.click() # Start the game by pressing play button
|
||||||
time.sleep(1)
|
time.sleep(0.5) # Wait for screen refresh
|
||||||
treeX, treeY = pyautogui.locateCenterOnScreen('tree.png') # Recognize tree position
|
treeX, treeY = pyautogui.locateCenterOnScreen('tree.png') # Recognize tree position
|
||||||
time.sleep(1)
|
time.sleep(0.3)
|
||||||
print("Im playing...")
|
print("Im playing... To stop me click on IDLE and press CTRL+F6.")
|
||||||
lumberjackBot(playX, playY, treeX, treeY).play()
|
lumberjack = lumberjackBot(playX, playY, treeX, treeY)
|
||||||
|
t1 = threading.Thread(target = lumberjack.pixelThreadL, args = ())
|
||||||
|
t2 = threading.Thread(target = lumberjack.pixelThreadR, args = ())
|
||||||
|
t1.start()
|
||||||
|
t2.start()
|
||||||
''' SCORE:
|
lumberjack.play() # Game start
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
Loading…
Reference in a new issue