From f3e1d8caa70829ab3167632905bccaed0b1fb3cd Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 2 Jan 2018 21:59:04 +0800 Subject: 924 --- bot.py | 111 ++++++++++++++++++------------------------------------- requirements.txt | 83 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 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 @@ -import pyautogui as pg -from time import sleep - +import time -def move(_pos, _now): - if _pos == 'left' and _now == 'left': - pg.typewrite(['left']) - pg.typewrite(['left']) - elif _pos == 'left' and _now == 'right': - pg.typewrite(['right']) - pg.typewrite(['right']) - elif _pos == 'right' and _now == 'right': - pg.typewrite(['right']) - pg.typewrite(['right']) - elif _pos == 'right' and _now == 'left': - pg.typewrite(['left']) - pg.typewrite(['left']) - -width, height = pg.size() -width *= 0.5 -pg.moveTo(333, 600) -pg.click() +import mss +import pyautogui as pg +from keyboard import press_and_release +from numpy import array, uint8 -posY = [360, 260, 160] -posX = [276, 398] -q = ['left', 'left', 'left'] +def begin(): + pg.click(440, 900, 2) -im = pg.screenshot(region=(0, 0, width, height)) -l0 = im.getpixel((posX[0], posY[0])) -l1 = im.getpixel((posX[0], posY[1])) -l2 = im.getpixel((posX[0], posY[2])) -r0 = im.getpixel((posX[1], posY[0])) -r1 = im.getpixel((posX[1], posY[1])) -r2 = im.getpixel((posX[1], posY[2])) +TREE = uint8([56, 116, 161]) -if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: - q[0] = 'right' - pos = 'right' -else: - pos = 'left' -if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: - q[1] = 'right' -if l2[0] == 161 and l2[1] == 116 and l2[2] == 56: - q[2] = 'right' +# from left to right +posY = [360, 460] +# from bottom to up +posX = [640, 540, 440, 340, 240, 140] -qlen = 3 -while True: - if qlen == 3: - now = q[0] - move(pos, now) - now = q[1] - move(pos, now) - now = q[2] - move(pos, now) - qlen = 0 - elif qlen == 0: - im = pg.screenshot(region=(0, 0, width, height)) - l0 = im.getpixel((posX[0], posY[0])) - l1 = im.getpixel((posX[0], posY[1])) - l2 = im.getpixel((posX[0], posY[2])) +def is_tree(c1): + if c1[0] == TREE[0] and c1[1] == TREE[1] and c1[2] == TREE[2]: + return True + else: + return False - r0 = im.getpixel((posX[1], posY[0])) - r1 = im.getpixel((posX[1], posY[1])) - r2 = im.getpixel((posX[1], posY[2])) - if l0[0] == 161 and l0[1] == 116 and l0[2] == 56: - q[0] = 'right' +def parse_screen(img, moves): + left = [img[x, posY[0]] for x in posX] + for i in range(6): + if is_tree(left[i]): + moves.append("right, right") else: - q[0] = 'left' - if l1[0] == 161 and l1[1] == 116 and l1[2] == 56: - q[1] = 'right' - else: - q[1] = 'left' - if l2[0] == 161 and l2[1] == 116 and l2[2] == 56: - q[2] = 'right' - else: - q[2] = 'left' + moves.append("left, left") + - now = q[0] - move(pos, now) - now = q[1] - move(pos, now) - now = q[2] - move(pos, now) +with mss.mss() as sct: + screen = sct.monitors[1] + screen["width"] = screen["width"] / 2.0 + begin() - sleep(0.095) + while True: + img = array(sct.grab(screen)) + moves = list() + parse_screen(img, moves) + for m in moves: + press_and_release(m) + 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 @@ +mss==3.1.1 numpy==1.13.3 opencv-python==3.4.0.12 +Pillow==5.0.0 +PyAutoGUI==0.9.36 +PyMsgBox==1.0.6 +pyobjc==4.1 +pyobjc-core==4.1 +pyobjc-framework-Accounts==4.1 +pyobjc-framework-AddressBook==4.1 +pyobjc-framework-AppleScriptKit==4.1 +pyobjc-framework-AppleScriptObjC==4.1 +pyobjc-framework-ApplicationServices==4.1 +pyobjc-framework-Automator==4.1 +pyobjc-framework-AVFoundation==4.1 +pyobjc-framework-AVKit==4.1 +pyobjc-framework-CalendarStore==4.1 +pyobjc-framework-CFNetwork==4.1 +pyobjc-framework-CloudKit==4.1 +pyobjc-framework-Cocoa==4.1 +pyobjc-framework-Collaboration==4.1 +pyobjc-framework-Contacts==4.1 +pyobjc-framework-ContactsUI==4.1 +pyobjc-framework-CoreBluetooth==4.1 +pyobjc-framework-CoreData==4.1 +pyobjc-framework-CoreLocation==4.1 +pyobjc-framework-CoreServices==4.1 +pyobjc-framework-CoreText==4.1 +pyobjc-framework-CoreWLAN==4.1 +pyobjc-framework-CryptoTokenKit==4.1 +pyobjc-framework-DictionaryServices==4.1 +pyobjc-framework-DiskArbitration==4.1 +pyobjc-framework-EventKit==4.1 +pyobjc-framework-ExceptionHandling==4.1 +pyobjc-framework-FinderSync==4.1 +pyobjc-framework-FSEvents==4.1 +pyobjc-framework-GameCenter==4.1 +pyobjc-framework-GameController==4.1 +pyobjc-framework-GameKit==4.1 +pyobjc-framework-GameplayKit==4.1 +pyobjc-framework-ImageCaptureCore==4.1 +pyobjc-framework-IMServicePlugIn==4.1 +pyobjc-framework-InputMethodKit==4.1 +pyobjc-framework-InstallerPlugins==4.1 +pyobjc-framework-InstantMessage==4.1 +pyobjc-framework-Intents==4.1 +pyobjc-framework-IOSurface==4.1 +pyobjc-framework-iTunesLibrary==4.1 +pyobjc-framework-LatentSemanticMapping==4.1 +pyobjc-framework-LaunchServices==4.1 +pyobjc-framework-libdispatch==4.1 +pyobjc-framework-LocalAuthentication==4.1 +pyobjc-framework-MapKit==4.1 +pyobjc-framework-MediaAccessibility==4.1 +pyobjc-framework-MediaLibrary==4.1 +pyobjc-framework-MediaPlayer==4.1 +pyobjc-framework-ModelIO==4.1 +pyobjc-framework-MultipeerConnectivity==4.1 +pyobjc-framework-NetFS==4.1 +pyobjc-framework-NetworkExtension==4.1 +pyobjc-framework-NotificationCenter==4.1 +pyobjc-framework-OpenDirectory==4.1 +pyobjc-framework-Photos==4.1 +pyobjc-framework-PhotosUI==4.1 +pyobjc-framework-PreferencePanes==4.1 +pyobjc-framework-PubSub==4.1 +pyobjc-framework-QTKit==4.1 +pyobjc-framework-Quartz==4.1 +pyobjc-framework-SafariServices==4.1 +pyobjc-framework-SceneKit==4.1 +pyobjc-framework-ScreenSaver==4.1 +pyobjc-framework-ScriptingBridge==4.1 +pyobjc-framework-SearchKit==4.1 +pyobjc-framework-Security==4.1 +pyobjc-framework-SecurityFoundation==4.1 +pyobjc-framework-SecurityInterface==4.1 +pyobjc-framework-ServiceManagement==4.1 +pyobjc-framework-Social==4.1 +pyobjc-framework-SpriteKit==4.1 +pyobjc-framework-StoreKit==4.1 +pyobjc-framework-SyncServices==4.1 +pyobjc-framework-SystemConfiguration==4.1 +pyobjc-framework-WebKit==4.1 +PyScreeze==0.1.13 +PyTweening==1.0.3 -- cgit v1.2.3