I've been working on a script to automate a Candy Crush-like game, and I've hit a roadblock that I'm struggling to overcome. In the game, I need to build a matrix of the map based on different images, each with varying shades and characteristics.
To achieve this, I've been using the ImageSearch function in AutoHotkey. My approach has been to find the smallest "haystack" and "needle" possible for each element, all of which are around 10x10 pixels (the search area is slightly larger, just 1 pixel bigger than the image). While ImageSearch works, it's quite slow, and speed is crucial in a game like Candy Crush.
I've discovered that Gdip_ImageSearch is significantly faster than ImageSearch, but it's not producing the desired results. Even with the same parameters, Gdip_ImageSearch finds fewer images than ImageSearch.
Here's a snippet of my code for reference:
Code: Select all
fn_single_box_check(num_riga, num_col) {
; ...
; Coordinates and dimensions for the image search area
coord_hat_x1 := 556
coord_hat_y1 := 286
pix_hat_x := 6
pix_hat_y := 6
X1 := coord_hat_x1 + (65 * index_col) - 1
Y1 := coord_hat_y1 + (65 * index_riga) - 1
X2 := X1 + pix_hat_x + 1
Y2 := Y1 + pix_hat_y + 1
; Using Gdip_ImageSearch
im_hat := Gdip_CreateBitmapFromFile("C:\Users\" . utente . "\Desktop\hat.png")
pBitMap := GDIP_BitmapFromScreen()
search_im_res := Gdip_ImageSearch(pBitMap, im_hat, OutputVar, X1, Y1, X2, Y2, 18, Trans:="", SearchDirection:=1, Instances:=1, LineDelim:="`n", CoordDelim:=",")
if (search_im_res > 0) {
; Do something when image is found
}
; Using ImageSearch
ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, *18 C:\Users\%utente%\Desktop\hat.png
if (ErrorLevel = 0) {
; Do something when image is found
}
; ...
}
I'm open to any suggestions or optimizations to make my image search more efficient while maintaining accuracy. Any help would be greatly appreciated. Thank you!