nothingbutus Posted March 6, 2010 Share Posted March 6, 2010 Hey there, first time on these forums. Hoping you can all help me find a solution to my problem.While I have some experience in Java programming, this is my first AutoIt script. I thought I would start off easy, so I've created a script that will automate a simple Java web browser game. The game is called Keno in which 80 numbers are displayed in a 8x10 grid. The user selects 10 numbers, and then 20 lottery balls are launched onto the grid, bouncing and colliding with each other until they all settle into specific numbers. The point of the game is to match as many user-chosen numbers with those that lottery balls land in.Now, automating the game endlessly is completed and works fine. My problems come in trying to take it a step further. On top of automating gameplay, I want the script to be able to detect what number each lottery ball lands on (not just user matches, misses as well) and record the data into a file. I also want it to increment the data. (so say a ball lands in #13 in round 1, and again in round 2. After two rounds, #13 should be recorded as having been picked twice) I guess the goal here is to determine whether or not there are any "better" numbers to choose, after a sampling of say, 1000 rounds of play. (purely for curiosity)To help visualize how to achieve this, I'll include a screen capture of the gameboard after all lottery balls have fallen into place:Legend:Red - User selected "miss"Black - Unselected "miss"Green - Unselected "hit"Blue - Selected "hit"The problem here is that the gameboard only stays like this for a few seconds before it is "reset". So however I do this, it needs to be done quickly. I need to be able to correctly detect what numbers each lottery ball land on every round and log them, without any duplicate or missed detections, within a short timeframe.I would have more time to accomplish this if I thought the detecting could begin immediately, as soon as a ball lands on a number, while other balls still roll around, but...with balls bumping and rolling all over the place - all over possible detections, I get the feeling that they would muddle with the results (especially if we're using things like PixelGetColor())Any thoughts, suggestions, and ideas would be greatly appreciated. Sorry if this is long-winded, but I just want to be as clear as I possibly can. Thank you!-us Link to comment Share on other sites More sharing options...
JohnOne Posted March 6, 2010 Share Posted March 6, 2010 (edited) Getting 80 results from pixelgetcolor takes a fraction of a second, even with logging the resulst, so thats well within your timeframe. heres a quick example to test. Local $array[80] For $i = 0 To 79 $temp = PixelGetColor($i, $i) $array[$i] = $temp FileWrite(@ScriptDir & "\Results.txt", $array[$i] & @CRLF) Next Edited March 6, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
nothingbutus Posted March 6, 2010 Author Share Posted March 6, 2010 (edited) Thanks John! That's reassuring to know that this can be done quickly. =)You've also given me the perfect start. I've taken your snippet and modified it to work within the game grid.When taking samples of PixelGetColor on each number in the grid, I've devised a way to use MouseMove and then MouseGetPos to do it for me. My problem comes when I reach $i == 10, 20, 30, 40, 50, 60, and 70 in the For loop. I need for it to be able to recognize when "i" is equal to a multiple of ten. Then, it can know it has reached the end of the row, and to MouseMove to the next row in the number grid. I've tried doing it using modulus, like so:Func getResults() Local $tempX = 79 ;holds the X position for MouseMoves Local $tempY = 168 ;Y position for MouseMoves Local $array[80] ;JohnOne's array For $i = 0 To 79 If $i == 0 Then MouseMove($tempX, $tempY, 0) ; this moves the mouse to number 1 on the game grid ElseIf $i % 10 == 0 ;any multiple of 10 should return 0 for "$i modulus 10", then execute this code $tempX = 79 ;x coord gets reset to the start $tempY += 38 ;y coord is lowered to the next row MouseMove($tempX, $tempY, 0) ;mouse is moved Else $tempX += 38 MouseMove($tempX, $tempY, 0) EndIf $array[$i] = PixelGetColor($tempX, $tempY) ;moar code EndFuncHowever, it doesn't like that. I looked for the modulus operator in autoit, but I didn't find anything. Is there another way to do modulus? Or a workaround that you guys like to use.:EDIT: Haha...nevermind. I found the Mod function =) That's the java in me...thinking it's a mathematical operator. I'll keep plugging away at it! Hope to get some results soon. Thanks again, John.Thanks a ton! Edited March 6, 2010 by nothingbutus Link to comment Share on other sites More sharing options...
JohnOne Posted March 6, 2010 Share Posted March 6, 2010 (edited) This should check a 10x8 area, you will need to alter it, but its a start. $x = 0 $y = 0 For $i = $y To 7 For $x = 0 To 9 $Pixel = PixelGetColor($x, $y) ConsoleWrite($x) Next $y += 1 ConsoleWrite(@CRLF) Next Edit: dodgy code Edited March 6, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
nothingbutus Posted March 6, 2010 Author Share Posted March 6, 2010 This should check a 10x8 area, you will need to alter it, but its a start. $x = 0 $y = 0 For $i = $y To 7 For $x = 0 To 9 $Pixel = PixelGetColor($x, $y) ConsoleWrite($x) Next $y += 1 ConsoleWrite(@CRLF) Next Edit: dodgy code Hey John. Thanks again for the suggestion, I've implemented your two for loops and it is work correctly. The next part I'm trying to expand on is the filewriting process. I've been playing with FileReadLine and FileWriteLine to try and accomplish this, but it isn't working the way I would like it to. What I would like for it to do is..when it detects a match on say, #13, that it can go into our results.txt and write "1" into the 13th line of the file. Then, if down the road #13 is matched again, it can go back into our file, read "1" and increment it to "2" on the correct 13th line. Is this possible? Or, is there a better, more efficient way to keep track of the results this way? Thanks again in advance =) Link to comment Share on other sites More sharing options...
JohnOne Posted March 6, 2010 Share Posted March 6, 2010 Perhaps you ought to look at _FileWriteToLine() which will overwrite (or not) a previous line. You could also use an .ini file to keep track of results, iniread, iniwrite, etc... But I've never had cause to use these functions so just have a fart about with them and see what suits you. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
nothingbutus Posted March 7, 2010 Author Share Posted March 7, 2010 (edited) Ah okay, awesome. I really appreciate the help. =) I skipped past the file writing portion and wrote some mock results in the way they will be generated. Then I wrote a function that sifts through them and sorts each number from lowest to highest. What I'm trying to do now is to draw a GUI window and display the top 10 most picked numbers from this function in that window. It should update each round when I'm finished. The problem is, I'm tinkering with the GUI functions and have no clue what to use to display text on the window I've created. (if I've even created the proper GUI window) =/ Any pointers? Edited March 7, 2010 by nothingbutus Link to comment Share on other sites More sharing options...
JohnOne Posted March 7, 2010 Share Posted March 7, 2010 Posting some code would help you. You can display text in a number of ways, labels, Edit boxes, lists etc.... AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
guwguw Posted March 8, 2010 Share Posted March 8, 2010 (edited) Ah okay, awesome. I really appreciate the help. =) I skipped past the file writing portion and wrote some mock results in the way they will be generated. Then I wrote a function that sifts through them and sorts each number from lowest to highest. What I'm trying to do now is to draw a GUI window and display the top 10 most picked numbers from this function in that window. It should update each round when I'm finished. The problem is, I'm tinkering with the GUI functions and have no clue what to use to display text on the window I've created. (if I've even created the proper GUI window) =/ Any pointers? I would put the $results in an array, sort and/or otherwise manipulate them and then use _ArrayDisplay($results,"title") to show. For displaying results (like you seem intent on), I would suggest creating_ $disp_results = GUICtrlCreateListView(" | Event |StartTime|EndTime|...") and (looping through your 10 items) GUICtrlCreateListViewItem("|" & $_good_events[$ecountr][1] & "|" & $_good_events[$ecountr][2] & "|" & $_good_events[$ecountr][3] & "|" & $_good_events[$ecountr][4], $disp_results ) or display the loop results in another graphically pleasing way. Edited March 8, 2010 by guwguw 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