Skip to content

Instantly share code, notes, and snippets.

Created October 11, 2016 13:41
Show Gist options
  • Save anonymous/132ac709545550497198de7e1a2ef8c8 to your computer and use it in GitHub Desktop.
Save anonymous/132ac709545550497198de7e1a2ef8c8 to your computer and use it in GitHub Desktop.
#lumberbot.py - plays Lumberjack Telegram game hopefully
#Every time you use Python 2, Guido Van Opossum introduces a new bug into Dropbox
#Tested on Windows on 3.5.2
import pyautogui
#import autopy
#autopy doesn't seem to install now which is unfortunate
import random
import time
import sys
def treechk(TREECOL, STATE):
print("Checking for tree")
#see if there's a tree
#Change these according to what you find in PDN or else calculate them offset from the hat
print("State is ", STATE)
if STATE == 2:
treepos = [801, 1051]
else:
treepos = [801, 931]
#pyautogui.moveTo(treepos[1], treepos[0])
if pyautogui.pixel(treepos[1], treepos[0]) == TREECOL:
#There's a tree
print("There's a tree")
return True
else:
print("There's no tree")
return False
def stateswitch(STATE):
print("Swapping sides")
if STATE == 1:
#Move him to the right
pyautogui.press("right")
print("Changing to 2")
return 2
if STATE == 2:
print("Changing to 1")
pyautogui.press("left")
return 1
def goalong(STATE):
#Keep moving in accordance with the current state
#State 1 means on the left and to keep going on the left
#Stae 2 means on the right
if STATE == 1:
pyautogui.press("left")
elif STATE == 2:
pyautogui.press("right")
def main():
#This is from top left as given in Paint.NET
#1051 and 810 was when he starts on the right
#I seem to have confused x and y for some reason
STARTY = 1051
STARTX = 810
STATE = 0
TREECOL = (136,99,50)
HATCOL = (58,100,108)
#RGB value of the hat is (58,100,108) according to PDN
#note that this is only applicable to the top row of pixels on the hat
#difference between left and right is 119 on mine
pyautogui.moveTo(STARTY - 119, STARTX)
pyautogui.click()
if pyautogui.pixel(STARTY, STARTX) == HATCOL:
print("Starting on the right")
STATE = 2
elif pyautogui.pixel(STARTY - 119, STARTX) == HATCOL:
print("Start on left")
STATE = 1
else:
print("Either the game doesn't work or it can't find the lumberjack")
sys.exit(1)
#Check if there's a tree and then move if there is otherwise keep chopping
while True:
if treechk(TREECOL, STATE) == False:
print("Keep going along")
goalong(STATE)
time.sleep(0.5)
elif treechk(TREECOL, STATE) == True:
print("Tree detected")
STATE = stateswitch(STATE)
time.sleep(0.5)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment