I'm having trouble finding bitmaps on the screen. I'm getting confusing results when I try to run a program to test the FindBitmap procedure (along with similar ones, like FindBitmapToleranceIn).
Here's what I have so far. It's for a sort of card matching game, where you're given a bunch of face down cards and you have to try to match them by flipping two over at a time, and I'm trying to make a script that will play this automatically. This is not the final product though; The following code is just a way to test some functions in SCAR and see if they can do what I need them to do.
The concerned area of the client currently looks like this:
http://img33.imageshack.us/img33/6581/pic1ys.jpg
Here's my code.
Output:Code:program New; Var BitmapArray:array[1..2] of integer; PosX:integer; PosY:integer; VarAc:Extended; Const BeginX=305; BeginY=80; EndX=800; EndY=580; begin BitmapArray[1] := Bitmapfromstring2(False, ''); Copyclienttobitmap(BitmapArray[1], 320, 510, 355, 555); writeln(FindBitmap(BitmapArray[1], PosX, PosY)); Clickmouse(400, 540, True); Wait(3000); Clickmouse(580,530,True); Wait(2000); writeln(FindBitmap(BitmapArray[1], PosX, PosY)); writeln(FindBitmapToleranceIn(BitmapArray[1], PosX, PosY, BeginX, BeginY, EndX, EndY, 300)); writeln(inttostr(PosX) + ' ' + inttostr(PosY)); writeln(FindBitmapToleranceIn(BitmapArray[1], PosX, PosY, BeginX, BeginY, EndX, EndY, 275)); writeln(inttostr(PosX) + ' ' + inttostr(PosY)); writeln(FindBitmapToleranceIn(BitmapArray[1], PosX, PosY, BeginX, BeginY, EndX, EndY, 250)); writeln(inttostr(PosX) + ' ' + inttostr(PosY)); // writeln(FindDeformedBitmapToleranceIn(BitmapArray[1], PosX, PosY, BeginX, BeginY, EndX, EndY, 150, 1, True, VarAc)); End
Just to run through it step by step. First, it uses CopyClientToBitmap to save the image located at 320, 510, 355, 555 (In other words, a tiny portion of the bottomleftmost card). Then, (Just to test to see if it works), it searches for the same card in the entire client and prints the result (Which is 1, or True) and the coordinates (Which appears to be the correct position of the bottom left card).Code:Line 7: [Hint] (7:1): Variable 'VARAC' never used in script 1 320 510 0 1 321 99 1 565 191 0 565 191 Successfully executed
Then, it clicks on an adjacent card (Which I know is not a correct match), waits for it to reset the flipped cards, then clicks on a new card (Which I know should be the correct match). The screen now looks like this:
http://img195.imageshack.us/img195/8608/pic4lh.jpg
Then it searches for the previously saved image in the entire client again and prints the result. Here's the problem though; It keeps returning 0 (False), so it's obviously not finding it.
It searches for the saved image in the client again, and prints the result, only using FindBitmapToleranceIn this time. It returns True, and then prints the coordinates. (Which appear to be incorrect; it is 'finding' the image far too high on the screen, and too far to the left.)
It searches using FindBitmapToleranceIn again, with a slightly lower tolerance. It returns True, and prints coordinates. (Which also appear to be incorrect. I believe the value for the X axis is the correct position, but the value for the Y axis is far too high on the screen, meaning it is picking a face down card that is in the same column but a higher row.)
And then search one more time using FindBitmapToleranceIn, with lower tolerance. This time it returns false. (I tell it to print the coordinates again, but since it did not find the image, the displayed coordinates have not changed from the last search.)
The last one is a comment because I do not know if it is working properly. That function seems to take an excessively long time to complete (Although it does complete *eventually*).
It seems that such a high tolerance makes it find the wrong image, even though a slightly lower once makes it not find a match at all. (I can bet, normally, tolerance would be set to something much lower? Maybe around 20-30?)
Any idea why I would be getting such confusing results? I do have a theory of my own; I think, perhaps, that the source file that this applet is using it much bigger, so it is being scaled down for each instance of the card in the game. It could be that the resulting scaled image will be slightly different depending on where it is on the screen. (If this makes any sense to anybody)
I want to note that once I close this game window, the next time I want to play around with this program I will have to restart it with a fresh game; the positions of the cards will be randomized.


Reply With Quote















