Morgen alle zusammen,
es ist mal zu einem zwischen Projekt gekommen bei mir, ich hatte langweilig - versteht sich
ich war auf einer website und löste ein Sudoku, hatte irgendwie gerade lust...
aber nach dem ersten Sudoku hatte ich schon keine lust mehr darauf, weil,
die highscores manipuliert aussahen - niemand schafft so ein sudoku in 11 sek (nicht mal ein PC - der wäre schneller)
irgendwie hatte ich gerade lust was mathematisches zu machen - dies ist zwar keine mathematik sondern logik aber das gefiel mir auch -
und da fing ich an einen Sudoku Rechner zu bauen, hat ja nicht lange gedauert, wann hab ich angefangen? gestern um 16:16 hab ich die *.au3 erstellt (lässt sich nachweisen)
es gibt hier zwar schon ein yut oder wie ihr das nennt, worin man so ein ding bauen sollte, aber das wusste ich nicht, ich wollte sowiso mein eigenes
es dauerte gerade mal 6 stunden, und ich bin ein berner - hab mich mal wieder raus geredet, berner sind nich so langsam wie ich... ääähm ich hatts nich eilig
auf jedenfall hab ichs geschafft ein fehlerfreies sudoku löse programm zu erstellen, hätte nicht gedacht dass es so einfach ist.
dass programm prüft ständig ob das Sudoku korrekt ist (ob in zeile, spalte oder block zwei mal dieselbe zahl kommt),
wenn ja, wird der fehler markiert mit g für block, h für zeile, v für spalte.
wenn man aber ein sudoku korrekt ab tippt wird es nie zu einem fehler kommen.
Fehlerferi, ist es deshalb,
weil es sich für jedes feld, merkt welche zahlen nicht möglich sind, und wenn nur noch eine möglich ist wird sie eingetragen. (ich mache dass nciht so, aber mein programm )
dadurch kann es jedoch möglich werden dass man selber mal die eine oder andere zahl tippen muss, aber es ist auch möglich dass es in weinger als 1 sek das ganze gelöst hat.
dass keine zahl mehr möglich ist merkt er nicht, ist auch nicht nötig wenn man es korrekt verwendet.
Skript
Vorsicht: Werbefrei!
[autoit]#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region GUI
$Form1 = GUICreate("Sudoku Rechner", 314, 264, 388, 124)
Global $inputs[9][9] ; erstes feld = spalte ; zweites feld = zeile ;
Global $colw[9]
$colw[0] = 8
$colw[1] = 40
$colw[2] = 72
$colw[3] = 112
$colw[4] = 144
$colw[5] = 176
$colw[6] = 216
$colw[7] = 248
$colw[8] = 280
Global $roww[9]
$roww[0] = 8
$roww[1] = 32
$roww[2] = 56
$roww[3] = 88
$roww[4] = 112
$roww[5] = 136
$roww[6] = 168
$roww[7] = 192
$roww[8] = 216
For $row = 0 to 8
For $col = 0 to 8
$inputs[$row][$col] = GUICtrlCreateInput("", $colw[$col], $roww[$row], 25, 21)
Next
Next
$Label1 = GUICtrlCreateLabel("Starten...", 8, 244, 204, 17)
$Button1 = GUICtrlCreateButton("Berechnen", 216, 240, 89, 21, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion GUI
GUICtrlSetData($Label1, "Bereit")
GUICtrlSetColor($Label1, 0x00CC00)
Global $werte[9][9]
Global $varriants[9][9][9]
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
For $row = 0 to 8
For $col = 0 to 8
$werte[$row][$col] = GUICtrlRead($inputs[$row][$col])
Next
Next
$full = False
$c_error = False
$sp1 = 0
$sp2 = 0
#Region testing
For $row = 0 to 8
For $col = 0 to 8
If $werte[$row][$col] <> "" Then
For $tcol = 0 to 8
If $werte[$row][$tcol] = $werte[$row][$col] And $col <> $tcol Then
$c_error = True
GUICtrlSetData($inputs[$row][$col], "h"&$werte[$row][$col])
GUICtrlSetData($inputs[$row][$tcol], "h"&$werte[$row][$tcol])
GUICtrlSetData($Label1, "Ihre eingaben sind Falsch!")
GUICtrlSetColor($Label1, 0xCC0000)
exitloop(3)
EndIf
Next
EndIf
Next
Next
If Not $c_error Then
For $col = 0 to 8
For $row = 0 to 8
If $werte[$row][$col] <> "" Then
For $trow = 0 to 8
If $werte[$trow][$col] = $werte[$row][$col] And $row <> $trow Then
$c_error = True
GUICtrlSetData($inputs[$row][$col], "v"&$werte[$row][$col])
GUICtrlSetData($inputs[$trow][$col], "v"&$werte[$trow][$col])
GUICtrlSetData($Label1, "Ihre eingaben sind Falsch!")
GUICtrlSetColor($Label1, 0xCC0000)
exitloop(3)
EndIf
Next
EndIf
Next
Next
EndIf
If Not $c_error Then
For $sp1 = 0 to 6 Step 3
For $sp2 = 0 to 6 Step 3
For $row = $sp1 to $sp1+2
For $col = $sp2 to $sp2+2
If $werte[$row][$col] <> "" Then
For $trow = $sp1 to $sp1+2
For $tcol = $sp2 to $sp2+2
If $werte[$trow][$tcol] = $werte[$row][$col] And $row <> $trow And $col <> $tcol Then
$c_error = True
GUICtrlSetData($inputs[$row][$col], "g"&$werte[$row][$col])
GUICtrlSetData($inputs[$trow][$tcol], "g"&$werte[$trow][$tcol])
GUICtrlSetData($Label1, "Ihre eingaben sind Falsch!")
GUICtrlSetColor($Label1, 0xCC0000)
exitloop(5)
EndIf
Next
Next
EndIf
Next
Next
Next
Next
EndIf
#EndRegion testing
#Region mark
If Not $c_error Then
For $col = 0 to 8
For $row = 0 to 8
If $werte[$row][$col] <> "" Then
GUICtrlSetStyle($inputs[$row][$col], $ES_READONLY)
EndIf
Next
Next
EndIf
#EndRegion mark
Do
$full = False
$c_error = False
$sp1 = 0
$sp2 = 0
GUICtrlSetData($Label1, "Berechne...")
GUICtrlSetColor($Label1, 0x777700)
For $row = 0 to 8
For $col = 0 to 8
$werte[$row][$col] = GUICtrlRead($inputs[$row][$col])
Next
Next
#Region recv data
If Not $c_error Then
For $row = 0 to 8
For $col = 0 to 8
If $werte[$row][$col] = "" Then
For $number = 0 to 8
$varriants[$row][$col][$number] = True
Next
If $row > 5 Then
$sp1 = 6
ElseIf $row > 2 Then
$sp1 = 3
Else
$sp1 = 0
EndIf
If $col > 5 Then
$sp2 = 6
ElseIf $col > 2 Then
$sp2 = 3
Else
$sp2 = 0
EndIf
For $number = 1 to 9
For $trow = $sp1 to $sp1+2
For $tcol = $sp2 to $sp2+2
If $werte[$trow][$tcol] <> "" Then
For $trow2 = $sp1 to $sp1+2
For $tcol2 = $sp2 to $sp2+2
If $werte[$trow2][$tcol2] = $number Then
$varriants[$row][$col][$number-1] = False
EndIf
Next
Next
EndIf
Next
Next
For $tcol = 0 to 8
If $werte[$row][$tcol] = $number Then
$varriants[$row][$col][$number-1] = False
EndIf
Next
For $trow = 0 to 8
If $werte[$trow][$col] = $number Then
$varriants[$row][$col][$number-1] = False
EndIf
Next
Next
EndIf
Next
Next
EndIf
#EndRegion recv data
#Region compute and fill in
If Not $c_error Then
$sp1 = 0
$changes = 0
For $row = 0 to 8
For $col = 0 to 8
If $werte[$row][$col] = "" Then
$sp1 += 1
$count = 0
For $number = 0 To 8
If $varriants[$row][$col][$number] = True Then
$count += 1
GUICtrlSetData($inputs[$row][$col], $number+1)
$changes += 1
EndIf
If $count > 1 Then
GUICtrlSetData($inputs[$row][$col], "")
$changes -= 2
ExitLoop
EndIf
Next
EndIf
Next
Next
If $sp1 = 0 Then
$full = True
EndIf
EndIf
#EndRegion compute and fill in
For $row = 0 to 8
For $col = 0 to 8
$werte[$row][$col] = GUICtrlRead($inputs[$row][$col])
Next
Next
#Region testing
For $row = 0 to 8
For $col = 0 to 8
If $werte[$row][$col] <> "" Then
For $tcol = 0 to 8
If $werte[$row][$tcol] = $werte[$row][$col] And $col <> $tcol Then
$c_error = True
GUICtrlSetData($inputs[$row][$col], "h"&$werte[$row][$col])
GUICtrlSetData($inputs[$row][$tcol], "h"&$werte[$row][$tcol])
GUICtrlSetData($Label1, "Beim Brechnen sind fehler entstanden!")
GUICtrlSetColor($Label1, 0xCC0000)
exitloop(3)
EndIf
Next
EndIf
Next
Next
If Not $c_error Then
For $col = 0 to 8
For $row = 0 to 8
If $werte[$row][$col] <> "" Then
For $trow = 0 to 8
If $werte[$trow][$col] = $werte[$row][$col] And $row <> $trow Then
$c_error = True
GUICtrlSetData($inputs[$row][$col], "v"&$werte[$row][$col])
GUICtrlSetData($inputs[$trow][$col], "v"&$werte[$trow][$col])
GUICtrlSetData($Label1, "Beim Brechnen sind fehler entstanden!")
GUICtrlSetColor($Label1, 0xCC0000)
exitloop(3)
EndIf
Next
EndIf
Next
Next
EndIf
If Not $c_error Then
For $sp1 = 0 to 6 Step 3
For $sp2 = 0 to 6 Step 3
For $row = $sp1 to $sp1+2
For $col = $sp2 to $sp2+2
If $werte[$row][$col] <> "" Then
For $trow = $sp1 to $sp1+2
For $tcol = $sp2 to $sp2+2
If $werte[$trow][$tcol] = $werte[$row][$col] And $row <> $trow And $col <> $tcol Then
$c_error = True
GUICtrlSetData($inputs[$row][$col], "g"&$werte[$row][$col])
GUICtrlSetData($inputs[$trow][$tcol], "g"&$werte[$trow][$tcol])
GUICtrlSetData($Label1, "Beim Brechnen sind fehler entstanden!")
GUICtrlSetColor($Label1, 0xCC0000)
exitloop(5)
EndIf
Next
Next
EndIf
Next
Next
Next
Next
EndIf
#EndRegion testing
Until $changes = 0 Or $c_error
If $full Then
GUICtrlSetData($Label1, "Sudoku gelöst!!")
GUICtrlSetColor($Label1, 0x0000CC)
ElseIf Not $c_error Then
GUICtrlSetData($Label1, "Es sind weitere Zahlen nötig zum lösen...")
GUICtrlSetColor($Label1, 0x770077)
ElseIf $c_error Then
For $col = 0 to 8
For $row = 0 to 8
If $werte[$row][$col] <> "" Then
GUICtrlSetStyle($inputs[$row][$col], "")
EndIf
Next
Next
EndIf
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
achja: nochwas: ich glaube nicht dass ich noch lust hab aus eigenen gründen daran was zu ändern, wenn jemand was findet werd ich eher interesse daran haben was zu ändern