KingGeorge Posted March 9, 2010 Posted March 9, 2010 (edited) Hi allI have made a start on creating my own bejeweled blitz bot, currently available to play on facebook.I have come to a grinding halt because my method of finding the gem colours in order to slde them in the right direction appears to be too cpu hungry and takes too long.Currently the code i have wrote starts at the bottom right gem and moves up the grid from right to left then from left to right, at the moment it is only looking for a three in a row match along a horizontal line. (two blue gems then one red gem then a blue one)Here is an image of the game to help you understand.My linkHere is my code to look at.expandcollapse popupHotKeySet("^!t", "FindTable") HotKeySet("^!m", "MoveToColour") While 1 Sleep(10) wend Func FindTable() $sc = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 1249842) If @error Then sleep(100) Else $oox = $sc[0] $ooy = $sc[1] $ox = $oox + 11 $oy = $ooy + 51 Global $TopLeftX = $ox Global $TopLeftY = $oy Global $BottomRightX = $ox+280 Global $BottomRightY = $oy+280 MouseMove($TopLeftX,$TopLeftY,10) MouseMove($BottomRightX,$BottomRightY,10) EndIf EndFunc ;==>FindTable Func MoveToColour() ;look for match on same line (two on left one on right) For $UpLook = 0 to 280 Step 40 ;MsgBox(0,"Uplook",$UpLook) For $LeftLook = 40 to 200 Step 40 ;MsgBox(0,"Leftlook",$LeftLook) $y = $LeftLook + 80 $ActiveColour = PixelGetColor($BottomRightX-$LeftLook+40,$BottomRightY-$UpLook) ;MouseMove($BottomRightX-$LeftLook+40,$BottomRightY-$UpLook,10) ;MouseMove($BottomRightX-$LeftLook,$BottomRightY-$UpLook,10) ;MouseMove($BottomRightX-$y,$BottomRightY-$UpLook,10) If PixelGetColor($BottomRightX-$LeftLook,$BottomRightY-$UpLook) = $ActiveColour Then If PixelGetColor($BottomRightX-$y,$BottomRightY-$UpLook) = $ActiveColour Then ;MsgBox(0,"Right to left match","Match") MouseClick("Primary",$BottomRightX-$y,$BottomRightY-$UpLook,1) Sleep(10) MouseClick("Primary",$BottomRightX-$y+40,$BottomRightY-$UpLook,1) Sleep(10) EndIf EndIf Next Next ;look for match on same line (two on right one on left) For $UpLook = 0 to 280 Step 40 ;MsgBox(0,"Uplook",$UpLook) For $LeftLook = 240 to 80 Step -40 ;MsgBox(0,"Leftlook",$LeftLook) $y = $LeftLook - 80 $ActiveColour = PixelGetColor($BottomRightX-$LeftLook-40,$BottomRightY-$UpLook) ;MouseMove($BottomRightX-$LeftLook-40,$BottomRightY-$UpLook,10) ;MouseMove($BottomRightX-$LeftLook,$BottomRightY-$UpLook,10) ;MouseMove($BottomRightX-$y,$BottomRightY-$UpLook,10) If PixelGetColor($BottomRightX-$LeftLook,$BottomRightY-$UpLook) = $ActiveColour Then If PixelGetColor($BottomRightX-$y,$BottomRightY-$UpLook) = $ActiveColour Then ;MsgBox(0,"Left to right match","Match") MouseClick("Primary",$BottomRightX-$y,$BottomRightY-$UpLook,1) Sleep(10) MouseClick("Primary",$BottomRightX-$y-40,$BottomRightY-$UpLook,1) Sleep(10) EndIf EndIf Next Next EndFuncYou would need to have the image i have provided open in paint or the game itself open on facebook then use Ctrl+Alt+t to set the grid then Ctrl+Alt+m to run the code.I think i am in need of an entirely new approach too be honest, any suggestions welcomeP.S. Before i go i found this video on utube of someone using autoit to run a bot in the same game but i cant get it to run as fast as he has, take a peek, the autoit code for this video is available through a link on utube. If i could get this working fast i would be happy.My linkMany thanks for looking Edited March 9, 2010 by KingGeorge
everseeker Posted March 9, 2010 Posted March 9, 2010 According to an announcement as old as the Forum itself... If a game's EULA or TOS explicitly mention bots are not allowed, discussing ways to automate that game is not allowed here. Likewise, if a game features an online multiplayer component and you are attempting to automate it, discussion of such bots is not allowed here. If you create a thread to automate a game you need to make sure the game doesn't explicitly forbid it and that it does not feature multiplayer. Any game bot related thread may be closed for any reason. Repeatedly creating threads if your previous thread was closed will result in your removal from the site. Particularly egregious threads that clearly flaunt this announcement will be met with your removal from this site. Play it safe, don't discuss game bots here. Everseeker
everseeker Posted March 9, 2010 Posted March 9, 2010 That being said... I think I'll have a look... from a purely... how to sort color grids... point of view Everseeker
JRowe Posted March 9, 2010 Posted March 9, 2010 It's not multiplayer and automation isn't prohibited. This is pretty safe ground. The bot logic has already been handled by the bot in the youtube video. The only thing needed is a conversion from desktop to online. Use the source for that bot as a reference. From a quick glance, it shouldn't be too difficult. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
KingGeorge Posted March 9, 2010 Author Posted March 9, 2010 Thanks for looking guys, i would not like to break any rules and i will not ignore anything that is said. That being said i would like to get this working, i think that my approach is somewhat backwards. I think what JRowe said makes sense as alot of the work has already been done in the code form the utube video, i just can't quite get to grasps with the logic and why it is working quite slow instead of at the speed at the end of the video. Anyway thanks JRowe and everseeker for looking and i look forward to your suggestions/help. Thanks for looking
everseeker Posted March 9, 2010 Posted March 9, 2010 (edited) Hi all<stuff>P.S. Before i go i found this video on utube of someone using autoit to run a bot in the same game but i cant get it to run as fast as he has, take a peek, the autoit code for this video is available through a link on utube. If i could get this working fast i would be happy.My linkCould do me a favor (or someone...)I kinda have some time on my hands, but there is no way to tunnel thru our company firewall to get YouTube up.... (Well, I could, but the Security types would get all pissy and whine a lot)Can someone clip out the code and post it here? Thanks --------------------------PS, remember to do your "hunting" from the bottom up, and restart after every "success"That allows the best chance for cascade scores Edited March 9, 2010 by everseeker Everseeker
KingGeorge Posted March 9, 2010 Author Posted March 9, 2010 Here is the code from utube. expandcollapse popup#include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> #include <ButtonConstants.au3> #include <Misc.au3> $dll = DllOpen("user32.dll") Global $window = GUICreate("Jewel Thief", 400, 300, 100, 100) Global $graphic = GUICtrlCreateGraphic(20, 20, 20 * 8 + 2 + 9, 20 * 8 + 2 + 9) Global Const $COLORS[7] = ["Red", "Orange", "Yellow", "Green", "Blue", "Purple", "White"] Global $sol[10][10] ;GUICtrlSetColor($graphic, 0) GUISetState(@SW_SHOW) Global $tick = -1 Global $afx = 0, $afy = 0 Global $ox = -1 Global $oy = -1 Global $oox = -1 Global $ooy = -1 Global $status = GUICtrlCreateLabel("", 10, 270, 380, 20) Global $mt[10][10] ; master table Global $tt[10][10] ; temp table GUICtrlSetData($status, "Running") While 1 DoEvents() ; Search GUICtrlSetData($status, "Searching for window") $flag = False While Not $flag DoEvents() ;Sleep(100) FindTable() WEnd GUICtrlSetData($status, "Found blitz window!") ;mousemove(GetBlitzX(1),GetBlitzY(1)) ; GAME LOGIC START $time = True While $time $tick = $tick + 1 ;While _IsPressed("A0", $dll) ; GUICtrlSetData($status, "SHIFT HOLD!") ; Sleep(200) ;WEnd ;GUICtrlSetData($status, "Playing...") ;$c = PixelChecksum($ox, $oy, $ox + 280, $oy + 280, 40) ;Sleep(100) ;While $c <> PixelChecksum($ox, $oy, $ox + 280, $oy + 280, 40) ; GUICtrlSetData($status, "Waiting for window to hold still...") ; Sleep(100) ; $c = PixelChecksum($ox, $oy, $ox + 280, $oy + 280, 40) ;WEnd ;GUICtrlSetData($status, "Updating graphic...") UpdateColors() ;GUICtrlSetData($status, "Playing...") ;Sleep(100) DoEvents() If $tick > 999 Then ;DidTableMove() $tick = 0 EndIf $time = GetIsTimeLeft() WEnd GUICtrlSetData($status, "Out of time! Waiting for Play Again button") While PixelGetColor($ox - 50, $oy + 280) <> 14772916 DoEvents() ClipPut(PixelGetColor($ox - 50, $oy + 280)) ;Sleep(250) WEnd GUICtrlSetData($status, "Waiting for new game to start.") While GetIsInGame() = False Sleep(50) WEnd ; GAME LOGIC END WEnd DllClose($dll) Exit Func GetBlitzX($x) Return $ox + ($x - 1) * 40 EndFunc ;==>GetBlitzX Func GetBlitzY($y) Return $oy + ($y - 1) * 40 + 1 EndFunc ;==>GetBlitzY Func GetIsInGame() If PixelGetColor($ox - 100, $oy + 150) <> 4337712 Then Return False Return True EndFunc ;==>GetIsInGame Func GetIsTimeLeft() If PixelGetColor($ox - 14, $oy + 310) = 4397348 Then Return False EndIf Return True EndFunc ;==>GetIsTimeLeft Func DoEvents() $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then GUIDelete() Exit EndIf EndFunc ;==>DoEvents Func UpdateMasterTable() $flag = False For $y = 1 To 8 For $x = 1 To 8 $nc = PixelGetColor(GetBlitzX($x), GetBlitzY($y)) If $mt[$x][$y] <> $nc Then $flag = True $mt[$x][$y] = $nc EndIf Next Next Return $flag EndFunc ;==>UpdateMasterTable Func UpdateColors() If UpdateMasterTable() = True Then SearchSolutions() ;~ For $y = 1 To 8 ;~ For $x = 1 To 8 ;~ $clr = GetColorFromName(GetColorName($mt[$x][$y])) ;~ If $sol[$x][$y] > 0 Then ;~ GUICtrlSetGraphic($graphic, $GUI_GR_COLOR, $clr, $clr) ;~ Else ;~ GUICtrlSetGraphic($graphic, $GUI_GR_COLOR, $clr, 0) ;~ EndIf ;~ $tx = 21 * ($x - 1) + 2 ;~ $ty = 21 * ($y - 1) + 2 ;~ GUICtrlSetGraphic($graphic, $GUI_GR_RECT, $tx, $ty, 20, 20) ;~ Next ;~ Next ;~ GUICtrlSetGraphic($graphic, $GUI_GR_REFRESH) ;~ UpdateClippy() EndIf EndFunc ;==>UpdateColors Func FindTable() ;~ $co = "="&chr(13)&chr(10) ;~ For $v = 350 To 733 ;~ For $u = 280 To 788 ;~ $flag = False ;~ $fcolor = PixelGetColor($u, $v) ;~ $fcount = 0 ;~ If Not $fcolor = 0 Then ;~ For $y = 350 To 733 ;~ For $x = 280 To 788 ;~ If PixelGetColor($x, $y) = $fcolor Then ;~ $fcount = $fcount + 1 ;~ If $fcount > 1 Then $flag = True ;~ EndIf ;~ If $flag = True Then ExitLoop ;~ Next ;~ GUICtrlSetData($status, "Finding: (" & $u & "," & $v & "," & $x & "," & $y & ") " & $fcount & " " & $fcolor) ;~ If $flag = True Then ExitLoop ;~ Next ;~ If $fcount = 1 Then ;~ Beep(1000, 1) ;~ mousemove($u,$v) ;~ $co =$co+ $u & ", " & $v & ", " & $fcolor & Chr(13) & Chr(10) ;~ ClipPut($co) ;~ EndIf ;~ EndIf ;~ Next ;~ Next ;~ Exit $sc = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 1249842) If @error Then GUICtrlSetData($status, "Still searching for blitz window...") DoEvents() Else $oox = $sc[0] $ooy = $sc[1] $ox = $oox + 11 $oy = $ooy + 51 ;~ mousemove($oox,$ooy,10) ;~ sleep(100) ;~ mousemove($ox,$oy,10) ;~ Exit $flag = True EndIf EndFunc ;==>FindTable Func DidTableMove() If PixelGetColor($oox, $ooy) <> 1249842 Then Sleep(100) FindTable() EndIf EndFunc ;==>DidTableMove Func UpdateClippy() Return $o = "" For $y = 1 To 8 $o = $o & GetColorName($mt[1][$y]) For $x = 2 To 8 $o = $o & "," & GetColorName($mt[$x][$y]) Next $o = $o & Chr(13) & Chr(10) Next ClipPut($o) EndFunc ;==>UpdateClippy Func GetColorName($c) Select Case $c = 1091362 Return "Green" Case $c = 15198183 Return "White" Case $c = 15362338 Return "Orange" Case $c = 16709156 Return "Yellow" Case $c = 16456503 Return "Red" Case $c = 15798257 Return "Purple" Case $c = 1150206 Return "Blue" Case $c = 0 Return "Black" Case Else Return "Unknown" EndSelect EndFunc ;==>GetColorName Func GetColorFromName($c) Select Case $c = "Green" Return 065280 Case $c = "White" Return 016777215 Case $c = "Orange" Return 016744192 Case $c = "Yellow" Return 016776960 Case $c = "Red" Return 016711680 Case $c = "Purple" Return 016711935 Case $c = "Blue" Return 0255 Case $c = "Black" Return 0 Case Else Return 0 EndSelect EndFunc ;==>GetColorFromName Func SearchSolutions() SearchValidMoves() If Not SearchFiveInARow() Then If Not SearchFiveLShape() Then If Not SearchFutureFiveInARow() Then If Not SearchFutureFiveLShape() Then If Not SearchFutureFourInARow() Then If Not SearchFourInARow() Then SearchForAThree() EndIf EndIf EndIf EndIf EndIf EndIf EndFunc ;==>SearchSolutions Func SearchValidMoves() ;Clear Solution Table EndFunc ;==>SearchValidMoves Func SearchFiveInARow() Return False EndFunc ;==>SearchFiveInARow Func SearchFiveLShape() Return False EndFunc ;==>SearchFiveLShape Func SearchFourInARow() Return False EndFunc ;==>SearchFourInARow Func SearchFutureFiveInARow() Return False EndFunc ;==>SearchFutureFiveInARow Func SearchFutureFiveLShape() Return False EndFunc ;==>SearchFutureFiveLShape Func SearchFutureFourInARow() Return False EndFunc ;==>SearchFutureFourInARow Func SearchForAThree() LoadTT() $flag = False $rr = 6 If $tick > 0 Then $rr = 1 For $y = $rr To 8 For $x = 1 To 8 $sol[$x][$y] = 0 If GetColorName($tt[$x][$y]) <> "Black" And GetColorName($tt[$x][$y]) <> "Unknown" Then If $x < 8 And $y > 1 And $y < 8 Then If $tt[$x][$y] = $tt[$x + 1][$y + 1] And $tt[$x][$y] = $tt[$x + 1][$y - 1] Then $sol[$x][$y] = 7002 ; G EndIf If $x > 1 And $y > 1 And $y < 8 Then If $tt[$x][$y] = $tt[$x - 1][$y + 1] And $tt[$x][$y] = $tt[$x - 1][$y - 1] Then $sol[$x][$y] = 8004 ; H EndIf If $y > 2 Then If $x < 8 Then If $tt[$x][$y] = $tt[$x + 1][$y - 1] And $tt[$x][$y] = $tt[$x + 1][$y - 2] Then $sol[$x][$y] = 1002 ; A EndIf If $x > 1 Then If $tt[$x][$y] = $tt[$x - 1][$y - 1] And $tt[$x][$y] = $tt[$x - 1][$y - 2] Then $sol[$x][$y] = 2004 ; B EndIf EndIf If $y < 7 Then If $x < 8 Then If $tt[$x][$y] = $tt[$x + 1][$y + 1] And $tt[$x][$y] = $tt[$x + 1][$y + 2] Then $sol[$x][$y] = 5002 ; E EndIf If $x > 1 Then If $tt[$x][$y] = $tt[$x - 1][$y + 1] And $tt[$x][$y] = $tt[$x - 1][$y + 2] Then $sol[$x][$y] = 6004 ; F EndIf EndIf If $x > 3 Then If $tt[$x][$y] = $tt[$x - 2][$y] And $tt[$x][$y] = $tt[$x - 3][$y] Then $sol[$x][$y] = 15004 ; O EndIf If $x < 6 Then If $tt[$x][$y] = $tt[$x + 2][$y] And $tt[$x][$y] = $tt[$x + 3][$y] Then $sol[$x][$y] = 17002 ; P EndIf If $y > 1 And $x > 1 And $x < 8 Then If $tt[$x][$y] = $tt[$x - 1][$y - 1] And $tt[$x][$y] = $tt[$x + 1][$y - 1] Then $sol[$x][$y] = 11001 ; K EndIf If $y < 8 And $x > 1 And $x < 8 Then If $tt[$x][$y] = $tt[$x - 1][$y + 1] And $tt[$x][$y] = $tt[$x + 1][$y + 1] Then $sol[$x][$y] = 12003 ; L EndIf ;If Mod($tick, 2) = 1 Then If $x < 7 Then If $y > 1 Then If $tt[$x][$y] = $tt[$x + 1][$y - 1] And $tt[$x][$y] = $tt[$x + 2][$y - 1] Then $sol[$x][$y] = 3001 ; C EndIf If $y < 8 Then If $tt[$x][$y] = $tt[$x + 1][$y + 1] And $tt[$x][$y] = $tt[$x + 2][$y + 1] Then $sol[$x][$y] = 10003 ; J EndIf EndIf If $x > 2 Then If $y > 1 Then If $tt[$x][$y] = $tt[$x - 1][$y - 1] And $tt[$x][$y] = $tt[$x - 2][$y - 1] Then $sol[$x][$y] = 4001 ; D EndIf If $y < 8 Then If $tt[$x][$y] = $tt[$x - 1][$y + 1] And $tt[$x][$y] = $tt[$x - 2][$y + 1] Then $sol[$x][$y] = 9003 ; I EndIf EndIf If $y < 6 Then If $tt[$x][$y] = $tt[$x][$y + 2] And $tt[$x][$y] = $tt[$x][$y + 3] Then $sol[$x][$y] = 13003 ; M EndIf If $y > 3 Then If $tt[$x][$y] = $tt[$x][$y - 2] And $tt[$x][$y] = $tt[$x][$y - 3] Then $sol[$x][$y] = 14001 ; N EndIf EndIf if $sol[$x][$y]<>0 then ExitLoop Next if $sol[$x][$y]<>0 then ExitLoop Next $flag = False For $y = 8 to $rr step -1 For $x = 1 To 8 If $sol[$x][$y] <> 0 Then $flag = True ExitLoop EndIf Next If $flag = True Then ExitLoop Next MakeAMove($x, $y, $sol[$x][$y]) Return True EndFunc ;==>SearchForAThree Func LoadTT() For $x = 0 To 9 For $y = 0 To 9 $tt[$x][$y] = 0 Next Next For $x = 1 To 8 For $y = 1 To 8 $tt[$x][$y] = $mt[$x][$y] $sol[$x][$y] = False Next Next Return True EndFunc ;==>LoadTT Func MakeAMove($x, $y, $dd) If Not _IsPressed("A0", $dll) Then $xd = 0 $yd = 0 If $x > 0 And $x < 9 And $y > 0 And $y < 9 And ($x + $xd) > 0 And ($x + $xd < 9) And ($y + $yd) > 0 And ($y + $yd) < 9 Then $d = $dd While $d >= 1000 $d = $d - 1000 WEnd If $d > 4 Then $d = 0 Select Case $d = 1 $yd = -1 Case $d = 2 $xd = 1 Case $d = 3 $yd = +1 Case $d = 4 $xd = -1 EndSelect GUICtrlSetData($status, "Moving " & $x & "," & $y & " ->" & $x + $xd & "," & $y + $yd & " (" & $dd & ")" & GetColorName($tt[$x][$y])) ;MouseClickDrag("primary", GetBlitzX($x), GetBlitzY($y), GetBlitzX($x + $xd), GetBlitzY($y + $yd),0) MouseMove(GetBlitzX($x), GetBlitzY($y), 0) Sleep(50) MouseClick("primary", GetBlitzX($x), GetBlitzY($y), 1) MouseMove(GetBlitzX($x + $xd), GetBlitzY($y + $yd), 1) Sleep(50) MouseClick("primary", GetBlitzX($x + $xd), GetBlitzY($y + $yd), 1) EndIf DoEvents() EndIf EndFunc ;==>MakeAMove
MariusN Posted March 22, 2010 Posted March 22, 2010 Could do me a favor (or someone...)I kinda have some time on my hands, but there is no way to tunnel thru our company firewall to get YouTube up.... (Well, I could, but the Security types would get all pissy and whine a lot)Can someone clip out the code and post it here? Thanks --------------------------PS, remember to do your "hunting" from the bottom up, and restart after every "success"That allows the best chance for cascade scores Have you tried the program called FREEPROXY? you can tunnel through that...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now