aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2018-01-02 21:59:04 +0800
committerclarkzjw <[email protected]>2018-01-02 21:59:04 +0800
commitf3e1d8caa70829ab3167632905bccaed0b1fb3cd (patch)
treed0b63973e6fed302022cbcfd3a11dbde199dadbf /bot.py
parent66240fe4c0704c5481fe203119367bcac7790e23 (diff)
downloadLumberJack-f3e1d8caa70829ab3167632905bccaed0b1fb3cd.tar.gz
924
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py111
1 files changed, 35 insertions, 76 deletions
diff --git a/bot.py b/bot.py
index e8f7a3c..f19694a 100644
--- a/bot.py
+++ b/bot.py
@@ -1,89 +1,48 @@
1import pyautogui as pg 1import time
2from time import sleep
3
4 2
5def move(_pos, _now): 3import mss
6 if _pos == 'left' and _now == 'left': 4import pyautogui as pg
7 pg.typewrite(['left']) 5from keyboard import press_and_release
8 pg.typewrite(['left']) 6from numpy import array, uint8
9 elif _pos == 'left' and _now == 'right':
10 pg.typewrite(['right'])
11 pg.typewrite(['right'])
12 elif _pos == 'right' and _now == 'right':
13 pg.typewrite(['right'])
14 pg.typewrite(['right'])
15 elif _pos == 'right' and _now == 'left':
16 pg.typewrite(['left'])
17 pg.typewrite(['left'])
18
19width, height = pg.size()
20width *= 0.5
21pg.moveTo(333, 600)
22pg.click()
23 7
24posY = [360, 260, 160]
25posX = [276, 398]
26 8
27q = ['left', 'left', 'left'] 9def begin():
10 pg.click(440, 900, 2)
28 11
29im = pg.screenshot(region=(0, 0, width, height))
30l0 = im.getpixel((posX[0], posY[0]))
31l1 = im.getpixel((posX[0], posY[1]))
32l2 = im.getpixel((posX[0], posY[2]))
33 12
34r0 = im.getpixel((posX[1], posY[0])) 13TREE = uint8([56, 116, 161])
35r1 = im.getpixel((posX[1], posY[1]))
36r2 = im.getpixel((posX[1], posY[2]))
37 14
38if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: 15# from left to right
39 q[0] = 'right' 16posY = [360, 460]
40 pos = 'right' 17# from bottom to up
41else: 18posX = [640, 540, 440, 340, 240, 140]
42 pos = 'left'
43if l1[0] == 161 and l1[1] == 116 and l1[2] == 56:
44 q[1] = 'right'
45if l2[0] == 161 and l2[1] == 116 and l2[2] == 56:
46 q[2] = 'right'
47 19
48qlen = 3
49 20
50while True: 21def is_tree(c1):
51 if qlen == 3: 22 if c1[0] == TREE[0] and c1[1] == TREE[1] and c1[2] == TREE[2]:
52 now = q[0] 23 return True
53 move(pos, now) 24 else:
54 now = q[1] 25 return False
55 move(pos, now)
56 now = q[2]
57 move(pos, now)
58 qlen = 0
59 elif qlen == 0:
60 im = pg.screenshot(region=(0, 0, width, height))
61 l0 = im.getpixel((posX[0], posY[0]))
62 l1 = im.getpixel((posX[0], posY[1]))
63 l2 = im.getpixel((posX[0], posY[2]))
64 26
65 r0 = im.getpixel((posX[1], posY[0]))
66 r1 = im.getpixel((posX[1], posY[1]))
67 r2 = im.getpixel((posX[1], posY[2]))
68 27
69 if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: 28def parse_screen(img, moves):
70 q[0] = 'right' 29 left = [img[x, posY[0]] for x in posX]
30 for i in range(6):
31 if is_tree(left[i]):
32 moves.append("right, right")
71 else: 33 else:
72 q[0] = 'left' 34 moves.append("left, left")
73 if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: 35
74 q[1] = 'right'
75 else:
76 q[1] = 'left'
77 if l2[0] == 161 and l2[1] == 116 and l2[2] == 56:
78 q[2] = 'right'
79 else:
80 q[2] = 'left'
81 36
82 now = q[0] 37with mss.mss() as sct:
83 move(pos, now) 38 screen = sct.monitors[1]
84 now = q[1] 39 screen["width"] = screen["width"] / 2.0
85 move(pos, now) 40 begin()
86 now = q[2]
87 move(pos, now)
88 41
89 sleep(0.095) 42 while True:
43 img = array(sct.grab(screen))
44 moves = list()
45 parse_screen(img, moves)
46 for m in moves:
47 press_and_release(m)
48 time.sleep(0.145)
Powered by cgit v1.2.3 (git 2.41.0)