[原创]在雷电模拟器玩2048[源码]
首先参考我的上一个帖子 雷电模拟器说明附代码里面的东西是这一篇的前提
有人问那一篇有什么用,这里主要是说一下有什么用
2048使用这个包名的版本:com.digiplex.game
广告最少,干扰最小
分辨率开1080*1920*480
目前用的贪婪算法,思考深度是1
基本可以玩到128,运气好到512
===
import time
from Dnconsole import Dnconsole
import cv2 as cv
def compare_status(st0: list, st1: list) -> bool:# True相同 False不同
if len(st0) != len(st1):
return False
for i in range(len(st0)):
if len(st0) != len(st1):
return False
for j in range(len(st0)):
if st0 != st1:
return False
return True
def copy_statu(status: list) -> list:
result = list()
for line in status:
result.append(, line, line, line])
return result
def read_num(area: tuple, screen: str, template: list) -> int:
scr = cv.imread(screen)
cur_area = scr:area, area:area]# 前面是y轴 后面是x轴
for i, tmp in enumerate(template):
tp = cv.imread(tmp)
try:
result = cv.matchTemplate(cur_area, tp, cv.TM_SQDIFF_NORMED)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if min_val < 0.001:
return int(template.replace('2048/', '').replace('.png', ''))
except cv.error:
continue
return -1
def get_cur_status() -> list:
result = list()
result.append()
result.append()
result.append()
result.append()
pos = # , , , ]
template = ['2048/0.png', '2048/2.png', '2048/4.png', '2048/8.png', '2048/16.png', '2048/32.png',
'2048/64.png', '2048/128.png', '2048/256.png', '2048/512.png', '2048/1024.png']
screen = 'E:/Project/PyCharmProj/Script/2048/share/2048.png'
for i in range(4):
for j in range(4):
area = (pos + 270 * j, pos + 270 * i, pos + 270 * j, pos + 270 * i)
result = read_num(area, screen, template)
return result
def swipe_up():
Dnconsole.swipe(0, (540, 1280), (540, 260))
print('上移')
def swipe_down():
Dnconsole.swipe(0, (540, 260), (540, 1280))
print('下移')
def swipe_left():
Dnconsole.swipe(0, (1000, 770), (100, 770))
print('左移')
def swipe_right():
Dnconsole.swipe(0, (100, 770), (1000, 770))
print('右移')
def get_null_count(status: list) -> int:
if len(status) == 0:
print('此方向移动无效')
return -1
result = 0
for row in status:
for node in row:
if node == 0:
result += 1
return result
def get_sum(line: list) -> int:
total = 0
for i in range(len(line)):
total += line
return total
def compress_line(line: list) -> list:
# 压实一条数据
length = len(line)
result = line[:]
if get_sum(line) == 0:# 全零则直接返回
return line
for i in range(length):
if get_sum(result) == 0:
break
while result == 0:
for j in range(i, length - 1):
result = result
result = 0
return result
def combine_line(line: list) -> list:
# 合并一条数据
length = len(line)
result = line[:]
for i in range(length - 1):
if result == result:
result *= 2
result = 0
return result
def deduction_up(status: list) -> list:
result = copy_statu(status)
# 先把数据压实,再合并
for i in range(4):
line = , result, result, result]
line = compress_line(line)# 压实(去掉为0的格子)
line = combine_line(line)# 合并
line = compress_line(line)# 压实
result, result, result, result = line, line, line, line
if compare_status(result, status):
return []
return result
def deduction_down(status: list) -> list:
result = copy_statu(status)
# 先把数据压实,再合并
for i in range(4):
line = , result, result, result]
line = compress_line(line)# 压实(去掉为0的格子)
line = combine_line(line)# 合并
line = compress_line(line)# 压实
result, result, result, result = line, line, line, line
if compare_status(result, status):
return []
return result
def deduction_left(status: list) -> list:
result = copy_statu(status)
# 先把数据压实,再合并
for i in range(4):
line = , result, result, result]
line = compress_line(line)# 压实(去掉为0的格子)
line = combine_line(line)# 合并
line = compress_line(line)# 压实
result, result, result, result = line, line, line, line
if compare_status(result, status):
return []
return result
def deduction_right(status: list) -> list:
result = copy_statu(status)
# 先把数据压实,再合并
for i in range(4):
line = , result, result, result]
line = compress_line(line)# 压实(去掉为0的格子)
line = combine_line(line)# 合并
line = compress_line(line)# 压实
result, result, result, result = line, line, line, line
if compare_status(result, status):
return []
return result
def run():
if Dnconsole.is_running(0) is False:
Dnconsole.launch(0)
for i in range(120):
if Dnconsole.is_running(0):
time.sleep(10)
break
time.sleep(1)
Dnconsole.invokeapp(0, 'com.digiplex.game')
end_status = [[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]]
if Dnconsole.wait_activity(0, 'com.digiplex.game/.MainActivity', 20) is True:
while True:
Dnconsole.dnld(0, 'screencap -p /sdcard/Pictures/2048.png')
time.sleep(1)
status = get_cur_status()
if compare_status(end_status, status):
print('结束')
break
print('status=', status)
func =
swipe =
max_count = 0
direction = -1
for i in range(4):
c = get_null_count(func(status))
if c > max_count:
direction = i
max_count = c
if direction == -1:
print('结束')
return
swipe()
time.sleep(1.5)
=== 雷电广告虽少,但是win7安装雷电模拟,试了七、八个电视tv软件安装后,打不开视频!打游戏戏还可以https://www.52pojie.cn/thread-806714-1-1.html 补充一个1024的识别附件,上传的时候选择了,但是好像没有上传成功
这些都是用于做模板,进行比对的
通过比对来识别文字 这个非常不错 Python已经无所不能了 脚本收下了,学习一下,感谢分享! 谢谢分享 谢谢论坛 虽然看不懂,但是很强。。。。 前阵子雷电模拟器上被封了一个微信小号,也不靠谱啊
虽然看不懂,但是很强。。。。 这个是游戏本身。还是辅助用的
不过这个游戏真的是有毒,一上手就停不下来
页:
[1]
2