发表回复 
宝石矿——游戏挂机脚本
2014-06-27, 00 : 25
Heart 宝石矿——游戏挂机脚本


此脚本适用于休闲小游戏 宝石矿(Diamond Mine)2.0 版计时模式
游戏下载地址:
http://download.pchome.net/game/puzzle/d...33918.html

这个脚本比较简单,但也有一定的启发性。


代码: (全选)
;// 此脚本适用于休闲小游戏 宝石矿(Diamond Mine)2.0 版计时模式
;// 游戏下载地址:
;// http://download.pchome.net/game/puzzle/download_33918.html
;// 此示例脚本采用了最简单的计算方式,一般可以得到60000至70000的高分 :)


start:
CoordMode, Mouse
CoordMode, Pixel
Goto, 开始挂机
Return


*F4::    ;//重启热键
IfWinExist, %A_ScriptName% ahk_class Notepad
{
  PostMessage, 0x111, 3
  Sleep, 500
}
Reload
Return


;===================================


开始挂机:

WinWait, 宝石矿中文版
WinActivate
WinSet, AlwaysOnTop, On
WinGet, WinID, ID

global map:=[]
Loop, 8
  map[A_Index]:=[]

Loop {
  Sleep, 100

  ;//获取相对窗口坐标
  WinGetPos, winx, winy,,, ahk_id %WinID%
  startX:=winx+232-51, startY:=winy+62-51

  ;//先生成颜色类型数组
  updateFastPixelGetColor()
  Loop, 8 {
    j:=A_Index
    Loop, 8 {
      i:=A_Index
      颜色:=fastPixelGetColor(startX+i*51, startY+j*51)
      类型:=颜色分类(颜色)
      if (类型=-1)
        Continue, 3
      map[j][i]:=类型
    }
  }

  ;//通过操作数组找出成功的移动方案
  if (!检测是否成功()) and 找到移动方案(x, y, 方向)
  {
    x:=startX-winx+x*51
    y:=startY-winy+y*51
    SetControlDelay, -1
    ControlClick, x%x% y%y%, ahk_id %WinID%,,,, NA Pos
    if (方向="上")
      y-=51
    else if (方向="下")
      y+=51
    else if (方向="左")
      x-=51
    else if (方向="右")
      x+=51
    ControlClick, x%x% y%y%, ahk_id %WinID%,,,, NA Pos
  }
}
Return


;===================================


颜色分类(color) {
  b:=(color>>16) & 0xFF
  g:=(color>>8) & 0xFF
  r:=color & 0xFF
  ;//蓝色
  if (b>r*1.5 and b>g*1.5)
    Return, 1
  ;//红色
  if (r>b*1.5 and r>g*1.5 and Abs(b-g)<50)
    Return, 2
  ;//绿色
  if (g>b*1.5 and g>r*1.5)
    Return, 3
  ;//灰色
  if (Abs(r-g)<10 and Abs(r-b)<10)
    Return, 4
  ;//黄色
  if (Abs(r-g)<10 and r>b*1.5)
    Return, 5
  ;//橙色
  if (r>g*1.5 and g>b*1.5)
    Return, 6
  ;//紫色
  if (Abs(r-b)<10 and r>g*1.5)
    Return, 7
  ;//判断不出
  Return, -1
}

检测是否成功() {
  ;//左右横向查看
  Loop, 8 {
    j:=A_Index
    Loop, 6 {
      i:=A_Index
      if (map[j][i]=map[j][i+1] and map[j][i]=map[j][i+2])
        Return, 1
    }
  }
  ;//上下纵向查看
  Loop, 6 {
    j:=A_Index
    Loop, 8 {
      i:=A_Index
      if (map[j][i]=map[j+1][i] and map[j][i]=map[j+2][i])
        Return, 1
    }
  }
  Return, 0
}


找到移动方案(byref x, byref y, byref 方向) {
  Loop, 8 {
    ;//从最下面开始消除
    j:=8+1-A_Index
    Loop, 8 {
      i:=A_Index
      ;---- 每个点进行四次尝试 ------
      ;//向左交换
      if (i>1) {
        tmp:=map[j][i]
        map[j][i]:=map[j][i-1]
        map[j][i-1]:=tmp
        if (检测是否成功()) {
          x:=i, y:=j, 方向:="左"
          Return, 1
        } else {
          tmp:=map[j][i]
          map[j][i]:=map[j][i-1]
          map[j][i-1]:=tmp
        }
      }
      ;//向右交换
      if (i<8) {
        tmp:=map[j][i]
        map[j][i]:=map[j][i+1]
        map[j][i+1]:=tmp
        if (检测是否成功()) {
          x:=i, y:=j, 方向:="右"
          Return, 1
        } else {
          tmp:=map[j][i]
          map[j][i]:=map[j][i+1]
          map[j][i+1]:=tmp
        }
      }
      ;//向上交换
      if (j>1) {
        tmp:=map[j][i]
        map[j][i]:=map[j-1][i]
        map[j-1][i]:=tmp
        if (检测是否成功()) {
          x:=i, y:=j, 方向:="上"
          Return, 1
        } else {
          tmp:=map[j][i]
          map[j][i]:=map[j-1][i]
          map[j-1][i]:=tmp
        }
      }
      ;//向下交换
      if (j<8) {
        tmp:=map[j][i]
        map[j][i]:=map[j+1][i]
        map[j+1][i]:=tmp
        if (检测是否成功()) {
          x:=i, y:=j, 方向:="下"
          Return, 1
        } else {
          tmp:=map[j][i]
          map[j][i]:=map[j+1][i]
          map[j+1][i]:=tmp
        }
      }
      ;--------------------------
    }
  }
  Return, 0
}


