Skip to content

Instantly share code, notes, and snippets.

@slavking
Forked from anonymous/lumberbot.py
Last active October 13, 2016 11:25
Show Gist options
  • Select an option

  • Save slavking/a9827ec4a246cdd7bb5687eb3f9e47ed to your computer and use it in GitHub Desktop.

Select an option

Save slavking/a9827ec4a246cdd7bb5687eb3f9e47ed 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
#tree is at 480,640
print("State is ", STATE)
if STATE == 2:
'''old
if STATE == 2:
treepos = [801, 1051]
else:
treepos = [801, 931]
'''
treepos = [540, 620-119 ]
else:
treepos = [540-(119*2), 619 ]
#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
# GIMP, top left corner is 0,0:
# start button is 480,890 (x,y)
# old coordinates STARTY = 1051 STARTX = 810
#51,93,101 according to KolourPaint
#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
STARTY=619
STARTX=540
STATE=0
TREECOL=(136,99,50)
HATCOL=(58,100,108)
pyautogui.moveTo(STARTX,STARTY-119)
pyautogui.click()
print(pyautogui.pixel(STARTX,STARTY))
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