#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Dalinou Sudoku Résolveur Version: Alpha Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include #include #include #include #include Global $sudoku[10][10];premier ligne deuxième colonne Global $vide = 0 $hGUI=GUICreate("exemple") $id = GUICtrlCreateButton("Résolution", 310, 370, 85, 25) For $i=1 to 9 for $j=1 To 9 $e=Random(10,15,1) if $e > 9 Then $e = "" Assign("c"&String($j)&String($i),GUICtrlCreateInput($e,$i*30,$j*30,20,20),2) Next Next GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $id For $i = 1 To 9 For $j = 1 To 9 $sudoku[$i][$j] = GUICtrlRead(Eval("c" & String($i) & String($j))) Next Next ExitLoop EndSwitch WEnd GUIDelete($hGUI) While 1 For $i = 1 To 9 For $J = 1 To 9 For $x = 1 To 9 placageLigne($x, $i) placageColonne($x, $j) placageCase($x, $i, $j) Next Next Next comptage() WEnd Func NeufToTrois($x);pase de petite case à grande case Switch $x Case 1 To 3 Return 1 Case 1 To 3 Return 1 Case 1 To 3 Return 1 EndSwitch EndFunc Func NbLigne($x, $L);return Nb de $x dans la ligne $L $a=0 for $i = 1 To 9 If $sudoku[$L][$i] = $x Then $a = $a + 1 Next Return $a EndFunc Func NbColonne($x, $C);return Nb de $x dans la colonne $C $a=0 for $i = 1 To 9 If $sudoku[$i][$C] = $x Then $a = $a + 1 Next Return $a EndFunc Func NbCase($x, $L, $C);return Nb de $x dans la grande case de la case $sudoku[$L][$C] $a = 0 For $i = 1 To 3 $L = $i+3*(NeufToTrois($L)-1) For $j = 1 To 3 $C = $j+3*(NeufToTrois($C)-1) If $sudoku[$L][$C] Then $a = $a + 1 Next Next EndFunc Func placable($x, $L, $C);return 0 si $x n'est pas placable dans la case $sudoku[$L][$C] --- return 1 si $x est placable dans la case $sudoku[$L][$C] $a = 1 Switch NbLigne($x, $L) Case 0 $a = $a Case 1 $a = 1 Case 2 MsgBox(1,"sudoku","erreur") Exit EndSwitch Switch NbColonne($x, $C) Case 0 $a = $a Case 1 $a = 1 Case 2 MsgBox(1,"sudoku","erreur") Exit EndSwitch Switch NbCase($x, $L, $C) Case 0 $a = $a Case 1 $a = 1 Case 2 MsgBox(1,"sudoku","erreur") Exit EndSwitch Return $a EndFunc Func NbPlaceLigne ($x, $L);return Nb de place pour $x dans la ligne $L $a = 0 For $i = 1 To 9 If placable($x, $L, $i) = 0 Then $a = $a + 1 Next Return $a EndFunc Func NbPlaceColonne ($x, $C);return Nb de place pour $x dans la colonne $C $a = 0 For $i = 1 To 9 If placable($x, $i, $C) = 0 Then $a = $a + 1 Next Return $a EndFunc Func NbPlaceCase ($x, $L, $C);return Nb de place pour $x dans la grande case de la case $sudoku[$L][$C] $a = 0 For $i = 1 To 3 For $j = 1 To 3 If placable($x, ($i+3*($L-1)), ($j+3*($C-1))) = 0 Then $a = $a + 1 Next Next Return $a EndFunc Func placageLigne ($x, $L);place $x si il n'y à qu'une seul place posible dans la ligne $L Switch NbPlaceLigne($x, $L) Case 0 MsgBox(1,"sudoku","erreur") Exit Case 1 For $i = 1 To 9 If placable($x, $L, $i) = 1 Then $sudoku[$L][$i] = $x Next EndSwitch EndFunc Func placageColonne ($x, $C);place $x si il n'y à qu'une seul place posible dans la Colonne $C Switch NbPlaceColonne($x, $C) Case 0 MsgBox(1,"sudoku","erreur") Exit Case 1 For $i = 1 To 9 If placable($x, $i, $C) = 1 Then $sudoku[$i][$C] = $x Next EndSwitch EndFunc Func placageCase ($x, $L, $C);place $x si il n'y à qu'une seul place posible dans la grande case de la case $sudoku[$L][$C] Switch NbPlaceCase($x, $L, $C) Case 0 MsgBox(1,"sudoku","erreur") Exit Case 1 For $i = 1 To 3 For $j = 1 To 3 If placable($x, ($i+3*($L-1)), ($j+3*($C-1))) = 1 Then $sudoku[($i+3*($L-1))][($j+3*($C-1))] = $x Next Next EndSwitch EndFunc Func affichage() Local $sudokuaffich = "" For $i = 1 To 9 For $j = 1 To 9 $sudokuaffich = $sudokuaffich & String($sudoku[$i][$j]) & " " If $sudoku[$i][$j] = "" Then $sudokuaffich = $sudokuaffich & " " Next $sudokuaffich = $sudokuaffich & @CR Next MsgBox(1,"sudoku",$sudokuaffich) EndFunc Func comptage() $vide2 = $vide $vide = 0 For $i = 1 To 9 For $j = 1 To 9 If $sudoku[$i][$j] = "" Then $vide = $vide + 1 Next Next If $vide = 0 Then MsgBox(1,"sudoku","J'ai fini le sudoku voici la grille") affichage() Exit EndIf If $vide = $vide2 Then MsgBox(1,"sudoku","Je ne peux plus avancer voici la grille") affichage() Exit EndIf EndFunc