演示
本想放视频,可airscrpt跑的时候要用屏幕,在录视频两个进程其冲突,所以录视频失败!!
所以展示运行图片,具体运行可以看airscript官网,这里主要用到了找图的功能,用这功能去识别手机中16*10的数字矩阵,然后用算法去实现效果(slide滑动)
这里的算法比较简单
最高分可得122,最少可得90+
其中1,2,3到9的图片为数字图片:
如图
代码在:
# __init__.py 为初始化加载文件#导入-资源路径规划库from airscript.system import Rfrom airscript.action import slide#导入-节点检索库from airscript.node import Selector#导入-屏幕检索库from airscript.screen import FindColors # 找色from airscript.screen import CompareColors # 比色from airscript.screen import FindImages # 找图from airscript.screen import Ocr # 文字识别import timeprint('开始了')dic = []for j in range(1,10): ress = FindImages(R(__file__).res(f"/img/{j}.png")).confidence(0.9).find_all() for i in ress: # print(i) temp = {} temp['value'] = j temp['loc'] = i['result'] dic.append(temp)count = 0for i in dic: count+=i['value']print(count)if len(dic)!=160: print("error") exit(1)else: dic.sort(key=lambda x: [x['loc'][1]]) map = [] for i in range(16): temp = dic[i*10:(i+1)* 10] map.append(sorted(temp,key=lambda x:x['loc'][0])) # print(i)def drag(x1,y1,x2,y2): print(x1,y1,'->',x2,y2) clear(x1,y1,x2,y2) slide(map[x1][y1]['loc'][0],map[x1][y1]['loc'][1],map[x2][y2]['loc'][0],map[x2][y2]['loc'][1],200) time.sleep(0.5) passdef clear(x1,y1,x2,y2): for i in range(x1,x2+1): for j in range(y1,y2+1): map[i][j]['value'] = 0def sumtt(i,j,x,y): res =0 for x1 in range(i,x+1): for y1 in range(j,y+1): res+=map[x1][y1]['value'] return resfor i in map: print(i)change = Truewhile change == True: # 循环直到没有可以消除的 change = False for i in range(16): for j in range(10): flag = False row_list = [] column_list = [] #横向消除 count = map[i][j]['value'] for k in range(j+1,10): count+=map[i][k]['value'] if count<10: row_list.append(k) elif count==10: drag(i,j,i,k) #移动 change = True flag = True break else: break # 纵向消除 count = map[i][j]['value'] for k in range(i+ 1, 16): count += map[k][j]['value'] if count < 10: row_list.append(k) elif count == 10: drag(i, j, k, j) # 移动 change = True flag = True break else: break # 代表横向或纵向已经消除过,斜向就不搞了 if flag: continue for x in column_list: for y in row_list: res = sumtt(i,j,x,y) if res == 10: drag(i,j,x,y) change=True flag = True break if flag: breakfor i in map: print(i)