Jump to content
Sign in to follow this  
danny0

Condense Function

Recommended Posts

danny0

I have a working function for my sudoku script, but it is kinda long. I was wondering if any one could condense it for me. $Row1Array is an array containing the known values written into the boxes in row 1. $TotalPossibilities[$j][$k] = "1,2,3,4,5,6,7,8,9" and is the possible values of each box. $j = row number and $k = column number.

Func EliminatePossibilities()
Local $TotalBoxPossibilities
    For $x = 1 To 9
        $Search = _ArraySearch($Row1Array, $x)                                 ;try to find a number
        If $Search <> -1 Then                                   ;if search successful then
            $Number = GUICtrlRead($Box[1][$Search])                        ;number written in row 1
            If $Search <> 9 And $Search <> 1 Then                   ;if the box number is not 9 then
                $index = ($Search-1)                                ;sets index variable
                For $y = 1 To $index
                    $start = StringInStr($TotalBoxPossibilities[1][$y], "," & $Number);tries to find the number in $Possibilities
                    If $start <> 0 Then                 ;if number found then delete value from string
                        $Temporary = StringSplit($TotalBoxPossibilities[1][$y], ",")    ;splits the possibility string into an array
                        $TemporaryPlace = _ArraySearch($Temporary, $Number) ;index of the number
                        _ArrayDelete($Temporary, $TemporaryPlace)
                        $TemporaryString = _ArrayToString($Temporary, ",")
                        $TotalBoxPossibilities[1][$y] = $TemporaryString
                    EndIf
                Next
                $index = ($Search+1)
                For $z = $index To 9
                    $start = StringInStr($TotalBoxPossibilities[1][$z], "," & $Number)
                    If $start <> 0 Then
                        $Temporary = StringSplit($TotalBoxPossibilities[1][$z], ",")
                        $TemporaryPlace = _ArrayToString($Temporary, ",")
                        _ArrayDelete($Temporary, $TemporaryPlace)
                        $TotalBoxPossibilities[1][$z] = $TemporaryString
                    EndIf
                Next
            ElseIf $Search = 9 Then
                For $y = 1 To 8
                    $start = StringInStr($TotalBoxPossibilities[1][$y], "," & $Number)
                    If $start <> 0 Then
                        $Temporary = StringSplit($TotalBoxPossibilities[1][$y], ",")
                        $TemporaryPlace = _ArraySearch($Temporary, $Number)
                        _ArrayDelete($Temporary, $TemporaryPlace)
                        $TemporaryString = _ArrayToString($Temporary, ",")
                        $TotalBoxPossibilities[1][$y] = $TemporaryString
                    EndIf
                Next
            ElseIf $Search = 1 Then
                For $y = 2 To 9
                    $start = StringInStr($TotalBoxPossibilities[1][$y], ",")
                    $TemporaryPlace = _ArraySearch($Temporary, $Number)
                    _ArrayDelete($Temporary, $TemporaryPlace)
                    $TemporaryString = _ArrayToString($Temporary, ",")
                    $TotalBoxPossibilities[1][$y] = $TemporaryString
                Next
            EndIf
        EndIf
    Next
EndFunc

Thanks to anyone who makes an attempt! Thanks a lot to anyone one condenses it!

Share this post


Link to post
Share on other sites
danny0

I would look at other peoples sudoku scripts. Heres mine: http://www.autoitscript.com/forum/index.ph...1&hl=sudoku very rough coding, but it might give you ideas. Other members have made similar scripts before.

I've looked at your example already. I have it on my computer to see how it works. Can you condense this function or not? Do you have any advice since you've already made a sudoku program?

Share this post


Link to post
Share on other sites
qazwsx

i would use a three dimensional array. $possibilities[column][row][number] = 0 or 1 for possible or not. I think that will make the logic easier.

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  

×