Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DllCall("dwmapi.dll", "uint", "DwmEnableComposition", "int", 0)
- Global $boardPos[2]
- Global $board[8][8]
- Global Const $ChkSumArea = 3
- Global Const $YellowNormalChkSum = 3359205046
- Global Const $WhiteNormalChkSum = 1271433909
- Global Const $PurpleNormalChkSum = 4095892250
- Global Const $OrangeNormalChkSum = 3393413352
- Global Const $GreenNormalChkSum = 4132258909
- Global Const $BlueNormalChkSum = 2991081477
- Global Const $RedNormalChkSum = 4223680673
- Global Const $YellowNormal = 0
- Global Const $WhiteNormal = 1
- Global Const $PurpleNormal = 2
- Global Const $OrangeNormal = 3
- Global Const $GreenNormal = 4
- Global Const $BlueNormal = 5
- Global Const $RedNormal = 6
- Global Const $UnknownGem = 7
- Global Const $Right = 0
- Global Const $Up = 1
- Global Const $Left = 2
- Global Const $Down = 3
- Global $loop = True
- Global Const $GemNames[8] = ["YellowNormal", _
- "WhiteNormal", _
- "PurpleNormal", _
- "OrangeNormal", _
- "GreenNormal", _
- "BlueNormal", _
- "RedNormal", _
- "UnknownGem"]
- ;
- ; ...
- ; ...
- ; ....
- ;
- Func FindNearestGemPos($pos)
- Local $dir = 0
- Local $step = 1
- While PosGetGem($pos) == $UnknownGem And $loop
- Switch $dir
- Case 0
- For $i = 1 To $step
- $pos[0] = $pos[0] + 1
- If PosGetGem($pos) <> $UnknownGem Then
- Return $pos
- EndIf
- Next
- $dir = 1
- Case 1
- For $i = 1 To $step
- $pos[1] = $pos[1] - 1
- If PosGetGem($pos) <> $UnknownGem Then
- Return $pos
- EndIf
- Next
- $dir = 2
- $step = $step + 1
- Case 2
- For $i = 1 To $step
- $pos[0] = $pos[0] - 1
- If PosGetGem($pos) <> $UnknownGem Then
- Return $pos
- EndIf
- Next
- $dir = 3
- Case 3
- For $i = 1 To $step
- $pos[1] = $pos[1] + 1
- If PosGetGem($pos) <> $UnknownGem Then
- Return $pos
- EndIf
- Next
- $dir = 0
- $step = $step + 1
- EndSwitch
- ;MouseMove($pos[0], $pos[1])
- ;Sleep(300)
- Wend
- Return $pos
- EndFunc
- Func FillBoard($pos)
- Local $gemPos[2]
- For $y = 0 To 7
- For $x = 0 To 7
- $gemPos[0] = $pos[0] + $x * 40
- $gemPos[1] = $pos[1] + $y * 40
- $board[$y][$x] = PosGetGem($gemPos)
- Next
- Next
- EndFunc
- Func DisplayBoard()
- For $y = 0 To 7
- For $x = 0 to 7
- ConsoleWrite(StringMid(GemGetName($board[$y][$x]), 1, 1) & " ")
- Next
- ConsoleWrite(@CRLF)
- Next
- EndFunc
- Func PerformMove($x, $y, $dir)
- Local $pos[2]
- $pos[0] = $boardPos[0] + $x * 40
- $pos[1] = $boardPos[1] + $y * 40
- Switch $dir
- Case $Right
- MouseMove($pos[0], $pos[1])
- MouseClickDrag("Left", $pos[0], $pos[1], $pos[0] + 40, $pos[1], 1)
- Case $Up
- MouseMove($pos[0], $pos[1])
- MouseClickDrag("Left", $pos[0], $pos[1], $pos[0], $pos[1] - 40, 1)
- Case $Left
- MouseMove($pos[0], $pos[1])
- MouseClickDrag("Left", $pos[0], $pos[1], $pos[0] - 40, $pos[1], 1)
- Case $Down
- MouseMove($pos[0], $pos[1])
- MouseClickDrag("Left", $pos[0], $pos[1], $pos[0], $pos[1] + 40, 1)
- EndSwitch
- EndFunc
- ; ----
- ; x ?
- ; x ?
- ; ? x
- ; ----
- ; ? x
- ; ? x
- ; x ?
- ; ----
- ; ? x
- ; x ?
- ; x ?
- ; ----
- ; x ?
- ; ? x
- ; ? x
- ; ----
- ; x ?
- ; ? x
- ; x ?
- ; ----
- ; ? x
- ; x ?
- ; ? x
- ; ----
- ; x x ?
- ; ? ? x
- ; ----
- ; ? ? x
- ; x x ?
- ; ----
- ; ? x x
- ; x ? ?
- ; ----
- ; x ? ?
- ; ? x x
- ; ----
- ; x ? x
- ; ? x ?
- ; ----
- ; ? x ?
- ; x ? x
- ; ----
- ; x x ? x
- ; ----
- ; x ? x x
- ; ----
- ; x
- ; x
- ; ?
- ; x
- ; ----
- ; x
- ; ?
- ; x
- ; x
- Func AiMoveAt($x, $y)
- If $y - 2 >= 0 And $x + 1 <= 7 Then
- If $board[$y][$x + 1] <> $UnknownGem And _
- $board[$y][$x + 1] == $board[$y - 1][$x] And _
- $board[$y][$x + 1] == $board[$y - 2][$x] Then
- PerformMove($x + 1, $y, $Left)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 1][$x + 1] And _
- $board[$y][$x] == $board[$y - 2][$x + 1] Then
- PerformMove($x, $y, $Right)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 1][$x] And _
- $board[$y][$x] == $board[$y - 2][$x + 1] Then
- PerformMove($x + 1, $y - 2, $Left)
- Return True
- EndIf
- If $board[$y][$x + 1] <> $UnknownGem And _
- $board[$y][$x + 1] == $board[$y - 1][$x + 1] And _
- $board[$y][$x + 1] == $board[$y - 2][$x] Then
- PerformMove($x, $y - 2, $Right)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 1][$x + 1] And _
- $board[$y][$x] == $board[$y - 2][$x] Then
- PerformMove($x + 1, $y - 1, $Left)
- Return True
- EndIf
- If $board[$y][$x + 1] <> $UnknownGem And _
- $board[$y][$x + 1] == $board[$y - 1][$x] And _
- $board[$y][$x + 1] == $board[$y - 2][$x + 1] Then
- PerformMove($x, $y - 1, $Right)
- Return True
- EndIf
- EndIf
- If $x + 2 <= 7 And $y - 1 >= 0 Then
- If $board[$y - 1][$x] <> $UnknownGem And _
- $board[$y - 1][$x] == $board[$y - 1][$x + 1] And _
- $board[$y - 1][$x] == $board[$y][$x + 2] Then
- PerformMove($x + 2, $y, $Up)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y][$x + 1] And _
- $board[$y][$x] == $board[$y - 1][$x + 2] Then
- PerformMove($x + 2, $y - 1, $Down)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 1][$x + 1] And _
- $board[$y][$x] == $board[$y - 1][$x + 2] Then
- PerformMove($x, $y, $Up)
- Return True
- EndIf
- If $board[$y - 1][$x] <> $UnknownGem And _
- $board[$y - 1][$x] == $board[$y][$x + 1] And _
- $board[$y - 1][$x] == $board[$y][$x + 2] Then
- PerformMove($x, $y - 1, $Down)
- Return True
- EndIf
- If $board[$y - 1][$x] <> $UnknownGem And _
- $board[$y - 1][$x] == $board[$y][$x + 1] And _
- $board[$y - 1][$x] == $board[$y - 1][$x + 2] Then
- PerformMove($x + 1, $y, $Up)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 1][$x + 1] And _
- $board[$y][$x] == $board[$y][$x + 2] Then
- PerformMove($x + 1, $y - 1, $Down)
- Return True
- EndIf
- EndIf
- If $x + 3 <= 7 Then
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y][$x + 1] And _
- $board[$y][$x] == $board[$y][$x + 3] Then
- PerformMove($x + 3, $y, $Left)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y][$x + 2] And _
- $board[$y][$x] == $board[$y][$x + 3] Then
- PerformMove($x, $y, $Right)
- Return True
- EndIf
- EndIf
- If $y - 3 >= 0 Then
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 2][$x] And _
- $board[$y][$x] == $board[$y - 3][$x] Then
- PerformMove($x, $y, $Up)
- Return True
- EndIf
- If $board[$y][$x] <> $UnknownGem And _
- $board[$y][$x] == $board[$y - 1][$x] And _
- $board[$y][$x] == $board[$y - 3][$x] Then
- PerformMove($x, $y - 3, $Down)
- Return True
- EndIf
- EndIf
- Return False
- EndFunc
- Func AiMove()
- FillBoard($boardPos)
- For $y = 7 To 0 Step -1
- For $x = 0 To 7
- If AiMoveAt($x, $y) Then
- Return True
- EndIf
- Next
- Next
- Return False
- EndFunc
- Func GemGetName($gem)
- Return $GemNames[$gem]
- EndFunc
- Func PosGetGem($pos)
- Local $chksum
- $chksum = PixelChecksum($pos[0] - $ChkSumArea, $pos[1] - $ChkSumArea, $pos[0] + $ChkSumArea, $pos[1] + $ChkSumArea)
- Switch $chksum
- Case $YellowNormalChkSum
- Return $YellowNormal
- Case $WhiteNormalChkSum
- Return $WhiteNormal
- Case $PurpleNormalChkSum
- Return $PurpleNormal
- Case $OrangeNormalChkSum
- Return $OrangeNormal
- Case $GreenNormalChkSum
- Return $GreenNormal
- Case $BlueNormalChkSum
- Return $BlueNormal
- Case $RedNormalChkSum
- Return $RedNormal
- Case Else
- Return $UnknownGem
- EndSwitch
- EndFunc
- Local $hwnd
- $hwnd = WinGetHandle("Bejeweled Blitz on Facebook")
- If @error Then
- MsgBox(0, "Error", 'Could not see the "Bejeweled Blitz on Facebook" window');
- Exit
- EndIf
- HotKeySet("!z", "DoIt")
- HotKeySet("!x", "DoIt2")
- HotKeySet("!c", "DoIt3")
- HotKeySet("!v", "DoIt4")
- HotKeySet("!a", "BotGame")
- HotKeySet("!s", "PauseToggle")
- Global $pause = False
- Func PauseToggle()
- $pause = Not $pause
- While $pause
- Sleep(200)
- Wend
- EndFunc
- Func DoIt()
- Local $pos = MouseGetPos()
- $loop = False
- Exit
- EndFunc
- Func DoIt2()
- Local $pos = MouseGetPos()
- $pos[0] = $pos[0] + 40
- MouseMove($pos[0], $pos[1])
- If PosGetGem($pos) == $UnknownGem Then
- $pos[0] = $pos[0] - 8*40
- $pos[1] = $pos[1] + 40
- If PosGetGem($pos) == $UnknownGem Then
- $pos[1] = $pos[1] - 8*40
- EndIf
- MouseMove($pos[0], $pos[1])
- EndIf
- EndFunc
- Func DoIt3()
- Local $pos = MouseGetPos()
- $pos = FindNearestGemPos($pos)
- MouseMove($pos[0], $pos[1])
- EndFunc
- Func DoIt4()
- Local $pos = MouseGetPos()
- $pos = FindNearestGemPos($pos)
- MouseMove($pos[0], $pos[1])
- $boardPos = $pos
- Local $t = TimerInit()
- FillBoard($pos)
- $t = TimerDiff($t)
- DisplayBoard()
- ConsoleWrite("Took " & $t & " milliseconds to scan" & @CRLF)
- ;MsgBox(0, "Info", "Took " & $t & " milliseconds to scan" & @CRLF)
- EndFunc
- Func BotGame()
- Local $noMoveCount = 0
- $boardPos = FindNearestGemPos(MouseGetPos())
- While $loop
- If AiMove() Then
- $noMoveCount = 0
- Else
- $noMoveCount = $noMoveCount + 1
- EndIf
- Sleep(100)
- If $noMoveCount > 30 Then
- Local $allUnknown = True
- For $y = 0 To 7
- For $x = 0 to 7
- If $board[$y][$x] <> $UnknownGem Then
- $allUnknown = False
- ExitLoop
- EndIf
- Next
- If Not $allUnknown Then
- ExitLoop
- EndIf
- Next
- If $allUnknown Then
- MouseClick("Left", $boardPos[0] + 100, $boardPos[1] + 270)
- EndIf
- EndIf
- WEnd
- EndFunc
- While $loop
- Sleep(200)
- ;Local $pos = MouseGetPos()
- ;ToolTip(GemGetName(PosGetGem($pos)), 50, 50)
- Wend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement