Ca gère des grilles n*m (pour le moment de 2 à 4)
C'est très mal codé alors pour le moment je distribue sous forme de lib (argh j'ai été obligé d'utiliser Tailbite) mais je compte bien faire de l'opensource ^^
LibSudoku

Et un petit exemple d'utilisation ^_^
(codé à l'arrache avec le visual designer)
Code : Tout sélectionner
; PureBasic Visual Designer v3.92 build 1460
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Button_0
#Button_1
#Button_2
#Button_3
#Button_4
#Button_5
#Button_6
#Button_7
#Button_8
#Button_9
#Button_10
#Button_11
#Button_12
#Button_13
#Button_14
#Button_15
#Button_16
#Button_17
#Button_18
#Button_19
#Button_20
#Button_21
#Button_22
#Button_23
#Button_24
#Button_25
#Button_26
#Button_36
#Button_37
#Button_38
#Button_39
#Button_40
#Button_41
#Button_42
#Button_43
#Button_44
#Button_45
#Button_46
#Button_47
#Button_48
#Button_49
#Button_50
#Button_51
#Button_52
#Button_53
#Button_54
#Button_55
#Button_56
#Button_57
#Button_58
#Button_59
#Button_60
#Button_61
#Button_62
#Button_63
#Button_64
#Button_65
#Button_66
#Button_67
#Button_68
#Button_69
#Button_70
#Button_71
#Button_72
#Button_73
#Button_74
#Button_75
#Button_76
#Button_77
#Button_78
#Button_79
#Button_80
#Button_81
#Button_82
#Button_83
#Button_84
#Button_85
#Button_86
#Button_87
#Button_88
#Button_89
#Button_R
#Spin_0
#Text_0
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 366, 176, 220, 260, #PB_Window_SystemMenu | #PB_Window_TitleBar , "Su-Doku")
If CreateGadgetList(WindowID())
ButtonGadget(#Button_0, 10, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_1, 30, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_2, 50, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_3, 80, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_4, 100, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_5, 120, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_6, 150, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_7, 170, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_8, 190, 50, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_9, 10, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_10, 30, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_11, 50, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_12, 80, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_13, 100, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_14, 120, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_15, 150, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_16, 170, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_17, 190, 70, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_18, 10, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_19, 30, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_20, 50, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_21, 80, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_22, 100, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_23, 120, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_24, 150, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_25, 170, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_26, 190, 90, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_36, 10, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_37, 30, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_38, 50, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_39, 80, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_40, 100, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_41, 120, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_42, 150, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_43, 170, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_44, 190, 120, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_45, 10, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_46, 30, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_47, 50, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_48, 80, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_49, 100, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_50, 120, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_51, 150, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_52, 170, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_53, 190, 140, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_54, 10, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_55, 30, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_56, 50, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_57, 80, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_58, 100, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_59, 120, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_60, 150, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_61, 170, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_62, 190, 160, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_63, 10, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_64, 30, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_65, 50, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_66, 80, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_67, 100, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_68, 120, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_69, 150, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_70, 170, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_71, 190, 190, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_72, 10, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_73, 30, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_74, 50, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_75, 80, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_76, 100, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_77, 120, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_78, 150, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_79, 170, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_80, 190, 210, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_81, 10, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_82, 30, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_83, 50, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_84, 80, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_85, 100, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_86, 120, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_87, 150, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_88, 170, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_89, 190, 230, 20, 20, "", #PB_Button_Toggle)
ButtonGadget(#Button_R, 10, 10, 60, 20, "Résoudre", #PB_Button_Default)
SpinGadget(#Spin_0, 80, 10, 30, 20, 1, 9)
TextGadget(#Text_0, 195, 15, 15, 15, "Dri", #PB_Text_Right)
SetGadgetText(#Spin_0, "1")
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindowID() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadgetID() ; Is it a gadget event?
EventType = EventType() ; The event type
;You can place code here, and use the result as parameters for the procedures
If Event = #PB_EventGadget
If GadgetID < #Button_R
;clic sur la grille
If GetGadgetState(GadgetID)
SetGadgetText(GadgetID, GetGadgetText(#Spin_0))
Else
SetGadgetText(GadgetID, "")
EndIf
ElseIf GadgetID = #Button_R
;résoud le sudoku
Sudoku_Init(3, 3)
For y = 0 To 8
For x = 0 To 8
valeur = Val(GetGadgetText(x + y*9))
Sudoku_Set(x, y, valeur)
Next x
Next y
passe = 0
While Sudoku_Solve()
passe + 1
Wend
If Sudoku_IsSolved()
MessageRequester("Su-Doku", "Résolu en " + Str(passe) + " passe(s)", #MB_ICONINFORMATION)
For y = 0 To 8
For x = 0 To 8
valeur = Sudoku_Get(x, y)
SetGadgetText(x + y*9, Str(valeur))
SetGadgetState(x + y*9, 1)
Next x
Next y
Else
MessageRequester("Su-Doku", "Impossible à résoudre", #MB_ICONERROR)
EndIf
ElseIf GadgetID = #Spin_0
SetGadgetText( #Spin_0, Str(GetGadgetState(#Spin_0)))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
