Sign in to follow this  
Followers 0
Kickassjoe

SuDoKu Generator

5 posts in this topic

#1 ·  Posted (edited)

I just finished the Sudoku Generator that I have been working on since friday. I just made the background, so don't tell me that it looks bad.

I hope you like it. Here is the source code.

;Script written by KickassJoe
#include<array.au3>
#include<GUIConstants.au3>

MakeTheBoard()

Func MakeTheBoard()
;columns
Dim $lcol[10][10], $pic[10], $box[10]
Global $sudoku[9][9]

For $a = 1 to 9
    For $b = 1 to 9
    $lcol[$b][$a] = $a
    $pic[$a] = $a
    Next
Next

For $x = 0 to 8
For $y = 0 to 8
 $i = Random(1,9,1)
 If CheckColumn($i,$y) AND CheckRow($i,$x) AND CheckSquare($i,$x,$y) Then
  $sudoku[$x][$y] = $i
 Else
  $sudoku[$x][$y] = "  "
 EndIf
Next
Next

GuiCreate("Sudoku Generator By KickassJoe!", 350, 275,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS));325 , 265
$BakPick = GUICtrlCreatePic("data\Title.bmp",0,0,350,275)
GuiCtrlSetState(-1,$GUI_DISABLE)

; GUI
$pic1 = GUICtrlCreatePic("data\Square.bmp", 5, 5,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 5, 95,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 5, 185,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 125, 5,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 125, 95,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 125, 185,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 245, 5,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 245, 95,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\Square.bmp", 245, 185,90,90)
GUICtrlSetState(-1,$GUI_DISABLE)

For $i = 0 to 8
    $lcol[$i][0] = GUICtrlCreateInput($sudoku[$i][0], 10, $i * 30 + 10, 20, 20)
    $lcol[$i][1] = GUICtrlCreateInput($sudoku[$i][1], 40, $i * 30 + 10, 20, 20)
    $lcol[$i][2] = GUICtrlCreateInput($sudoku[$i][2], 70, $i * 30 + 10, 20, 20)
    $lcol[$i][3] = GUICtrlCreateInput($sudoku[$i][3], 130, $i * 30 + 10, 20, 20)
    $lcol[$i][4] = GUICtrlCreateInput($sudoku[$i][4], 160, $i * 30 + 10, 20, 20)
    $lcol[$i][5] = GUICtrlCreateInput($sudoku[$i][5], 190, $i * 30 + 10, 20, 20)
    $lcol[$i][6] = GUICtrlCreateInput($sudoku[$i][6], 250, $i * 30 + 10, 20, 20)
    $lcol[$i][7] = GUICtrlCreateInput($sudoku[$i][7], 280, $i * 30 + 10, 20, 20)
    $lcol[$i][8] = GUICtrlCreateInput($sudoku[$i][8], 310, $i * 30 + 10, 20, 20)
    
    For $h = 0 to 8
    GUICtrlSetBkColor($lcol[$i][$h], $GUI_BKCOLOR_TRANSPARENT)
    GuiCtrlSetLimit($lcol[$i][$h], 1)

Next
Next

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        ;;;
    EndSelect
WEnd
Exit
EndFunc

Func CheckRow($number,$x)
For $y = 0 to 8
 If $sudoku[$x][$y] = $number Then
  Return 0
 EndIf
Next
Return 1
EndFunc

Func CheckColumn($number,$y)
For $x = 0 to 8
 If $sudoku[$x][$y] = $number Then
  Return 0
 EndIf
Next
Return 1
EndFunc

Func CheckSquare($number,$x1,$y1)
Local $square_x = Int($x1/3)
Local $square_y = Int($y1/3)
For $x = ($square_x*3) to ($square_x*3)+2
 For $y = ($square_y*3) to ($square_y*3)+2
     ;MsgBox(0, "checksquare cheking", "$sudoku[$x][$y] = " & $sudoku[$x][$y] & @CRLF & " $number = " & $number)
  If $sudoku[$x][$y] = $number Then
   Return 0
  EndIf
 Next
Next
Return 1
EndFunc

and here is the .zip, if you want to be able to read the sudokus more clearly, I suggest downloading this.

Sudoku.zip

SOURCE UPDATED: input limit set.

Edited by Kickassjoe

What goes around comes around... Payback's a bitch.

Share this post


Link to post
Share on other sites



set a limit on input boxes to 1 :whistle:

Share this post


Link to post
Share on other sites

You should make a checker.

Share this post


Link to post
Share on other sites

set a limit on input boxes to 1 :whistle:

thanks for the idea, source updated.


What goes around comes around... Payback's a bitch.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You should make a checker.

I might if I get bored over my 5-day weekend.

EDIT: the checker is being worked on now, kind of works, kind of doesn't. I'm leaving in less than an hour, but when I get back from a friend's house tomorrow, I will continue to work on it.

Edited by Kickassjoe

What goes around comes around... Payback's a bitch.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0