AlmarM Posted November 23, 2010 Posted November 23, 2010 Hiya, at work we had to discover a 2D array pattern finding algoritme. I thought converting it into AutoIt and post it. Notice the "0" in $_aPattern does represent anything. Any number. Global $_aGrid[6][6] = [ [0, 0, 0, 0, 0, 0], _ [0, 0, 0, 0, 0, 0], _ [0, 0, 0, 1, 0, 0], _ [0, 0, 1, 1, 1, 0], _ [0, 0, 0, 0, 0, 0], _ [0, 0, 0, 0, 0, 0] ] Global $_aPattern[2][3] = [ [0, 1, 0], _ [1, 1, 1] ] _findPattern($_aGrid, $_aPattern) ; outputs "2, 2" Func _findPattern($aGrid, $aPattern) Local $bMatch = False For $i = 0 To ((UBound($aGrid) - 1) - (UBound($aPattern) - 1)) For $j = 0 To (UBound($aGrid) - UBound($aPattern, 2)) $bMatch = True For $k = 0 To (UBound($aPattern) - 1) For $l = 0 To (UBound($aPattern, 2) - 1) $bMatch = ($bMatch And ($aGrid[$i + $k][$j + $l] == $aPattern[$k][$l]) Or $aPattern[$k][$l] == 0) Next Next If ($bMatch) Then ConsoleWrite("Pattern found: " & $i & ", " & $j & @CRLF) Return EndIf Next Next ConsoleWrite("No pattern found." & @CRLF) EndFunc Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.
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