diff options
-rw-r--r-- | bot.py | 111 | ||||
-rw-r--r-- | requirements.txt | 83 |
2 files changed, 118 insertions, 76 deletions
@@ -1,89 +1,48 @@ | |||
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 keyboard import press_and_release |
8 | pg.typewrite(['left']) | 6 | from 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 | |||
19 | width, height = pg.size() | ||
20 | width *= 0.5 | ||
21 | pg.moveTo(333, 600) | ||
22 | pg.click() | ||
23 | 7 | ||
24 | posY = [360, 260, 160] | ||
25 | posX = [276, 398] | ||
26 | 8 | ||
27 | q = ['left', 'left', 'left'] | 9 | def begin(): |
10 | pg.click(440, 900, 2) | ||
28 | 11 | ||
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 | 12 | ||
34 | r0 = im.getpixel((posX[1], posY[0])) | 13 | TREE = uint8([56, 116, 161]) |
35 | r1 = im.getpixel((posX[1], posY[1])) | ||
36 | r2 = im.getpixel((posX[1], posY[2])) | ||
37 | 14 | ||
38 | if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: | 15 | # from left to right |
39 | q[0] = 'right' | 16 | posY = [360, 460] |
40 | pos = 'right' | 17 | # from bottom to up |
41 | else: | 18 | 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 | 19 | ||
48 | qlen = 3 | ||
49 | 20 | ||
50 | while True: | 21 | def 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: | 28 | def 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] | 37 | with 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) | ||
diff --git a/requirements.txt b/requirements.txt index 54b4a43..4084e6d 100644 --- a/requirements.txt +++ b/requirements.txt | |||
@@ -1,2 +1,85 @@ | |||
1 | mss==3.1.1 | ||
1 | numpy==1.13.3 | 2 | numpy==1.13.3 |
2 | opencv-python==3.4.0.12 | 3 | opencv-python==3.4.0.12 |
4 | Pillow==5.0.0 | ||
5 | PyAutoGUI==0.9.36 | ||
6 | PyMsgBox==1.0.6 | ||
7 | pyobjc==4.1 | ||
8 | pyobjc-core==4.1 | ||
9 | pyobjc-framework-Accounts==4.1 | ||
10 | pyobjc-framework-AddressBook==4.1 | ||
11 | pyobjc-framework-AppleScriptKit==4.1 | ||
12 | pyobjc-framework-AppleScriptObjC==4.1 | ||
13 | pyobjc-framework-ApplicationServices==4.1 | ||
14 | pyobjc-framework-Automator==4.1 | ||
15 | pyobjc-framework-AVFoundation==4.1 | ||
16 | pyobjc-framework-AVKit==4.1 | ||
17 | pyobjc-framework-CalendarStore==4.1 | ||
18 | pyobjc-framework-CFNetwork==4.1 | ||
19 | pyobjc-framework-CloudKit==4.1 | ||
20 | pyobjc-framework-Cocoa==4.1 | ||
21 | pyobjc-framework-Collaboration==4.1 | ||
22 | pyobjc-framework-Contacts==4.1 | ||
23 | pyobjc-framework-ContactsUI==4.1 | ||
24 | pyobjc-framework-CoreBluetooth==4.1 | ||
25 | pyobjc-framework-CoreData==4.1 | ||
26 | pyobjc-framework-CoreLocation==4.1 | ||
27 | pyobjc-framework-CoreServices==4.1 | ||
28 | pyobjc-framework-CoreText==4.1 | ||
29 | pyobjc-framework-CoreWLAN==4.1 | ||
30 | pyobjc-framework-CryptoTokenKit==4.1 | ||
31 | pyobjc-framework-DictionaryServices==4.1 | ||
32 | pyobjc-framework-DiskArbitration==4.1 | ||
33 | pyobjc-framework-EventKit==4.1 | ||
34 | pyobjc-framework-ExceptionHandling==4.1 | ||
35 | pyobjc-framework-FinderSync==4.1 | ||
36 | pyobjc-framework-FSEvents==4.1 | ||
37 | pyobjc-framework-GameCenter==4.1 | ||
38 | pyobjc-framework-GameController==4.1 | ||
39 | pyobjc-framework-GameKit==4.1 | ||
40 | pyobjc-framework-GameplayKit==4.1 | ||
41 | pyobjc-framework-ImageCaptureCore==4.1 | ||
42 | pyobjc-framework-IMServicePlugIn==4.1 | ||
43 | pyobjc-framework-InputMethodKit==4.1 | ||
44 | pyobjc-framework-InstallerPlugins==4.1 | ||
45 | pyobjc-framework-InstantMessage==4.1 | ||
46 | pyobjc-framework-Intents==4.1 | ||
47 | pyobjc-framework-IOSurface==4.1 | ||
48 | pyobjc-framework-iTunesLibrary==4.1 | ||
49 | pyobjc-framework-LatentSemanticMapping==4.1 | ||
50 | pyobjc-framework-LaunchServices==4.1 | ||
51 | pyobjc-framework-libdispatch==4.1 | ||
52 | pyobjc-framework-LocalAuthentication==4.1 | ||
53 | pyobjc-framework-MapKit==4.1 | ||
54 | pyobjc-framework-MediaAccessibility==4.1 | ||
55 | pyobjc-framework-MediaLibrary==4.1 | ||
56 | pyobjc-framework-MediaPlayer==4.1 | ||
57 | pyobjc-framework-ModelIO==4.1 | ||
58 | pyobjc-framework-MultipeerConnectivity==4.1 | ||
59 | pyobjc-framework-NetFS==4.1 | ||
60 | pyobjc-framework-NetworkExtension==4.1 | ||
61 | pyobjc-framework-NotificationCenter==4.1 | ||
62 | pyobjc-framework-OpenDirectory==4.1 | ||
63 | pyobjc-framework-Photos==4.1 | ||
64 | pyobjc-framework-PhotosUI==4.1 | ||
65 | pyobjc-framework-PreferencePanes==4.1 | ||
66 | pyobjc-framework-PubSub==4.1 | ||
67 | pyobjc-framework-QTKit==4.1 | ||
68 | pyobjc-framework-Quartz==4.1 | ||
69 | pyobjc-framework-SafariServices==4.1 | ||
70 | pyobjc-framework-SceneKit==4.1 | ||
71 | pyobjc-framework-ScreenSaver==4.1 | ||
72 | pyobjc-framework-ScriptingBridge==4.1 | ||
73 | pyobjc-framework-SearchKit==4.1 | ||
74 | pyobjc-framework-Security==4.1 | ||
75 | pyobjc-framework-SecurityFoundation==4.1 | ||
76 | pyobjc-framework-SecurityInterface==4.1 | ||
77 | pyobjc-framework-ServiceManagement==4.1 | ||
78 | pyobjc-framework-Social==4.1 | ||
79 | pyobjc-framework-SpriteKit==4.1 | ||
80 | pyobjc-framework-StoreKit==4.1 | ||
81 | pyobjc-framework-SyncServices==4.1 | ||
82 | pyobjc-framework-SystemConfiguration==4.1 | ||
83 | pyobjc-framework-WebKit==4.1 | ||
84 | PyScreeze==0.1.13 | ||
85 | PyTweening==1.0.3 | ||