► Afficher le texte
Code : Tout sélectionner
#include <Array.au3>
Func _CreerLaby($iHauteur = 5, $iLargeur = 5)
Local $aLaby[$iHauteur][$iLargeur][2], $OpenList[0], $PrivateList[0]
For $i = 0 To $iHauteur - 1
For $j = 0 To $iLargeur - 1
$aLaby[$i][$j][0] = "0"
$aLaby[$i][$j][1] = "15"
Next
Next
;_ArrayDisplay($aLaby)
_Cherche($aLaby, 0, 1, $OpenList, $PrivateList)
;~ _RpzIn2D($aLaby)
$file=FileOpen("testou.txt",2)
For $i=0 to UBound($aLaby)-1
For $j=0 to UBound($aLaby,2)-1
FileWrite($file,Binary(Number($aLaby[$i][$j][1])&" "))
Next
FileWrite($file,@CRLF)
Next
FileClose($file)
_ArrayDisplay($aLaby)
Return $aLaby
EndFunc ;==>_CreerLaby
Func _Cherche(ByRef $aLaby, $X, $Y, $OpenList, $PrivateList)
If _IsCompleted($aLaby) = True Then
Return
Else
_ArrayAdd($PrivateList, _Verif($aLaby, $X + 1, $Y, 1))
_ArrayAdd($PrivateList, _Verif($aLaby, $X - 1, $Y, 2))
_ArrayAdd($PrivateList, _Verif($aLaby, $X, $Y + 1, 3))
_ArrayAdd($PrivateList, _Verif($aLaby, $X, $Y - 1, 4))
While _ArraySearch($PrivateList, -1) <> -1
_ArrayDelete($PrivateList, _ArraySearch($PrivateList, -1))
WEnd
_ArrayDisplay($PrivateList,"privé")
_ArrayDisplay($OpenList,"ouvert")
If UBound($PrivateList) = 0 And UBound($OpenList) > 0 Then
$rand = Random(0, UBound($OpenList) - 1, 1)
$X2 = StringSplit($OpenList[$rand], ",")[1]
$Y2 = StringSplit($OpenList[$rand], ",")[2]
_ArrayDelete($OpenList, $rand)
ReDim $PrivateList[0]
_Cherche($aLaby, $X2, $Y2, $OpenList, $PrivateList)
ElseIf UBound($OpenList)=0 And UBound($PrivateList) = 0 Then
MsgBox(0,"","sort")
Return
EndIf
;~ _ArrayDisplay($OpenList)
;_ArrayDisplay($PrivateList)
$rand = Random(0, UBound($PrivateList) - 1, 1)
$X2 = StringSplit($PrivateList[$rand], ",")[1]
$Y2 = StringSplit($PrivateList[$rand], ",")[2]
Switch $X2
Case $X + 1
$aLaby[$X2][$Y2][1] = "7"
$aLaby[$X][$Y][1] = BitAND($aLaby[$X][$Y][1], "13")
Case $X - 1
$aLaby[$X2][$Y2][1] = "13"
$aLaby[$X][$Y][1] = BitAND($aLaby[$X][$Y][1], "7")
Case $X
Switch $Y2
Case $Y + 1
$aLaby[$X2][$Y2][1] = "11"
$aLaby[$X][$Y][1] = BitAND($aLaby[$X][$Y][1], "14")
Case $Y - 1
$aLaby[$X2][$Y2][1] = "14"
$aLaby[$X][$Y][1] = BitAND($aLaby[$X][$Y][1], "11")
EndSwitch
EndSwitch
_ArrayDelete($PrivateList, $rand)
For $i = 0 To UBound($PrivateList) - 1
_ArrayAdd($OpenList, $PrivateList[$i])
Next
$aLaby[$X][$Y][0] = "1"
_RpzIn2D($aLaby)
ReDim $PrivateList[0]
_Cherche($aLaby, $X2, $Y2, $OpenList, $PrivateList)
EndIf
EndFunc ;==>_Cherche
Func _Verif($aLaby, $X, $Y, $Case)
If $X >= 0 And $Y >= 0 And $X <= UBound($aLaby) - 1 And $Y <= UBound($aLaby, 2) - 1 And $aLaby[$X][$Y][0] = "0" Then
Switch $Case
Case 1
Return $X & "," & $Y & "," & $X - 1 & "," & $Y
Case 2
Return $X & "," & $Y & "," & $X + 1 & "," & $Y
Case 3
Return $X & "," & $Y & "," & $X & "," & $Y - 1
Case 4
Return $X & "," & $Y & "," & $X & "," & $Y + 1
EndSwitch
Else
Return -1
EndIf
EndFunc ;==>_Verif
Func _IsCompleted($Array)
For $i = 0 To UBound($Array) - 1
For $j = 0 To UBound($Array, 2) - 1
If $Array[$i][$j][0] <> "1" Then Return False
Next
Next
MsgBox(0,"","complété")
Return True
EndFunc ;==>_IsCompleted
Func _RpzIn2D($Array)
Local $temp[UBound($Array)][UBound($Array, 2)]
For $i = 0 To UBound($Array) - 1
For $j = 0 To UBound($Array, 2) - 1
$temp[$i][$j] = $Array[$i][$j][0]
Next
Next
_ArrayDisplay($temp)
EndFunc ;==>_RpzIn2D



