程序员玩游戏之三--天天爱消除非暴力脚本

来源:互联网 发布:如何测量三围知乎 编辑:程序博客网 时间:2024/04/28 03:10

      评论:        此款游戏成功在其好友排名上。好友的分数超过了你无疑会增加你的斗志。

      中级策略:七手八脚多人一起点。这相当于多个CPU处理一个大任务了,哈哈。

      终极策略:自动化。机器总是比人快的多。你两个人一秒充其量点4下,而机器的数量级至少是10以上吧。

 

      本人编写的是LUA脚本(CSDN语言中没有LUA这门,所以才用的python格式上传的),只适用于iphone4及4s, iphone5分辨率不同于4也可能用不了,对此没测试过。其他平台有兴趣的自己改吧。把LUA脚本导入触摸精灵中修改循环次数为0间隔时间为0,开始游戏按下音量键即可使用。

      脚本中都有详细的注释,即使是初学编程的人应该也会明白的。故不再解释。

      如想试试此脚本的最大功率,建议

            1. 关闭除触摸精灵及天天爱消除之外的其他所有程序(减少系统调度开销时间&释放更多内存)

            2. 等闪烁的动物有4个左右时统一触摸消除。

            3. 注意有无找不到消除的情况发生。如有人工消除几个即可。

 

  脚本本来上传到资源里,但好像被CSDN删除了!不知违反了什么规定!大家还是拷贝复制吧。

