this example for everyone to share a small program WeChat jump automatically run the script, for your reference, the specific contents are as follows

1, compressed package with ADB tools to configure it,

2, Python environment variables can be directly run (Python3.6)

wechat_jump_auto.py

 coding: # Code: UTF-8 '# = = = = = = # core ideas: every time off after the screenshot, screenshot and calculate the pieces according to the coordinates of the next block top surface point coordinates, # according to the distance of two points multiplied by a time line for long time according to the number # recognition rates: by colours to identify the location, through the screenshots found on the bottom for it is a straight line, on the way down from the line traversal, # color (color with an interval to find) The bottom line that all points, and then find a point, after half # for good let the Y axis to reduce the height of the chassis so as to obtain the coordinate pieces # recognition point: the center of the board by color background and box to do, starting from below the fraction, a row of circular scanning, because the block on the top is a line above # square is probably a bit, so I used the similar recognition rates approach recognized by several points for point, this time has been # X axis at the midpoint of the block, then assume now pawn in the current block center, according to a # gets through the screenshots the fixed angle to the midpoint of the launch Y coordinate # finally: according to the two coordinates is multiplied by the coefficient to obtain the long distance according to the time (seems to be the direct use of X OS import import 'axis distance) sys import subprocess Import time import math from PIL import Image import random from six.moves import input import debug, config import numpy as NP VERSION = "1.1.1" debug_switch = False # debug switch, need to debug when you change: True config = config.open_accordant_config (Magic Number) #, not set may not perform properly, please according to the screenshots from to set up as required, is stored in the config folder in the under_game_score_y = config['under_game_score_y'] press_coefficient = config['press_coefficient'] # long press time coefficient, please attach your own piece base according to the actual situation of regulation of piece_base_height_1_2 = config['piece_base_height_1_2'] 1/2 #, may need to adjust the piece_body_width = config['piece_body_width'] # piece width ratio. Amount to a little larger relatively safe, may need to adjust the screenshot_way = 2 def (pull_screenshot): a new method of 'please according to the efficiency and applicability of the order from high to low' global screenshot_way if screenshot_way or screenshot_way 1: process = = = = 2 = subprocess.Popen ('adb shell screencap -p', shell=True, stdout=subprocess.PIPE) screenshot = process.stdout.read (if) screenshot_way = = 2: binary_screenshot = screenshot.replace (b'rn', b'n') else: binary_screenshot = screenshot.replace (b'rrn', b'n') f = open ('autojump.png','wb') f.write (binary_screenshot) f.close (elif) screenshot_way 0: os.system ('adb shell = screencap -p /sdcard/autojump.png' os.system ('adb) pull /sdcard/autojump.png def (IM) set_button_position.) : 'swipe is set to ` again ` button position' '' global swipe_x1, swipe_y1, swipe_x2, swipe_y2, W, H = im.size left = int (w / 2) top = int (1584 * (H / 1920) left (random.uniform) = int (left-50, left+50) = int (random.uniform) top (top-10, top+10) - ban swipe_x1) # random, swipe_y1, swipe_x2, swipe_y2 = left, top, left, top def jump (distance): 'jump distance' press_time = distance * press_coefficient press_time = max (press_time, 200) # set 200ms is the smallest of the pressing time press_time = int (press_time) CMD ='adb shell input swipe {x1} {y1} {x2} {y2} {duration}'.format (x1=swipe_x1, y1=swipe_y1, x2=swipe_x2, y2=swipe_y2, duration=press_time) print (CMD) os.system (CMD) return press_time D EF find_piece_and_board (IM): 'w h' coordinates to find the key, im.size = piece_x_sum = 0 piece_x_c = 0 piece_y_max = 0 board_x = 0 board_y = 0 scan_x_border = int (w / scan_start_y = 8) around the border # scanning pieces 0 # scanning y im_pixel = im.load (initial coordinates) # to step 50px scan_start_y for I in, try to detect range (int (H / 3), int (h*2 / 3), 50): last_pixel = im_pixel[0, i] for J in range (1, w): pixel = im_pixel[j, i] # is not a solid line, record the value of scan_start_y, ready to jump out of the cycle of if pixel[0]! Last_pixel[0] = or pixel[1] = last_pixel[1] or! Pixel[2]! = last_pixel[2]: scan_start_y = I - 50 break if scan_start_y: break print ('scan_start_y: {}'.format (scan_start_y) #) from scan_start_y To scan pieces should be located in the top half of the screen, there is no more than 2/3 for I in is range (scan_start_y, int (h * 2 / 3)): for J in range (scan_x_border, W - scan_x_border): # abscissa also reduced the part scanning overhead of pixel = im_pixel[j, i] # according to minimum for pieces of color judgment, to find the last line of the mean value of the point, the color of this should be OK, temporarily proposed by if (50 < pixel[0] < 60) and (53 < pixel[1] < 63) and (95 < pixel[2] < 110): piece_x_sum = J piece_x_c = 1 piece_y_max = max (I, piece_y_max) if not all ((piece_x_sum, piece_x_c)): return 0, 0, 0, 0 piece_x = int (piece_x_sum / piece_x_c) piece_y = piece_y_max - piece_base_height_1_2 # up to half of the height limit # chassis chess chess The abscissa disc scanning, bug if piece_x < to avoid notes; w/2: board_x_start = piece_x board_x_end = w else: board_x_start = 0 board_x_end = piece_x for I in range (int (H / 3), int (h * 2 / 3)): last_pixel = im_pixel[0, i] if board_x or board_y: break board_x_sum = board_x_c = 0 0 for J in range (int (board_x_start), int (board_x_end)): pixel = im_pixel[j, i] # cut off head is higher than the small lattice under a condition of bug if ABS (J - piece_x) < piece_body_width: continue; # cut off a line leading to the dome of the small bug, the color of judgment should OK, temporarily if out ABS (pixel[0] - last_pixel[0]) + ABS (pixel[1] - last_pixel[1]) + ABS (pixel[2] - last_pixel[2]) > 10: board_x_sum = J board_x_c = 1 if board_x_ Sum: board_x = board_x_sum / board_x_c = last_pixel im_pixel[board_x, i] # starting from the vertex +274 below the position to find the same color and vertex point, for the method of vertex # all solid plane and non plane solid effective, on golf turf surface, wood desktop, bottle and non diamond disc machine (it is an error of judgment for K in) range (i+274, I, -1): pixel = im_pixel[board_x vertex distance square maximum # from 274 at the start, k] if ABS (pixel[0] - last_pixel[0]) + ABS (pixel[1] - last_pixel[1]) + ABS (pixel[2] - last_pixel[2]) < 10: break board_y = int ((i+k) / 2) # if a jump shot, the next target will appear in the center of R245 G245 b245, make up a section of the code may have the use of this attribute error of judgment # if a jump for some reason not to jump to the middle, and next hop just can not correctly identify patterns, is likely the game failed due to the pattern area is usually large, the lower the probability of failure of for L in range (I, i+200): pixel = im_pixel[board_x, l] if ABS (pixel[0] - 245) + ABS (pixel[1] - 245) + ABS (pixel[2] - 245) = 0: board_y = l+10 break if not all ((board_x, board_y)): return 0, 0, 0, 0 return piece_x, piece_y, board_x, board_y def (check_screenshot): 'get check way' '' global screenshot_way if. (os.path.isfile'autojump.png'): os.remove ('autojump.png') if (screenshot_way < print (0): 'does not support the current device (sys.exit')) pull_screenshot (try:) Image.open (autojump.png') print (.Load'./) (the Party' Type'.format (screenshot_way) {} get screenshot) except Exception: screenshot_way check_screenshot (DEF) = 1 yes_or_no (prompt, true_value='y', false_value='n', default=True): default_value = true_value if default else false_value prompt ='%s%s/%s [%s]: '% (prompt, true_value, false_value, default_value) I = input (prompt) if not i: return default while True: if I true_value: return True elif I = false_value: return = = False prompt ='Please input%s or%s:'% (true_value, false_value) I = input (prompt) def (main): 'main function' OP '= yes_or_no (please make sure to open the ADB mobile phone and connect with the computer, and then open the jump [] and start the game with this program, determine the start? 'if not op: print ('bye') print (return) 'program version number: {}'.format (VERSION)) debug.dump_device_info (check_screenshot) (I), next_rest, next_rest_time = 0, random.randrange (3, 10), random.randrange (5, 10) while True: pull_screenshot (IM) = Image.open ('./autojump.png') piece_x, # get the pieces and board piece_y, board_x, board_y = find_piece_and_board (IM) ts = int (time.time) (print) (TS, piece_x, piece_y, board_x, board_y) set_button_position (IM) jump (math.sqrt ((board_x - piece_x) * 2 + (board_y - piece_y) * * 2) debug_switch: debug.save_debug_screenshot (if) TS, Im, piece_x, piece_y, board_x, board_y) debug.backup_screenshot (TS) I + = 1 if I = = next_rest: print ('consecutive hit {}, rest {}s'.forma T (I, next_rest_time) for) J in range (next_rest_time): sys.stdout.write ('r program will continue to'.format after {}s (next_rest_time - J)) (sys.stdout.flush) time.sleep (2) print ('n 'I, next_rest, to) random.randrange (next_rest_time = 0, 30, 100, 10, 60 (random.randrange) (time.sleep) np.random.uniform (0.6,0.9)) # screenshot time should be in order to ensure a steady drop, delay for a while, the random value if = ='__main__': __name__ ban main (

)

simple.py

 # -*- coding: UTF-8 import as NP import -*- numpy CV2 import OS import time import re def pull_screenshot (path # screenshot) os.system ('adb shell screencap -p /sdcard/%s'path os.system ('adb%) pull /sdcard/%s.% path) # according to x from jump (distance, jump def alpha) Press_time = max (int (distance * alpha), 200) CMD ='adb shell input swipe {} {} {} {} {}'.format (BX1, by1, bx2, BY2, press_time) os.system (CMD) screenshot ='screenshot.png'alpha = 0 BX1, by1, bx2, BY2 = 0, 0, 0, 0 chess_x = 0 target_x = 0 fix = 1.6667 # check size_str resolution is 960x540 = os.popen ('adb shell WM size' if size_str: m (.Read)) = re.search (R'(d+) x (d+)', size_str) if m: hxw = "{height}x{width}".Format (height=m.group (2), width=m.group (1) hxw = = if) "960x540": fix = 3.16 while True: pull_screenshot (screenshot) image_np = cv2.im


This concludes the body part