石家庄市建设局质监站网站,温州人才网招聘网官网,wordpress手机端404页面,wordpress 简介转自我的独立博客alanslab.cn#xff0c;不打算续费域名了。懒人实在不该开什么独立博客。。。csdn的都嫌折腾了。。。。。。。上帝赐我一个脑机接口吧#xff0c;usb兼容就行。。。 csdn不知道怎么放土豆视频#xff0c;留链接【http://www.tudou.com/programs/view/QmQ49l…转自我的独立博客alanslab.cn不打算续费域名了。懒人实在不该开什么独立博客。。。csdn的都嫌折腾了。。。。。。。上帝赐我一个脑机接口吧usb兼容就行。。。 csdn不知道怎么放土豆视频留链接【http://www.tudou.com/programs/view/QmQ49lg1XTs/?resourceId321946240_06_02_99】 注视频中的效果是一开始做的暴力划屏幕的作弊效果这里则是尝试分析截图有目的的去划动。截屏实在太慢效果还不如暴力。我是懒得继续了搞它了有兴趣玩的可以看下frame buffer的资料一定程度应该能缓解截屏速度的限制。 文章比较早代码已丢。但是所需的东西这里都有抄抄改改几十行就完事了。 更新睡一觉起来改写了算法之前那个写的时候脑袋有点不太清醒。。。思路就是穷举所有可以消除的模式跟之前一样不过改写完好像正确率高了很多看来之前那个是写太乱漏了什么东西。 前几天被人鄙视了。。今早就试试看写个小脚本刷下分数。 视频里的做法非常简单就用了android sdk tools 里面的monkeyrunner这一个自动测试工具。 google的文档 做法就是用monkeyrunner截图后用gimp找到卡通角色对应的位置规律然后代码模拟触控让其不停上上下下左左右右。。。如视频中所见一整个屏幕的触控操作几乎同时完成效果非常给力google养的这只monkey相当强悍 中间出了一次小插曲。。我的最高分被清空了一次。。不知道是网络问题还是怎样。。。所以之后就考虑怎么分析图像来解决这问题。好在这游戏还算宽松没拿什么雪花闪电的挡屏幕在每个角色的同一位置取色对比就可以了网上没找着什么合适的算法。。就自己动手暴力编了一个下文附上虽然效果差很多而且老是误判一定有bug。。。懒得找了今天也算是学习之余休息休息放个假。 第一个版本代码里没用到的那个注释了crazy monkey的函数不过应该用不了了效果不错分分钟打败大毛。 第二个版本现在这个误判连连已重写效果还不错偶尔的误判是因为处理的图像不是实时的可以调整暂停的时间做一点有限的优化刷分效果不是太好但是隐蔽。。。有机会找个霸气点的算法看看怎么改进一下应该也不错。但获取屏幕截图的速度是个硬伤这个思路估计再努力也到不了第一版的效果今早本来是想写个打飞机的脚本也是因为这个问题作罢。 运行方式先装好andorid sdk然后复制文后的代码到monkey.py。 接上手机打开开发者模式打开游戏同时点开始按钮和执行下面的命令玩完关闭的话。。抱歉。。Ctrlc吧win是Ctrld好像不行就试试Ctrlz。。。
zcfanalan-ubuntu ~/adb $ ~/android-sdks/tools/monkeyrunner /path/to/monkey.py windows的话可能是类似这样应该没错吧。。
C:\SDK\tools\monkeyrunner C:\monkey.py monkey.py:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
import timedef drag(pos, dir):tx pos[0]ty pos[1]if dir up:ty - 100if dir down:ty 100if dir left:tx - 100if dir right:tx 100device.drag(pos, (tx, ty), 0, 1)device MonkeyRunner.waitForConnection()def capToFile():screen device.takeSnapshot()screen.writeToFile(shot.png, png)def getNodePos(x, y):width 108height 108return (60(x*width),280(y*height))# crazy monkey(s)
def monkeyrun():for y in xrange(2, 7, 2):for x in xrange(0, 8):drag(getNodePos(x, y), up)time.sleep(sleeptime)for y in xrange(1, 6, 2):for x in xrange(0, 8):drag(getNodePos(x, y), up)time.sleep(sleeptime)for x in xrange(0, 5, 2):for y in xrange(0, 8):drag(getNodePos(x, y), right)time.sleep(sleeptime)for x in xrange(1, 6, 2):for y in xrange(0, 8):drag(getNodePos(x, y), right)time.sleep(sleeptime)for y in xrange(0, 5, 2):for x in xrange(0, 8):drag(getNodePos(x, y), down)time.sleep(sleeptime)for y in xrange(1, 6, 2):for x in xrange(0, 8):drag(getNodePos(x, y), down)time.sleep(sleeptime)for x in xrange(2, 7, 2):for y in xrange(0, 8):drag(getNodePos(x, y), left)time.sleep(sleeptime)for x in xrange(1, 6, 2):for y in xrange(0, 8):drag(getNodePos(x, y), left)time.sleep(sleeptime)def getpuzzle():screen device.takeSnapshot()puzzle []for y in xrange(0,7):line []for x in xrange(0,7):line.append(screen.getRawPixelInt(getNodePos(x,y)[0], getNodePos(x,y)[1]))puzzle.append(line)return puzzle# lazy one
def trainedmonkey():x 0y 0do Truepr Truepuzzle getpuzzle()while (x 7):while (y 7):################################# if match patterns, drag up ################################## o o # 0if ((y 0 and x 1 andpuzzle[y][x] puzzle[y-1][x-1] andpuzzle[y][x] puzzle[y-1][x-2]) or# o o# 0(y 0 and x 0 and x 6 andpuzzle[y][x] puzzle[y-1][x-1] andpuzzle[y][x] puzzle[y-1][x1]) or# o o# 0(y 0 and x 5 andpuzzle[y][x] puzzle[y-1][x1] andpuzzle[y][x] puzzle[y-1][x2]) or# o# o## 0(y 2 andpuzzle[y][x] puzzle[y-2][x] andpuzzle[y][x] puzzle[y-3][x])):if pr: print x, y, upif do: drag(getNodePos(x, y), up)return#################################### if match patterns, drag right ##################################### o# o # 0if ((y 1 and x 6 andpuzzle[y][x] puzzle[y-1][x1] andpuzzle[y][x] puzzle[y-2][x1]) or# o# 0# o(y 0 and y 6 and x 6 andpuzzle[y][x] puzzle[y-1][x1] andpuzzle[y][x] puzzle[y1][x1]) or# 0# o# o(y 5 and x 6 andpuzzle[y][x] puzzle[y1][x1] andpuzzle[y][x] puzzle[y2][x1]) or# 0 o o(x 4 andpuzzle[y][x] puzzle[y][x2] andpuzzle[y][x] puzzle[y][x3])):if pr: print x, y, rightif do: drag(getNodePos(x, y), right)return################################### if match patterns, drag down #################################### 0# o oif ((y 6 and x 5 andpuzzle[y][x] puzzle[y1][x1] andpuzzle[y][x] puzzle[y1][x2]) or# 0# o o(y 6 and x 0 and x 6 andpuzzle[y][x] puzzle[y1][x1] andpuzzle[y][x] puzzle[y1][x-1]) or# 0# o o(y 6 and x 1 andpuzzle[y][x] puzzle[y1][x-1] andpuzzle[y][x] puzzle[y1][x-2]) or# 0## o# o(y 4 andpuzzle[y][x] puzzle[y2][x] andpuzzle[y][x] puzzle[y3][x])):if pr: print x, y, downif do: drag(getNodePos(x, y), down)return################################### if match patterns, drag left #################################### 0# o# oif ((y 5 and x 0 andpuzzle[y][x] puzzle[y1][x-1] andpuzzle[y][x] puzzle[y2][x-1]) or# o# 0# o(y 0 and y 6 and x 0 andpuzzle[y][x] puzzle[y-1][x-1] andpuzzle[y][x] puzzle[y1][x-1]) or# o# o# 0(y 1 and x 0 andpuzzle[y][x] puzzle[y-1][x-1] andpuzzle[y][x] puzzle[y-2][x-1]) or# o o 0(x 2 andpuzzle[y][x] puzzle[y][x-2] andpuzzle[y][x] puzzle[y][x-3])):if pr: print x, y, leftif do: drag(getNodePos(x, y), left)returny y 1x x 1y 0def testdrag(x,y):drag(getNodePos(x, y), up)time.sleep(0.5)drag(getNodePos(x, y), right)time.sleep(0.5)drag(getNodePos(x, y), down)time.sleep(0.5)drag(getNodePos(x, y), left)time.sleep(0.5)if __name__ __main__:while True:trainedmonkey()time.sleep(0.1) 代码最后记得多留一行空行不然可能会出错好像是jython的一个bug还是怎样不太清楚