DanielD Posted June 20, 2009 Share Posted June 20, 2009 (edited) Hi, My name is Daniel, and I live in Israel. (Sorry for my bad english) My friend introduced me to AutoIt Yersterday, and today I had some free time so I tried to create a solving bot for the Simon Says Game. The general idea is everytime a button changes is color, I add it to an array, and than a function presses the buttons according to it. Problem is that after the color has changed to the "selected" color, I need to wait for it to change back, and only than wait for the next color (could be the same one) to be selected. I'm afraid the program I made is not quick enough to solve. Any other ideas? Cheers expandcollapse popupConst $YellowX = 816, $YellowY = 554, $GreenX = 810, $GreenY = 423, $RedX = 640 , $RedY = 419, $BlueX = 637, $BlueY = 552 Const $MaxLevel = 5 HotKeySet("+!a", "Start") HotKeySet("{ESC}", "Escape") ; Program While 1 WEnd Func Start() Global $GreenDefaultColor = PixelGetColor($Greenx, $GreenY) Global $RedDefaultColor = PixelGetColor($RedX, $RedY) Global $BlueDefaultColor = PixelGetColor($BlueX, $BlueY) Global $YellowDefaultColor = PixelGetColor($YellowX, $YellowY) Dim $arrColors[$MaxLevel] Dim $CurrLevel = 1 While $CurrLevel <= $Level For $i = 0 to $CurrLevel Step 1 $arrColors[$i] = ColorChanged() Next FillColors($arrColors, $CurrLevel) $CurrLevel += 1 WEnd EndFunc Func ColorChanged() Local $bDidChanged = False Local $ReturnVal While Not $bDidChanged $bDidChanged = True ; Checks if the color changed to the selected color if (PixelGetColor($GreenX, $GreenY) <> $GreenDefaultColor) Then $ReturnVal = "Green" ; Waits until the color Changes back While (PixelGetColor($GreenX, $GreenY) <> $GreenDefaultColor) WEnd ElseIf (PixelGetColor($RedX, $RedY) <> $RedDefaultColor) Then $ReturnVal = "Red" While (PixelGetColor($RedX, $RedY) <> $RedDefaultColor) WEnd ElseIf (PixelGetColor($BlueX, $BlueY) <> $BlueDefaultColor) Then $ReturnVal = "Blue" While PixelGetColor($BlueX, $BlueY) <> $BlueDefaultColor WEnd ElseIf (PixelGetColor($YellowX, $YellowY) <> $YellowDefaultColor) Then $ReturnVal = "Yellow" While (PixelGetColor($YellowX, $YellowY) <> $YellowDefaultColor) WEnd Else $bDidChanged = False EndIf WEnd Return $ReturnVal EndFunc Func FillColors($arrColors, $CurrLevel) For $i = 0 to $CurrLevel Step 1 Sleep (500) Switch $arrColors[$i] Case "Green" MouseClick("left",$GreenX, $GreenY, 1) Case "Red" MouseClick("left",$RedX, $RedY, 1) Case "Blue" MouseClick("left",$BlueX, $BlueY, 1) Case "Yellow" MouseClick("left",$YellowX, $YellowY, 1) EndSwitch Next EndFunc Func Escape() Exit 0 EndFunc Edited June 20, 2009 by DanielD Link to comment Share on other sites More sharing options...
llewxam Posted June 29, 2009 Share Posted June 29, 2009 Sorry, I know it can help to see how someone has taken your existing code and made some changes/improvements, but I decided to start from scratch. I myself am fairly new to AutoIt and since I didn't know where to find your game, plus I was just in the mood to do this, I made a script from scratch... In the code you will see the source that the game is opened, also please notice the HotKeySet command which sets Control-q to quit the automation of the script, so when you are ready to do something other than watch Simon Says play with itself Control-q will get you out. I put in some comments so hopefully you will get to learn something, even though it isn't based on your code. expandcollapse popup; Simon Says automator by Ian Maxwell (llewxam) 06-28-2009 HotKeySet("^q","_End");Control-q will quit! Dim $move[1000];sets maximum number of moves to 1000 Dim $x[1000];x axis Dim $y[1000];y axis $playdelay=350;needed if 2 or more moves in a row are the same color $hitdelay=10;needed for a slight delay between hits $height=@DesktopHeight $width=@DesktopWidth $redcol=9256767 $greencol=5684822 $yellowcol=12040028 $bluecol=2769028 ShellExecute("http://www.albinoblacksheep.com/flash/simon","","","",@SW_MAXIMIZE) ;initial scan, runs once "Play" is clicked Do $red=PixelSearch(1,1,$width,$height,$redcol) If @error<>1 Then ExitLoop Until 1=2 Do $green=PixelSearch(1,1,$width,$height,$greencol) If @error<>1 Then ExitLoop Until 1=2 Do $yellow=PixelSearch(1,1,$width,$height,$yellowcol) If @error<>1 Then ExitLoop Until 1=2 Do $blue=PixelSearch(1,1,$width,$height,$bluecol) If @error<>1 Then ExitLoop Until 1=2 $homex=($red[0]+(($green[0]-$red[0])/2));centers the mouse cursor horizontally $homey=($red[1]+(($blue[1]-$red[1])/2));centers the mouse cursor vertically MouseMove($homex,$homey,1);moves the mouse to the center of the game board, ready to go! ;initial scan end $begin=TimerInit();sets the delay timer used to switch from scanning to playing _Scan() Func _Scan() Do If PixelGetColor($red[0],$red[1])<>$redcol Then;must be flashing red! For $i = 0 To UBound($move)-1 If $move[$i]=0 Then;if there is not a move assigned here yet, assign it as a move and set the variables $x[$i]=$red[0];assign the x axis $y[$i]=$red[1];assign the y axis $move[$i]=1;set this as a move Do If PixelGetColor($red[0],$red[1])=$redcol Then ExitLoop;wait until the color is not flashing Until 1=2 $begin=TimerInit();reset the timer to go to _Hit() _Scan();go back to scanning for flashes EndIf Next EndIf If PixelGetColor($green[0],$green[1])<>$greencol Then;must be flashing green! For $i = 0 To UBound($move)-1 If $move[$i]=0 Then $x[$i]=$green[0] $y[$i]=$green[1] $move[$i]=1 Do If PixelGetColor($green[0],$green[1])=$greencol Then ExitLoop Until 1=2 $begin=TimerInit() _Scan() EndIf Next EndIf If PixelGetColor($yellow[0],$yellow[1])<>$yellowcol Then;must be flashing yellow! For $i = 0 To UBound($move)-1 If $move[$i]=0 Then $x[$i]=$yellow[0] $y[$i]=$yellow[1] $move[$i]=1 $begin=TimerInit() Do If PixelGetColor($yellow[0],$yellow[1])=$yellowcol Then ExitLoop Until 1=2 _Scan() EndIf Next EndIf If PixelGetColor($blue[0],$blue[1])<>$bluecol Then;must be flashing blue! For $i = 0 To UBound($move)-1 If $move[$i]=0 Then $x[$i]=$blue[0] $y[$i]=$blue[1] $move[$i]=1 Do If PixelGetColor($blue[0],$blue[1])=$bluecol Then ExitLoop Until 1=2 $begin=TimerInit() _Scan() EndIf Next EndIf If TimerDiff($begin)>650 Then _Hit();if nothing has flashed for a moment, must be time to hit! Until 1=2 EndFunc Func _Hit() For $i = 0 To UBound($move)-1 If $move[$i]<>0 Then;if there is a move, do it! Sleep($hitdelay);small delay before the next move MouseClick("left",$x[$i],$y[$i],1,5) If $x[$i]=$x[$i+1] Then sleep($playdelay);if the next move is the same color, pause EndIf Next For $i = 0 To UBound($move)-1;clear all previous moves in case of a restart $move[$i]=0 $x[$i]=0 $y[$i]=0 Next MouseMove($homex,$homey);move the mouse back to the center _Scan();go back to scanning EndFunc Func _End() Exit EndFunc I had a ball doing this, I let the count get up to 88 before exiting. I don't know how high the game will go, maybe I'll run it overnight and see how far it goes! Enjoy Ian My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
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