Hi ich hab mir heute morgen vorgenommen ein eigenen Sudoku Generator zu basteln. Ich bin auch schon ziemlich weit gekommen für meine Verhältnisse, aber nachdem ich die ersten Regeln für den Generator eingebaut hab füllt er nicht mehr das komplette Rätsel aus.
Ich denke er hängt bei meiner kleinen mini Random UDF aber ich bin noch nicht dahinter gekommen
da er nach jeden neustarten des Scripts, unterschiedlich mehr oder weniger ausfüllt.
Wäre cool wenn jemand zeit hatte mal drüber zu sehen und evtl etwas sieht das ich übersehen hab.
Danke
ERandom()
Func ERandom($min,$max,$except)
$ZZ=StringSplit($except,"")
Do
$W=True
$R=Random($min,$max,1)
For $i=1 To $ZZ[0]
If $R=$ZZ[$i] Then
$W=False
ExitLoop
EndIf
Next
Until $W= True
Return $R
EndFunc
SudoKU
#include <StaticConstants.au3>
#include <Random.au3>
Dim $Labels[10][10]
$X=12
$Y=12
HotKeySet("{ESC}","e")
Func e()
Exit
EndFunc
GUICreate("SuDoKu",400,400)
GUICtrlCreateLabel("",10,10,380,380)
GUICtrlSetBkColor(-1,0xABABAB)
GUICtrlCreateLabel("",136,12,2,376)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",388,10,2,380)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",12,388,376,2)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",12,10,376,2)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",10,10,2,380)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",262,12,2,376)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",12,136,376,2)
GUICtrlSetBkColor(-1,0x000000)
GUICtrlCreateLabel("",12,262,376,2)
GUICtrlSetBkColor(-1,0x000000)
For $a=1 To 9 ;runter
For $0=1 To 9 ;rechts
$Labels[$a][$0] = GUICtrlCreateLabel("",$X,$Y,40,40,Bitor($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1,15)
$X+=42
Next
$Y+=42
$X=12
Next
GUISetState()
$T=Random(1,9,1)
For $0=1 to 9
GUICtrlSetData($Labels[1][$0],StringRight($T,1))
If $0=9 Then ExitLoop
$T&=ERandom(1,9,$T)
Next
$T=""
Sleep(1000)
For $a=2 To 9
For $0=1 To 9
If $a>0 And $a<4 And $0>0 And $0<4 Then
$KL=1
ElseIf $a>0 And $a<4 And $0>3 And $0<7 Then
$KL=2
ElseIf $a>0 And $a<4 And $0>6 And $0<10 Then
$KL=3
ElseIf $a>3 And $a<7 And $0>0 And $0<4 Then
$KL=4
ElseIf $a>3 And $a<7 And $0>3 And $0<7 Then
$KL=5
ElseIf $a>3 And $a<7 And $0>6 And $0<10 Then
$KL=6
ElseIf $a>6 And $a<10 And $0>0 And $0<4 Then
$KL=7
ElseIf $a>6 And $a<10 And $0>3 And $0<7 Then
$KL=8
ElseIf $a>6 And $a<10 And $0>6 And $0<10 Then
$KL=9
EndIf
GUICtrlSetData($Labels[$a][$0],ERandom(1,9,Read($KL,$0,$a)))
Next
Next
;While 1
;WEnd
Func Read($K,$V,$H)
$B=""
$T=""
$B&=StringStripWS(Kastchen($K),8)
$B&=StringStripWS(Ver($V),8)
$B&=StringStripWS(Hor($H),8)
Return $B
EndFunc
Func Kastchen($K)
$T=""
If $K=1 Then
For $a=1 To 3
For $0 =1 To 3
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=2 Then
For $a=1 To 3
For $0 =3 To 6
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=3 Then
For $a=1 To 3
For $0 =6 To 9
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=4 Then
For $a=3 To 6
For $0 =1 To 3
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=5 Then
For $a=3 To 6
For $0 =3 To 6
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=6 Then
For $a=3 To 6
For $0 =6 To 9
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=7 Then
For $a=6 To 9
For $0 =1 To 3
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=8 Then
For $a=6 To 9
For $0 =3 To 6
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
ElseIf $K=9 Then
For $a=6 To 9
For $0 =6 To 9
$T&=GUICtrlRead($Labels[$a][$0])
Next
Next
EndIf
Return $T
EndFunc
Func Ver($V)
$T=""
For $a=1 To 9
$T&=GUICtrlRead($Labels[$a][$V])
Next
Return $T
EndFunc
Func Hor($H)
$T=""
For $0=1 To 9
$T&=GUICtrlRead($Labels[$H][$0])
Next
Return $T
EndFunc