Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.57 KB | None | 0 0
  1. DllCall("dwmapi.dll", "uint", "DwmEnableComposition", "int", 0)
  2.  
  3. Global $boardPos[2]
  4. Global $board[8][8]
  5.  
  6. Global Const $ChkSumArea         = 3
  7. Global Const $YellowNormalChkSum = 3359205046
  8. Global Const $WhiteNormalChkSum  = 1271433909
  9. Global Const $PurpleNormalChkSum = 4095892250
  10. Global Const $OrangeNormalChkSum = 3393413352
  11. Global Const $GreenNormalChkSum  = 4132258909
  12. Global Const $BlueNormalChkSum   = 2991081477
  13. Global Const $RedNormalChkSum    = 4223680673
  14.  
  15. Global Const $YellowNormal = 0
  16. Global Const $WhiteNormal  = 1
  17. Global Const $PurpleNormal = 2
  18. Global Const $OrangeNormal = 3
  19. Global Const $GreenNormal  = 4
  20. Global Const $BlueNormal   = 5
  21. Global Const $RedNormal    = 6
  22. Global Const $UnknownGem   = 7
  23.  
  24. Global Const $Right = 0
  25. Global Const $Up    = 1
  26. Global Const $Left  = 2
  27. Global Const $Down  = 3
  28.  
  29. Global $loop = True
  30.  
  31. Global Const $GemNames[8] = ["YellowNormal", _
  32.                              "WhiteNormal", _
  33.                              "PurpleNormal", _
  34.                              "OrangeNormal", _
  35.                              "GreenNormal", _
  36.                              "BlueNormal", _
  37.                              "RedNormal", _
  38.                              "UnknownGem"]
  39.  
  40. ;
  41. ;   ...
  42. ;   ...
  43. ;   ....
  44. ;
  45. Func FindNearestGemPos($pos)
  46.     Local $dir = 0
  47.     Local $step = 1
  48.     While PosGetGem($pos) == $UnknownGem And $loop
  49.         Switch $dir
  50.         Case 0
  51.             For $i = 1 To $step
  52.                 $pos[0] = $pos[0] + 1
  53.                 If PosGetGem($pos) <> $UnknownGem Then
  54.                     Return $pos
  55.                 EndIf
  56.             Next
  57.             $dir = 1
  58.         Case 1
  59.             For $i = 1 To $step
  60.                 $pos[1] = $pos[1] - 1
  61.                 If PosGetGem($pos) <> $UnknownGem Then
  62.                     Return $pos
  63.                 EndIf
  64.             Next
  65.             $dir = 2
  66.             $step = $step + 1
  67.         Case 2
  68.             For $i = 1 To $step
  69.                 $pos[0] = $pos[0] - 1
  70.                 If PosGetGem($pos) <> $UnknownGem Then
  71.                     Return $pos
  72.                 EndIf
  73.             Next
  74.             $dir = 3
  75.         Case 3
  76.             For $i = 1 To $step
  77.                 $pos[1] = $pos[1] + 1
  78.                 If PosGetGem($pos) <> $UnknownGem Then
  79.                     Return $pos
  80.                 EndIf
  81.             Next
  82.             $dir = 0
  83.             $step = $step + 1
  84.         EndSwitch
  85.         ;MouseMove($pos[0], $pos[1])
  86.         ;Sleep(300)
  87.     Wend
  88.     Return $pos
  89. EndFunc
  90.  
  91. Func FillBoard($pos)
  92.     Local $gemPos[2]
  93.     For $y = 0 To 7
  94.         For $x = 0 To 7
  95.             $gemPos[0] = $pos[0] + $x * 40
  96.             $gemPos[1] = $pos[1] + $y * 40
  97.             $board[$y][$x] = PosGetGem($gemPos)
  98.         Next
  99.     Next
  100. EndFunc
  101.  
  102. Func DisplayBoard()
  103.     For $y = 0 To 7
  104.         For $x = 0 to 7
  105.             ConsoleWrite(StringMid(GemGetName($board[$y][$x]), 1, 1) & " ")
  106.         Next
  107.         ConsoleWrite(@CRLF)
  108.     Next
  109. EndFunc
  110.  
  111. Func PerformMove($x, $y, $dir)
  112.     Local $pos[2]
  113.     $pos[0] = $boardPos[0] + $x * 40
  114.     $pos[1] = $boardPos[1] + $y * 40
  115.     Switch $dir
  116.     Case $Right
  117.         MouseMove($pos[0], $pos[1])
  118.         MouseClickDrag("Left", $pos[0], $pos[1], $pos[0] + 40, $pos[1], 1)
  119.     Case $Up
  120.         MouseMove($pos[0], $pos[1])
  121.         MouseClickDrag("Left", $pos[0], $pos[1], $pos[0], $pos[1] - 40, 1)
  122.     Case $Left
  123.         MouseMove($pos[0], $pos[1])
  124.         MouseClickDrag("Left", $pos[0], $pos[1], $pos[0] - 40, $pos[1], 1)
  125.     Case $Down
  126.         MouseMove($pos[0], $pos[1])
  127.         MouseClickDrag("Left", $pos[0], $pos[1], $pos[0], $pos[1] + 40, 1)     
  128.     EndSwitch
  129. EndFunc
  130.  
  131. ; ----
  132. ; x ?
  133. ; x ?
  134. ; ? x
  135. ; ----
  136. ; ? x
  137. ; ? x
  138. ; x ?
  139. ; ----
  140. ; ? x
  141. ; x ?
  142. ; x ?
  143. ; ----
  144. ; x ?
  145. ; ? x
  146. ; ? x
  147. ; ----
  148. ; x ?
  149. ; ? x
  150. ; x ?
  151. ; ----
  152. ; ? x
  153. ; x ?
  154. ; ? x
  155. ; ----
  156. ; x x ?
  157. ; ? ? x
  158. ; ----
  159. ; ? ? x
  160. ; x x ?
  161. ; ----
  162. ; ? x x
  163. ; x ? ?
  164. ; ----
  165. ; x ? ?
  166. ; ? x x
  167. ; ----
  168. ; x ? x
  169. ; ? x ?
  170. ; ----
  171. ; ? x ?
  172. ; x ? x
  173. ; ----
  174. ; x x ? x
  175. ; ----
  176. ; x ? x x
  177. ; ----
  178. ; x
  179. ; x
  180. ; ?
  181. ; x
  182. ; ----
  183. ; x
  184. ; ?
  185. ; x
  186. ; x
  187. Func AiMoveAt($x, $y)
  188.     If $y - 2 >= 0 And $x + 1 <= 7 Then
  189.         If $board[$y][$x + 1] <> $UnknownGem And _
  190.            $board[$y][$x + 1] == $board[$y - 1][$x] And _
  191.            $board[$y][$x + 1] == $board[$y - 2][$x] Then
  192.             PerformMove($x + 1, $y, $Left)
  193.             Return True
  194.         EndIf
  195.         If $board[$y][$x] <> $UnknownGem And _
  196.            $board[$y][$x] == $board[$y - 1][$x + 1] And _
  197.            $board[$y][$x] == $board[$y - 2][$x + 1] Then
  198.             PerformMove($x, $y, $Right)
  199.             Return True
  200.         EndIf
  201.         If $board[$y][$x] <> $UnknownGem And _
  202.            $board[$y][$x] == $board[$y - 1][$x] And _
  203.            $board[$y][$x] == $board[$y - 2][$x + 1] Then
  204.             PerformMove($x + 1, $y - 2, $Left)
  205.             Return True
  206.         EndIf
  207.         If $board[$y][$x + 1] <> $UnknownGem And _
  208.            $board[$y][$x + 1] == $board[$y - 1][$x + 1] And _
  209.            $board[$y][$x + 1] == $board[$y - 2][$x] Then
  210.             PerformMove($x, $y - 2, $Right)
  211.             Return True
  212.         EndIf
  213.         If $board[$y][$x] <> $UnknownGem And _
  214.            $board[$y][$x] == $board[$y - 1][$x + 1] And _
  215.            $board[$y][$x] == $board[$y - 2][$x] Then
  216.             PerformMove($x + 1, $y - 1, $Left)
  217.             Return True
  218.         EndIf
  219.         If $board[$y][$x + 1] <> $UnknownGem And _
  220.            $board[$y][$x + 1] == $board[$y - 1][$x] And _
  221.            $board[$y][$x + 1] == $board[$y - 2][$x + 1] Then
  222.             PerformMove($x, $y - 1, $Right)
  223.             Return True
  224.         EndIf
  225.     EndIf
  226.     If $x + 2 <= 7 And $y - 1 >= 0 Then
  227.         If $board[$y - 1][$x] <> $UnknownGem And _
  228.            $board[$y - 1][$x] == $board[$y - 1][$x + 1] And _
  229.            $board[$y - 1][$x] == $board[$y][$x + 2] Then
  230.             PerformMove($x + 2, $y, $Up)
  231.             Return True
  232.         EndIf
  233.         If $board[$y][$x] <> $UnknownGem And _
  234.            $board[$y][$x] == $board[$y][$x + 1] And _
  235.            $board[$y][$x] == $board[$y - 1][$x + 2] Then
  236.             PerformMove($x + 2, $y - 1, $Down)
  237.             Return True
  238.         EndIf
  239.         If $board[$y][$x] <> $UnknownGem And _
  240.            $board[$y][$x] == $board[$y - 1][$x + 1] And _
  241.            $board[$y][$x] == $board[$y - 1][$x + 2] Then
  242.             PerformMove($x, $y, $Up)
  243.             Return True
  244.         EndIf
  245.         If $board[$y - 1][$x] <> $UnknownGem And _
  246.            $board[$y - 1][$x] == $board[$y][$x + 1] And _
  247.            $board[$y - 1][$x] == $board[$y][$x + 2] Then
  248.             PerformMove($x, $y - 1, $Down)
  249.             Return True
  250.         EndIf
  251.         If $board[$y - 1][$x] <> $UnknownGem And _
  252.            $board[$y - 1][$x] == $board[$y][$x + 1] And _
  253.            $board[$y - 1][$x] == $board[$y - 1][$x + 2] Then
  254.             PerformMove($x + 1, $y, $Up)
  255.             Return True
  256.         EndIf
  257.         If $board[$y][$x] <> $UnknownGem And _
  258.            $board[$y][$x] == $board[$y - 1][$x + 1] And _
  259.            $board[$y][$x] == $board[$y][$x + 2] Then
  260.             PerformMove($x + 1, $y - 1, $Down)
  261.             Return True
  262.         EndIf
  263.     EndIf
  264.     If $x + 3 <= 7 Then
  265.         If $board[$y][$x] <> $UnknownGem And _
  266.            $board[$y][$x] == $board[$y][$x + 1] And _
  267.            $board[$y][$x] == $board[$y][$x + 3] Then
  268.             PerformMove($x + 3, $y, $Left)
  269.             Return True
  270.         EndIf
  271.         If $board[$y][$x] <> $UnknownGem And _
  272.            $board[$y][$x] == $board[$y][$x + 2] And _
  273.            $board[$y][$x] == $board[$y][$x + 3] Then
  274.             PerformMove($x, $y, $Right)
  275.             Return True
  276.         EndIf
  277.     EndIf
  278.     If $y - 3 >= 0 Then
  279.         If $board[$y][$x] <> $UnknownGem And _
  280.            $board[$y][$x] == $board[$y - 2][$x] And _
  281.            $board[$y][$x] == $board[$y - 3][$x] Then
  282.             PerformMove($x, $y, $Up)
  283.             Return True
  284.         EndIf
  285.         If $board[$y][$x] <> $UnknownGem And _
  286.            $board[$y][$x] == $board[$y - 1][$x] And _
  287.            $board[$y][$x] == $board[$y - 3][$x] Then
  288.             PerformMove($x, $y - 3, $Down)
  289.             Return True
  290.         EndIf
  291.     EndIf
  292.     Return False
  293. EndFunc
  294.  
  295. Func AiMove()
  296.     FillBoard($boardPos)
  297.     For $y = 7 To 0 Step -1
  298.         For $x = 0 To 7
  299.             If AiMoveAt($x, $y) Then
  300.                 Return True
  301.             EndIf
  302.         Next
  303.     Next
  304.     Return False
  305. EndFunc
  306.  
  307. Func GemGetName($gem)
  308.     Return $GemNames[$gem]
  309. EndFunc
  310.  
  311. Func PosGetGem($pos)
  312.     Local $chksum
  313.     $chksum = PixelChecksum($pos[0] - $ChkSumArea, $pos[1] - $ChkSumArea, $pos[0] + $ChkSumArea, $pos[1] + $ChkSumArea)
  314.     Switch $chksum
  315.     Case $YellowNormalChkSum
  316.         Return $YellowNormal
  317.     Case $WhiteNormalChkSum
  318.         Return $WhiteNormal
  319.     Case $PurpleNormalChkSum
  320.         Return $PurpleNormal
  321.     Case $OrangeNormalChkSum
  322.         Return $OrangeNormal
  323.     Case $GreenNormalChkSum
  324.         Return $GreenNormal
  325.     Case $BlueNormalChkSum
  326.         Return $BlueNormal
  327.     Case $RedNormalChkSum
  328.         Return $RedNormal
  329.     Case Else
  330.         Return $UnknownGem
  331.     EndSwitch
  332. EndFunc
  333.  
  334. Local $hwnd
  335.  
  336. $hwnd = WinGetHandle("Bejeweled Blitz on Facebook")
  337.  
  338. If @error Then
  339.     MsgBox(0, "Error", 'Could not see the "Bejeweled Blitz on Facebook" window');
  340.     Exit
  341. EndIf
  342.  
  343. HotKeySet("!z", "DoIt")
  344. HotKeySet("!x", "DoIt2")
  345. HotKeySet("!c", "DoIt3")
  346. HotKeySet("!v", "DoIt4")
  347. HotKeySet("!a", "BotGame")
  348. HotKeySet("!s", "PauseToggle")
  349.  
  350. Global $pause = False
  351.  
  352. Func PauseToggle()
  353.     $pause = Not $pause
  354.     While $pause
  355.         Sleep(200)
  356.     Wend
  357. EndFunc
  358.  
  359. Func DoIt()
  360.     Local $pos = MouseGetPos()
  361.     $loop = False
  362.     Exit
  363. EndFunc
  364.  
  365. Func DoIt2()
  366.     Local $pos = MouseGetPos()
  367.     $pos[0] = $pos[0] + 40
  368.     MouseMove($pos[0], $pos[1])
  369.     If PosGetGem($pos) == $UnknownGem Then
  370.         $pos[0] = $pos[0] - 8*40
  371.         $pos[1] = $pos[1] + 40
  372.         If PosGetGem($pos) == $UnknownGem Then
  373.             $pos[1] = $pos[1] - 8*40
  374.         EndIf
  375.         MouseMove($pos[0], $pos[1])
  376.     EndIf
  377. EndFunc
  378.  
  379. Func DoIt3()
  380.     Local $pos = MouseGetPos()
  381.     $pos = FindNearestGemPos($pos)
  382.     MouseMove($pos[0], $pos[1])
  383. EndFunc
  384.  
  385. Func DoIt4()
  386.     Local $pos = MouseGetPos()
  387.     $pos = FindNearestGemPos($pos)
  388.     MouseMove($pos[0], $pos[1])
  389.     $boardPos = $pos
  390.     Local $t = TimerInit()
  391.     FillBoard($pos)
  392.     $t = TimerDiff($t)
  393.     DisplayBoard()
  394.     ConsoleWrite("Took " & $t & " milliseconds to scan" & @CRLF)
  395.     ;MsgBox(0, "Info", "Took " & $t & " milliseconds to scan" & @CRLF)
  396. EndFunc
  397.  
  398. Func BotGame()
  399.     Local $noMoveCount = 0
  400.     $boardPos = FindNearestGemPos(MouseGetPos())
  401.     While $loop
  402.         If AiMove() Then
  403.             $noMoveCount = 0
  404.         Else
  405.             $noMoveCount = $noMoveCount + 1
  406.         EndIf
  407.         Sleep(100)
  408.         If $noMoveCount > 30 Then
  409.             Local $allUnknown = True
  410.             For $y = 0 To 7
  411.                 For $x = 0 to 7
  412.                     If $board[$y][$x] <> $UnknownGem Then
  413.                         $allUnknown = False
  414.                         ExitLoop
  415.                     EndIf
  416.                 Next
  417.                 If Not $allUnknown Then
  418.                     ExitLoop
  419.                 EndIf
  420.             Next
  421.             If $allUnknown Then
  422.                 MouseClick("Left", $boardPos[0] + 100, $boardPos[1] + 270)
  423.             EndIf
  424.         EndIf
  425.     WEnd
  426. EndFunc
  427.  
  428. While $loop
  429.     Sleep(200)
  430.     ;Local $pos = MouseGetPos()
  431.     ;ToolTip(GemGetName(PosGetGem($pos)), 50, 50)
  432. Wend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement