From f043a0f1407916d3c90e6c88845a00cb6049ba07 Mon Sep 17 00:00:00 2001 From: Enrique Moran Date: Tue, 6 Dec 2016 17:46:29 +0100 Subject: [PATCH] Version 1.0 Score record: 367 --- lumberjackBot.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lumberjackBot.py diff --git a/lumberjackBot.py b/lumberjackBot.py new file mode 100644 index 0000000..dd610f9 --- /dev/null +++ b/lumberjackBot.py @@ -0,0 +1,44 @@ +import pyautogui +import time + + +class lumberjackBot(): + + __author__ = "EnriqueMoran" + + def __init__(self, playX, playY, playerX, playerY): + self.playX = playX + self.playY = playY + self.playerX = playerX + self.playerY = playerY + + def move(self, direction): + if direction == "left": + pyautogui.typewrite(['left']) + pyautogui.typewrite(['left']) + elif direction == "right": + pyautogui.typewrite(['right']) + pyautogui.typewrite(['right']) + + def play(self): + while(1): + branch = pyautogui.screenshot(region=(playerX, playerY - 85, 1, 1)) # Pixel of tree right side + obstacle = branch.getpixel((0,0)) + if obstacle == (161, 116, 56): + self.move("left") + else: + self.move("right") + time.sleep(0.09) # Speed of lumberman + + + +if __name__ == "__main__": + # 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) + playerX, playerY = pyautogui.locateCenterOnScreen('player.png') # Recognize position of player + time.sleep(1) + print("Im playing... To stop me click on IDLE window and press ctrl + C") + lumberjackBot(playX, playY, playerX, playerY).play()