#include #include #include #include #include #include #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Laby Générator by -Coco-", 338, 337, 192, 124) Global $Group1 = GUICtrlCreateGroup("Données du labyrinthe:", 8, 32, 321, 161) Global $Input1 = GUICtrlCreateInput("20", 32, 88, 241, 21) Global $Larg = GUICtrlCreateInput("20", 32, 152, 241, 21) Global $Label1 = GUICtrlCreateLabel("Longueur du labyrinthe", 32, 64, 112, 17) Global $Label2 = GUICtrlCreateLabel("Largeur du labyrinthe", 32, 128, 103, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Gen = GUICtrlCreateButton("Génerer", 16, 200, 303, 73, $WS_GROUP) Global $quit = GUICtrlCreateButton("Quitter", 16, 288, 303, 33, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $quit Exit Case $Gen ExitLoop EndSwitch WEnd HotKeySet('{escape}', 'stop') $j = GUICtrlRead($Input1) $i = GUICtrlRead($Larg) $o = TimerInit() $i = Int($i / 2) * 2 $j = Int($j / 2) * 2 Dim $mat[$i + 2][$j + 2] = [[0]] For $a = 1 To $i Step 1 For $b = 1 To $j Step 1 $mat[$a][$b] = 0 Next Next For $a = 1 To $i - 1 Step 1 For $b = 1 To $j - 1 Step 1 $mat[$a][$b] = 1 Next Next main(2, 2) Func main($xx, $yy) $x = $xx $y = $yy While 1 $mat[$x][$y] = 0 If $mat[$x + 2][$y] = 0 And $mat[$x - 2][$y] = 0 And $mat[$x][$y + 2] = 0 And $mat[$x][$y - 2] = 0 Then retest() EndIf $continue = 1 $u = $x $v = $y While $continue = 1 $y = $v $x = $u $r = Round(Random(0, 3), 0) Switch $r Case 0 $x = $x + 2 Case 1 $x = $x - 2 Case 2 $y = $y + 2 Case 3 $y = $y - 2 EndSwitch If $mat[$x][$y] = 1 Then $continue = 0 EndIf WEnd $mat[($u + $x) / 2][($v + $y) / 2] = 0 WEnd EndFunc ;==>main Func retest() For $a = 2 To $i - 2 Step 2 For $b = 2 To $j - 2 Step 2 If $mat[$a][$b] = 1 Then trouve() EndIf Next Next aff() EndFunc ;==>retest Func trouve() While 1 $x = Round(Random(1, $i / 2 - 1), 0) * 2 $y = Round(Random(1, $j / 2 - 1), 0) * 2 if ($mat[$x][$y] = 0 And ($mat[$x + 2][$y] = 1 Or $mat[$x - 2][$y] = 1 Or $mat[$x][$y + 2] = 1 Or $mat[$x][$y - 2] = 1)) Then main($x, $y) EndIf WEnd EndFunc ;==>trouve Func aff() $t = TimerDiff($o) _FileCreate("Laby_"&$i&"-"&$j&'.txt') $file = FileOpen("Laby_"&$i&"-"&$j&'.txt',1) For $a = 0 To $i Step 1 For $b = 0 To $j Step 1 If $mat[$a][$b] Then FileWrite($file,"^^") Else FileWrite($file," ") EndIf Next FileWrite($file,@CRLF) Next Filewrite($file, @CRLF&"(Matrice générée en " & $t & " ms)") FileClose($file) Exit EndFunc ;==>aff Func stop() Exit EndFunc ;==>stop