用python写全自动赛马娘脚本 全自动赛马娘脚本 Auto_Pretty Derby

用python写赛马娘脚本 全自动赛马娘脚本 Auto_Pretty Derby
先放上用脚本训练的成果
在这里插入图片描述

这是用脚本 练出来的一匹马
其实我一开始有一个想法就用python 去写一个模拟器脚本
但是大家都知道赛马娘 培养具有很多不稳定因素

所以研究了一点时间 用最笨的方法去实现 全自动赛马
现在在下面放上代码

from PIL import Image
import numpy as np
import pytesseract
import time
import cv2
import re
import os
import math
import operator
from functools import reduce
import cv2 as cv



def zhongma():
    
    os.system("adb devices")
    os.system("adb -s emulator-5554 shell input tap 874 2029")
    time.sleep(2)
    os.system("adb -s emulator-5554 shell input tap 518 2020")
    time.sleep(1)
    xunlainyaun()

def xunlainyaun():

   os.system("adb -s emulator-5554 shell screencap -p sdcard/screen.png") #截取屏幕,图片命名为screen.png
   os.system("adb -s emulator-5554 pull sdcard/screen.png D:\\ppc\\xu.png")
   
   img = Image.open(r"D:\\ppc\xu.png")
   
   cropped = img.crop((815,1990,1038,2076))  # (左,上,右,下 )#截图判断是否存在种马界面
   cropped.save(r"D:\\ppc\xu.png")

   img1_path=r'D:\ppc\xu.png'
   img2_path=r'D:\ppc\shuc\xu.png'
   try:
        # 读取图片
        img1 = cv2.imread(img1_path, cv2.IMREAD_GRAYSCALE)
        img2 = cv2.imread(img2_path, cv2.IMREAD_GRAYSCALE)
 
        # 初始化ORB检测器
        orb = cv2.ORB_create()
        kp1, des1 = orb.detectAndCompute(img1, None)
        kp2, des2 = orb.detectAndCompute(img2, None)
 
        # 提取并计算特征点
        bf = cv2.BFMatcher(cv2.NORM_HAMMING)
 
        # knn筛选结果
        matches = bf.knnMatch(des1, trainDescriptors=des2, k=2)
 
        # 查看最大匹配点数目
        good = [m for (m, n) in matches if m.distance < 0.55 * n.distance]
        #print(len(good))
        #print(len(matches))
        similary = len(good) / len(matches)
        print("两张图片相似度为:%s" % similary)
        if similary==0.9:
            print("等待训练员挑选马中---")
            xunlainyaun()
            time.sleep(1)
        else:
            print("训练员挑选马完毕---")
            quanzd()
        return similary
 
   except:
        print("等待训练员挑选马中---")
        xunlainyaun()
        time.sleep(1)
        return '0'
 
def quanzd():

    print("开始全自动种马")

    os.system("adb -s emulator-5554 shell input tap 741 1712")
    time.sleep(1)
    os.system("adb -s emulator-5554 shell input tap 744 1495")
    time.sleep(1)
    os.system("adb -s emulator-5554 shell input tap 510 2031")
    time.sleep(1)
    os.system("adb -s emulator-5554 shell input tap 761 1622")
    time.sleep(1)
    os.system("adb -s emulator-5554 shell input tap 761 1486")
    time.sleep(1)
    os.system("adb -s emulator-5554 shell input tap 558 2031")
    time.sleep(1)
    os.system("adb -s emulator-5554 shell input tap 851 2026")

    time.sleep(3)
    #跳过剧情
    
    time.sleep(3)
    os.system("adb -s emulator-5554 shell input tap 986 2241")
    time.sleep(2)
    os.system("adb -s emulator-5554 shell input tap 986 2241")
    time.sleep(2)
    os.system("adb -s emulator-5554 shell input tap 524 1565")
    time.sleep(2)
    os.system("adb -s emulator-5554 shell input tap 382 2293")
    time.sleep(2)
    os.system("adb -s emulator-5554 shell input tap 382 2293")
    time.sleep(2)

    saima()

    
def saima():

    #time.sleep(5)
    os.system("adb -s emulator-5554 shell screencap -p sdcard/screen.png") #截取屏幕,图片命名为screen.png
    os.system("adb -s emulator-5554 pull sdcard/screen.png D:\\ppc\\xn.png")
    
    img_path = r"D:\\ppc\xn.png"
    img = cv2.imread(img_path)
    gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imwrite(r"D:\\ppc\xn.png",gray_image)
    print(img.shape)
    

    #识别速度
    img = Image.open(r"D:\\ppc\xn.png")   
    cropped = img.crop((107,1704,203,1742))  # (左,上,右,下 )
    cropped.save(r"D:\\ppc\xn1.png")
    num_1 = Image.open(r'D:\\ppc\xn1.png')
    print("当前速度:"+pytesseract.image_to_string(num_1))

    
    #识别耐力
    img = Image.open(r"D:\\ppc\xn.png")  
    cropped = img.crop((280,1703,373,1742))  # (左,上,右,下 )
    cropped.save(r"D:\\ppc\nai.png")
    num_1 = Image.open(r'D:\\ppc\nai.png')
    print("当前耐力:"+pytesseract.image_to_string(num_1))



    #识别爆发
    img = Image.open(r"D:\\ppc\xn.png")    
    cropped = img.crop((445,1702,541,1742))  # (左,上,右,下 )
    cropped.save(r"D:\\ppc\bao.png")
    num_1 = Image.open(r'D:\\ppc\bao.png')
    print("当前爆发:"+pytesseract.image_to_string(num_1))
    
    
    #识别根性
    img = Image.open(r"D:\\ppc\xn.png")    
    cropped = img.crop((615,1704,711,1740))  # (左,上,右,下 )
    cropped.save(r"D:\\ppc\gen.png")
    num_1 = Image.open(r'D:\\ppc\gen.png')
    print("当前根性:"+pytesseract.image_to_string(num_1))

    #识别学识
    img = Image.open(r"D:\\ppc\xn.png")    
    cropped = img.crop((774,1702,876,1740))  # (左,上,右,下 )
    cropped.save(r"D:\\ppc\xue.png")
    num_1 = Image.open(r'D:\\ppc\xue.png')
    print("当前学识:"+pytesseract.image_to_string(num_1))



               
    
    #识别关闭技能页面
    img = Image.open(r"D:\\ppc\xn.png")   
    cropped = img.crop((819,1996,1030,2078))  # (左,上,右,下 )
    cropped.save(r"D:\\ppc\jn.png")

    pic1=r"D:\\ppc\jn.png"
    pic2=r"D:\\ppc\shuc\jn.png"
    image1 = Image.op
  • 9
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值