;================================================



fastPixelGetColor(x, y) {
   global fastPixelGetColorBufferDC, fastPixelGetColorReady, fastPixelGetColorWait
   global fastPixelGetColorScreenLeft, fastPixelGetColorScreenTop
   if fastPixelGetColorWait =
      fastPixelGetColorWait = 1
   ; check if there is a valid data buffer
   if (!fastPixelGetColorReady) {
      if (fastPixelGetColorWait) {
         Start := A_TickCount
         While !fastPixelGetColorReady {
            Sleep, 10
            if (A_TickCount - Start > 5000)
               return -3   ; time out if data is not ready after 5 seconds
         }
      }
      else
         return -2   ; return an invalid color if waiting is disabled
   }
   return DllCall("GetPixel", "Uint", fastPixelGetColorBufferDC
   , "int", x - fastPixelGetColorScreenLeft
   , "int", y - fastPixelGetColorScreenTop)
}

updateFastPixelGetColor() {
   global fastPixelGetColorReady, fastPixelGetColorBufferDC
   static oldObject = 0, hBuffer = 0
   static screenWOld = 0, screenHOld = 0
   ; get screen dimensions
   global fastPixelGetColorScreenLeft, fastPixelGetColorScreenTop
   SysGet, fastPixelGetColorScreenLeft, 76
   SysGet, fastPixelGetColorScreenTop, 77
   SysGet, screenW, 78
   SysGet, screenH, 79
   fastPixelGetColorReady = 0
   ; determine whether the old buffer can be reused
   bufferInvalid := screenW <> screenWOld OR screenH <> screenHOld
   OR fastPixelGetColorBufferDC = 0 OR hBuffer = 0
   screenWOld := screenW
   screenHOld := screenH
   if (bufferInvalid) {
      ; cleanly discard the old buffer
      DllCall("SelectObject", "Uint", fastPixelGetColorBufferDC, "Uint", oldObject)
      DllCall("DeleteDC", "Uint", fastPixelGetColorBufferDC)
      DllCall("DeleteObject", "Uint", hBuffer)
      ; create a new empty buffer
      fastPixelGetColorBufferDC := DllCall("CreateCompatibleDC", "Uint", 0)
      hBuffer := CreateDIBSection(fastPixelGetColorBufferDC, screenW, screenH)
      oldObject := DllCall("SelectObject", "Uint", fastPixelGetColorBufferDC, "Uint", hBuffer)
   }
   screenDC := DllCall("GetDC", "Uint", 0)
   ; retrieve the whole screen into the newly created buffer
   DllCall("BitBlt", "Uint", fastPixelGetColorBufferDC, "int", 0, "int"
   , 0, "int", screenW, "int", screenH, "Uint", screenDC, "int"
   , fastPixelGetColorScreenLeft, "int", fastPixelGetColorScreenTop
   , "Uint", 0x40000000 | 0x00CC0020)
   ; important: release the DC of the screen
   DllCall("ReleaseDC", "Uint", 0, "Uint", screenDC)
   fastPixelGetColorReady = 1
}

CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "") {
   NumPut(VarSetCapacity(bi, 40, 0), bi)
   NumPut(nW, bi, 4)
   NumPut(nH, bi, 8)
   NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
   NumPut(0,  bi,16)
   Return DllCall("gdi32\CreateDIBSection", "Uint", hDC
   , "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}
查找这个用户的全部帖子
表示感谢 引用并回复 移动视图置页面顶端
2014-11-17, 09 : 18
RE: 宝石矿——游戏挂机脚本
谢谢提供!!!
查找这个用户的全部帖子
表示感谢 引用并回复 移动视图置页面顶端
发表回复 


论坛跳转:


联系我们 | Autohotkey 中文站 | 回到顶部 | 回到正文区 | 精简(归档)模式 | RSS 聚合