#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Color.au3>
#include <Array.au3>
Global $LI_WALL = -1
Global $LI_BLANK = -2
Dim $a[2] = [0, 0]
Dim $b[2] = [99, 99]
Sleep(3000)
$Arr = Lee($a, $b, ToMatrix(0, 0, @DesktopWidth, @DesktopHeight))
_ArrayDisplay($Arr)
Func Lee($a, $b, $Arr)
Local $D = 0
Dim $Dx[8] = [1, 1, 0, -1, -1, -1, 0, 1]
Dim $Dy[8] = [0, -1, -1, -1, 0, 1, 1, 1]
$Arr[$a[1]][$a[0]] = $D
$SizeX = UBound($Arr)
$SizeY = UBound($Arr, 2)
Do
$Stop = True
For $x = 0 To $SizeX-1
For $y = 0 To $SizeY-1
If $Arr[$x][$y] == $D Then
For $i = 0 To 7
$Px = $x + $Dx[$i]
$Py = $y + $Dy[$i]
If $Px >=0 And $Py >= 0 And $Px < $SizeX And $Py < $SizeY And $Arr[$Px][$Py] == $LI_BLANK Then
$Stop = False
$Arr[$Px][$Py] = $D + 1
EndIf
Next
EndIf
Next
Next
$D += 1
Until $Stop Or $Arr[$b[1]][$b[0]] > 0
If $Arr[$b[1]][$b[0]] < 0 Then Return False
$x = $b[1]
$y = $b[0]
$D = $Arr[$x][$y]
Dim $P[$D][2]
Do
$D -= 1
$P[$D][0] = $y
$P[$D][1] = $x
For $i = 0 To 7
$Px = $x + $Dx[$i]
$Py = $y + $Dy[$i]
If $Px >=0 And $Py >= 0 And $Px < 100 And $Py < 100 And $Arr[$Px][$Py] == $D Then
$x = $Px
$y = $Py
ExitLoop
EndIf
Next
Until $D = 0
Return $P
EndFunc
Func ToMatrix($l, $t, $r, $b, $Color="000000", $Shade=0, $SizeX=100, $SizeY=100)
Local $x=0, $y=0
Dim $Arr[$SizeY][$SizeX]
$Data = GetImage($l, $t, $r, $b, $SizeX, $SizeY)
For $i=1 To StringLen($Data) Step 8
If $y == $SizeY Then
$y = 0
$x += 1
EndIf
If Shade(StringMid($Data, $i, 6), $Color, $Shade) Then
$Arr[$x][$y] = $LI_BLANK
Else
$Arr[$x][$y] = $LI_WALL
EndIf
$y += 1
Next
Return $Arr
EndFunc
Func Shade($Col1, $Col2, $Shade)
If $Col1 == $Col2 Then Return True
If $Shade==0 Then Return ($Col1==$Col2)
$Col1 = Execute("0x"&$Col1)
$Col2 = Execute("0x"&$Col2)
If Abs(_ColorGetRed($Col1)-_ColorGetRed($Col2)) < $Shade And Abs(_ColorGetGreen($Col1)-_ColorGetGreen($Col2)) < $Shade And Abs(_ColorGetBlue($Col1)-_ColorGetBlue($Col2)) < $Shade Then Return True
Return False
EndFunc
Func GetImage($l, $t, $r, $b, $ResW=0, $ResH=0)
Local $Width = $r-$l, $Height = $b-$t
_GDIPlus_Startup()
$hHBmp = _ScreenCapture_Capture('', $l, $t, $r, $b, False)
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp)
If $ResW <> 0 Then
$hBitmap = _GDIPlus_ImageResize($hBitmap, $ResW, $ResH)
$Width = $ResW
$Height = $ResH
EndIf
$Data = Hex(DllStructGetData(DllStructCreate('byte[' & ($Width * $Height * 4) & ']', DllStructGetData(_GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB), 'Scan0')), 1), 6)
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBmp)
_GDIPlus_Shutdown()
Return $Data
EndFunc