python游戏循环设置_python - 游戏脚本之无脑的循环挑战

该博客主要介绍了如何使用Python的wda库进行手游自动化操作,包括点击、循环执行等,并结合pytesseract进行图像识别,筛选有价值的战斗数据。通过自动化脚本,实现了手游挑战、跳过、购买等步骤,并对截图进行处理,过滤掉无效图片,保留关键战斗信息。
摘要由CSDN通过智能技术生成

三国挂机手游session

模拟点按并循环,在指定位置截图

# coding: utf-8

import os

import time

import wda

import random

#import pytesseract

from PIL import Image, ImageDraw

wdaClient = wda.Client()

wdaClientSession = wdaClient.session()

screenshot_historyLog_dir = 'historyLog/'

if not os.path.isdir(screenshot_historyLog_dir):

os.mkdir(screenshot_historyLog_dir)

def log_screenshot(ts):

wdaClient.screenshot("godlike.png")

image = Image.open("./godlike.png")

def main():

i = 1

while True:

#当前时间

ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

#挑战

wdaClientSession.tap(200, 549)

time.sleep(0.1)

#跳过

wdaClientSession.tap(200, 647)

time.sleep(0.1)

#把挑战数据h截图保存下来

log_screenshot(ts)

#关闭

wdaClientSession.tap(257, 581)

time.sleep(0.1)

#购买次数

if (i%13) == 0:

wdaClientSession.tap(277, 400)

print i,' ',ts

i += 1

if __name__ == '__main__':

main()

基于截图进行筛选,删除没必要要的图片,保留有价值的数据

# coding: utf-8

import os

import time

import wda

import random

import pytesseract

from PIL import Image, ImageDraw, ImageEnhance

import shutil

import string

import re

x = 170

y = 905

w = 217

h = 50

screenshot_historyLog_dir = 'historyLog/'

if not os.path.isdir(screenshot_historyLog_dir):

os.mkdir(screenshot_historyLog_dir)

filterLog_dir = 'filter/'

if not os.path.isdir(filterLog_dir):

os.mkdir(filterLog_dir)

unknowLog_dir = 'unknow2/'

if not os.path.isdir(unknowLog_dir):

os.mkdir(unknowLog_dir)

def initTable(threshold=77):#43

table = []

for i in range(256):

if i < threshold:

table.append(0)

else:

table.append(1)

return table

def log_screenshot(file):

imageName = '{}/{}'.format(screenshot_historyLog_dir, file)

regionName = "./godlikeRegion.png";

image = Image.open(imageName)

region = image.crop((x, y, x+w, y+h))

region.save(regionName)

imL = region.convert('L')

imL.save(regionName)

binaryImage = imL.point(initTable(), '1')

binaryImage.save(regionName)

text = pytesseract.image_to_string(binaryImage,lang='chi_sim')

#清除空格

text = ''.join(text.split())

print "识别数据 - ",text

if text == u"战斗至最后":

shutil.move(imageName,'{}{}'.format(filterLog_dir, file))

elif text == "":

print "will remove file " + imageName

os.remove(imageName)

else:

textNum = re.sub('\D','',text)

if textNum == "": #未能识别

os.remove(imageName)

# shutil.move(imageName,'{}{}'.format(unknowLog_dir, file))

return;

intNum = int(textNum)

if intNum > 44 :

print "will move file " + text

os.remove(imageName)

# shutil.move(imageName,'{}{}'.format(filterLog_dir, file))

else :

print "will remove file " + imageName

os.remove(imageName)

def main():

while True:

for file in os.listdir(screenshot_historyLog_dir):

if os.path.splitext(file)[-1] == ".png":

log_screenshot(file)

time.sleep(52)

if __name__ == '__main__':

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值