--/********************************************************-- * AUTHOR: 翟敏                                         *-- * TIME  : 2013-08-26 20:07                            *-- * MAIL  : zhaimin.cn@gmail.com                         *-- ********************************************************/-- 注意:适用iphone4及iphone4s. iphone5没测试过。SCREEN_RESOLUTION="640x960";SCREEN_COLOR_BITS=32;WIDTH=7;--横竖都是7个动物HEIGHT=7;START_X=5;--左上角第一个动物的像素坐标为(5,208)START_Y=208;ANIMAL_SIZE=90;--每个动物大小为90*90个像素-- 二维数组,记录分析出来的各种动物。animals = {}animals[0]={}animals[1]={}animals[2]={}animals[3]={}animals[4]={}animals[5]={}animals[6]={}-- 各种动物枚举。有些动物真不知道叫什么!汗!UNKNOWN=0PURPLE=1PANDA=2BROWNBEAR=3GREEN=4DUCK=5BLUE=6RED=7-- 抓屏。按特殊点判断是什么动物。function fillAnimalTable()    x = 0    y = 0    keepScreen(true) --加快效率。不连续抓屏,只捉一次。    for i=0,6,1 do        for j=0,6,1 do            x = START_X+i*ANIMAL_SIZE+79            y = START_Y+j*ANIMAL_SIZE+53            animals[i][j]=UNKNOWN            c=getColor(x,y)            if (c==0x8262B0) then animals[i][j]=PURPLE            elseif (c==0xCACACA) then animals[i][j]=PANDA            elseif (c==0xD1683A) then animals[i][j]=BROWNBEAR            elseif (c==0x3B4642 or c==0x343E3A) then animals[i][j]=GREEN            elseif (c==0x69552E or c==0x6E5B33) then animals[i][j]=DUCK            elseif (c==0x1C1F2A or c==0x252833) then animals[i][j]=BLUE            elseif (c==0x97626E or c==0x945E6B) then animals[i][j]=RED            end        end    end    keepScreen(false)end-- 游戏是否开始中?function isProcessing()    unkouwn_count=WIDTH*HEIGHT -- 未知动物个数。如太多认为游戏没开始,暂停触控    for i=0,6,1 do        for j=0,6,1 do            if animals[i][j]~=UNKNOWN then unkouwn_count=unkouwn_count-1 end        end    end    return unkouwn_count<WIDTH*HEIGHT/2end-- 把二维坐标(i,j)的动物拉到(i+deltax,j+deltay)function moveAnimal(i,j,deltax,deltay)    touchDown(9, START_X+i*ANIMAL_SIZE+ANIMAL_SIZE/2, START_Y+j*ANIMAL_SIZE+ANIMAL_SIZE/2)    mSleep(0);    touchMove(9, START_X+(i+deltax)*ANIMAL_SIZE+ANIMAL_SIZE/2, START_Y+(j+deltay)*ANIMAL_SIZE+ANIMAL_SIZE/2)    mSleep(0);    touchUp(9)end-- 按一下正在闪烁的动物,把同种颜色的消掉function removeShanShuoAnimals()    for i=0,6,1 do        for j=0,6,1 do            touchDown(9, START_X+i*ANIMAL_SIZE+ANIMAL_SIZE/2, START_Y+j*ANIMAL_SIZE+ANIMAL_SIZE/2)            touchUp(9)        end    endend-- 主入口function main()    rotateScreen(0);    --mSleep(0);        fillAnimalTable()    if not isProcessing() then return end        --各种可以移动的情况都找出来,从上到下找避免影响二维数组。先消下面的会改变上面的情况!    for j=0,6,1 do        for i=0,6,1 do            if ( animals[i][j]~=UNKNOWN) then --只凭一个点位可能确定不出来是什么动物,比如那个点位正好被特效盖住了。                if (i - 1 >= 0 and j - 1 >= 0 and animals[i][j]==(animals[i - 1][j - 1])) then                     if (i - 2 >= 0 and animals[i][j]==(animals[i - 2][j - 1]))  then moveAnimal(i, j, 0, -1); end                    if (j - 2 >= 0 and animals[i][j]==(animals[i - 1][j - 2]))  then moveAnimal(i, j, -1, 0); end                    if (j + 1 < WIDTH and animals[i][j]==(animals[i - 1][j + 1]))  then moveAnimal(i, j, -1, 0); end                end                if (i - 1 >= 0 and j + 1 < WIDTH and animals[i][j]==(animals[i - 1][j + 1])) then                     if (i - 2 >= 0 and animals[i][j]==(animals[i - 2][j + 1]))  then moveAnimal(i, j, 0, 1); end                    if (j + 2 < WIDTH and animals[i][j]==(animals[i - 1][j + 2]))  then moveAnimal(i, j, -1, 0); end                    if (i + 1 < HEIGHT and animals[i][j]==(animals[i + 1][j + 1]))  then moveAnimal(i, j, 0, 1); end                end                if (i + 1 < HEIGHT and j + 1 < WIDTH and animals[i][j]==(animals[i + 1][j + 1])) then                     if (i + 2 < HEIGHT and animals[i][j]==(animals[i + 2][j + 1]))  then moveAnimal(i, j, 0, 1); end                    if (j + 2 < WIDTH and animals[i][j]==(animals[i + 1][j + 2]))  then moveAnimal(i, j, 1, 0); end                    if (j - 1 >= 0 and animals[i][j]==(animals[i + 1][j - 1]))  then moveAnimal(i, j, 1, 0); end                end                if (i + 1 < HEIGHT and j - 1 >= 0 and animals[i][j]==(animals[i + 1][j - 1])) then                     if (i + 2 < HEIGHT and animals[i][j]==(animals[i + 2][j - 1]))  then moveAnimal(i, j, 0, -1); end                    if (j - 2 >= 0 and animals[i][j]==(animals[i + 1][j - 2]))  then moveAnimal(i, j, 1, 0); end                    if (i - 1 >= 0 and animals[i][j]==(animals[i - 1][j - 1]))  then moveAnimal(i, j, 0, -1); end                end                if (i - 2 >= 0 and i - 3 >= 0 and animals[i][j]==(animals[i - 2][j]) and animals[i][j]==(animals[i - 3][j]))  then moveAnimal(i, j, -1, 0); end                if (j - 2 >= 0 and j - 3 >= 0 and animals[i][j]==(animals[i][j - 2]) and animals[i][j]==(animals[i][j - 3]))  then moveAnimal(i, j, 0, -1); end                if (i + 2 < HEIGHT and i + 3 < HEIGHT and animals[i][j]==(animals[i + 2][j]) and animals[i][j]==(animals[i + 3][j]))  then moveAnimal(i, j, 1, 0); end                if (j + 2 < WIDTH and j + 3 < WIDTH and animals[i][j]==(animals[i][j + 2]) and animals[i][j]==(animals[i][j + 3]))  then moveAnimal(i, j, 0, 1); end            end        end    end        --removeShanShuoAnimals()    mSleep(0);end


 

 

    下面玩了几局的截图,有图有真相!

最高分,但腾讯给算成25000,排名倒数了。

 

原创粉丝点击