Sign in to follow this  
Followers 0
Kickassjoe

Sudoku Check help

4 posts in this topic

#1 ·  Posted (edited)

I have been trying to get my sudoku's check function to work for a while now, and I have no idea what I am doing wrong.

when I change the generated numbers to numbers that wouldn't fit in the sudoku, it marks them wrong, but when I change numbers that were originally "" when the sudoku was generated, and they are wrong, nothing happens.

Download for all of the pics + source: Sudoku.zip

CODE
#include<GUIConstants.au3>
#include<array.au3>
Global $sudoku[9][9], $SudokuCheck[9][9]
Global $lcol[10][10], $pic[10], $box[10]

MakeTheBoard()

Func MakeTheBoard()
;columns



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 Joe Rankin!", 350, 325,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS));350,275
$BakPick = GUICtrlCreatePic("data\Title.bmp",0,0,350,325)
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

;$pic1 = GUICtrlCreatePic("data\ButtonIMG.bmp", 130, 295,80,20)
;GUICtrlSetState(-1,$GUI_DISABLE)
$pic1 = GUICtrlCreatePic("data\ButtonIMG.bmp", 20, 295,80,20)
GUICtrlSetState(-1,$GUI_DISABLE)
$checkbutton = GUICtrlCreateLabel("Check", 130,295, 80, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$generatebutton = GUICtrlCreateLabel("New", 20, 295, 80, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState()
While 1
        $msg = GUIGetMsg()
                    Select
                        Case $msg = $GUI_EVENT_CLOSE
                            Exit
                            
                          ;generate button
                                        Case $msg = $generatebutton
                For $x = 0 to 8
                    For $y = 0 to 8
                        If $sudoku[$x][$y] <> "" Then $sudoku[$x][$y] = ""
                        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
                            
                            For $x = 0 to 8
                                For $y = 0 to 8
                                    GUICtrlSetData($lcol[$x][$y], $sudoku[$x][$y])
                                Next
                            Next
                          ;check button
            Case $msg = $checkbutton
                For $x = 0 to 8
                    For $y = 0 to 8
                        If $sudoku[$x][$y] = "" Then $sudoku[$x][$y] = GUICtrlRead($lcol[$x][$y])
 If  _CheckColumn($sudoku[$x][$y],$y) AND _CheckRow($sudoku[$x][$y],$x) AND _CheckSquare($sudoku[$x][$y],$x,$y) Then
     GUICtrlSetBkColor($lcol[$x][$y],0xFF0000);red
    ;$sudoku[$x][$y] = GuiCtrlRead($lcol[$x][$y])
 Else
     GUICtrlSetBKColor($lcol[$x][$y],0xFFFFFF);white
    ;$sudoku[$x][$y] = GuiCtrlRead($lcol[$x][$y])
 EndIf
;$sudoku[$x][$y] = GuiCtrlRead($lcol[$x][$y])
Next
Next
EndSelect
    WEnd
    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
  If $sudoku[$x][$y] = $number Then
   Return 0
  EndIf
 Next
Next
Return 1
EndFunc







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

Func _CheckColumn($number,$y)
For $x = 0 to 8
 If GUICtrlRead($lcol[$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
  If GUICtrlRead($lcol[$x][$y]) = $number Then
   Return 0
  EndIf
 Next
Next
Return 1
EndFunc
Edited by Kickassjoe

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

Share this post


Link to post
Share on other sites



anyone?


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

Share this post


Link to post
Share on other sites

Love the use of the 3x3 bmp for the GUI background, kinda neat!!

i think there may be a prob when you start with

For $a = 1 to 9

For $b = 1 to 9

$lcol[$b][$a] = $a

$pic[$a] = $a

Next

Next

and every other time you use 0 instead of 1

For $x = 0 to 8

For $y = 0 to 8

Just a thought

BTW... are you finished with the Monopoly Game????

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

that didn't work... didn't fix the problem I had, or do anything else, in fact, I could probably just delete that whole loop lol.

as for monopoly, I have been busy with other things, and I don't really have time to fix this, but I thought it would be a quick fix, and yet I still don't know whats wrong with it. I think I will finish monopoly this weekend, (fix all of the bugs, finish chance and community chest, and jail, a few others) or sometime soon. After that, I will have to learn some TCP functions, and make it multi-player, because I have been wanting to play it against friends for a while...


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