diff options
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 117 |
1 files changed, 41 insertions, 76 deletions
@@ -1,89 +1,54 @@ | |||
1 | import pyautogui as pg | 1 | import time |
2 | from time import sleep | ||
3 | |||
4 | 2 | ||
5 | def move(_pos, _now): | 3 | import mss |
6 | if _pos == 'left' and _now == 'left': | 4 | import pyautogui as pg |
7 | pg.typewrite(['left']) | 5 | from numpy import array, uint8 |
8 | pg.typewrite(['left']) | ||
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 | 6 | ||
19 | width, height = pg.size() | 7 | #from keyboard import send |
20 | width *= 0.5 | ||
21 | pg.moveTo(333, 600) | ||
22 | pg.click() | ||
23 | 8 | ||
24 | posY = [360, 260, 160] | 9 | from pynput.keyboard import Key, Controller |
25 | posX = [276, 398] | 10 | keyboard = Controller() |
26 | 11 | ||
27 | q = ['left', 'left', 'left'] | 12 | def begin(): |
13 | pg.click(440, 900, 2) | ||
28 | 14 | ||
29 | im = pg.screenshot(region=(0, 0, width, height)) | ||
30 | l0 = im.getpixel((posX[0], posY[0])) | ||
31 | l1 = im.getpixel((posX[0], posY[1])) | ||
32 | l2 = im.getpixel((posX[0], posY[2])) | ||
33 | 15 | ||
34 | r0 = im.getpixel((posX[1], posY[0])) | 16 | TREE = uint8([56, 116, 161]) |
35 | r1 = im.getpixel((posX[1], posY[1])) | ||
36 | r2 = im.getpixel((posX[1], posY[2])) | ||
37 | 17 | ||
38 | if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: | 18 | # from left to right |
39 | q[0] = 'right' | 19 | posY = [360, 460] |
40 | pos = 'right' | 20 | # from bottom to up |
41 | else: | 21 | posX = [640, 540, 440, 340, 240, 140] |
42 | pos = 'left' | ||
43 | if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: | ||
44 | q[1] = 'right' | ||
45 | if l2[0] == 161 and l2[1] == 116 and l2[2] == 56: | ||
46 | q[2] = 'right' | ||
47 | 22 | ||
48 | qlen = 3 | ||
49 | 23 | ||
50 | while True: | 24 | def is_tree(c1): |
51 | if qlen == 3: | 25 | if c1[0] == TREE[0] and c1[1] == TREE[1] and c1[2] == TREE[2]: |
52 | now = q[0] | 26 | return True |
53 | move(pos, now) | 27 | else: |
54 | now = q[1] | 28 | 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 | 29 | ||
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 | 30 | ||
69 | if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: | 31 | with mss.mss() as sct: |
70 | q[0] = 'right' | 32 | screen = sct.monitors[1] |
71 | else: | 33 | screen["width"] = screen["width"] / 2.0 |
72 | q[0] = 'left' | 34 | begin() |
73 | if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: | ||
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 | 35 | ||
82 | now = q[0] | 36 | while True: |
83 | move(pos, now) | 37 | img = array(sct.grab(screen)) |
84 | now = q[1] | 38 | moves = list() |
85 | move(pos, now) | 39 | left = [img[x, posY[0]] for x in posX] |
86 | now = q[2] | 40 | for i in range(6): |
87 | move(pos, now) | 41 | if is_tree(left[i]): |
42 | keyboard.press(Key.right) | ||
43 | keyboard.release(Key.right) | ||
44 | time.sleep(0.014) | ||
45 | keyboard.press(Key.right) | ||
46 | keyboard.release(Key.right) | ||
47 | else: | ||
48 | keyboard.press(Key.left) | ||
49 | keyboard.release(Key.left) | ||
50 | time.sleep(0.014) | ||
51 | keyboard.press(Key.left) | ||
52 | keyboard.release(Key.left) | ||
53 | time.sleep(0.17) | ||
88 | 54 | ||
89 | sleep(0.095) | ||