Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Mi Ultima Gran Ayuda Sobre Como No Repetirse El 9 En Mi Sudoku Ayudarme Urgente !!

Estas en el tema de Mi Ultima Gran Ayuda Sobre Como No Repetirse El 9 En Mi Sudoku Ayudarme Urgente !! en el foro de Visual Basic clásico en Foros del Web. Hola a todos es que estoy desesperado el martes pasado entregue mi sudoku que tenia hecho y hoy me ha dicho que si no quitaba ...
  #1 (permalink)  
Antiguo 09/03/2007, 10:33
mfc
 
Fecha de Ingreso: febrero-2007
Mensajes: 33
Antigüedad: 17 años, 2 meses
Puntos: 0
Exclamación Mi Ultima Gran Ayuda Sobre Como No Repetirse El 9 En Mi Sudoku Ayudarme Urgente !!

Hola a todos es que estoy desesperado el martes pasado entregue mi sudoku que tenia hecho y hoy me ha dicho que si no quitaba los 9 repetidos estaba suspendido de la recuperacion de programacion del primer curso de infromatica este año estoy en segundo y ya estoy apunto de acabar las clases para ir a practicas y para ir tengo de aprovar la programacion y me ha dicho el profesor que el lunes lo tengo que entregar y ya no se que hacer y queria pediros un gran favor es de poderme ayudarme con acabar el sudoku os lo voy a agradecer muchisimo, el problema que tengo es que salen repetidos los numeros los 9 salen 4 o 5 veces repetidos y ya no se que hacer ya me ayudo un usuario de este foro llamado o kool que me ayudo bastante y le doy las gracias pero es que no se donde encontrar el error alguien sabe de donde sale, que los 9 salgan repetidos.

aqui os dejo el codigo haver si os puede ayudar y si necesitais el programa os lo paso por correo encantado ayudarme porfa.

-------------------------------------------------
Const Gris As Long = &HFFFFFF

Private SudokuGrid(81) As Integer
Private SudokuTemp(81) As String
Private SudokuSolution(81) As String
--------------------------------------------------
Private Sub cmdGenerar_Click()

While Not CreateSudokuGrid()

Wend

lblDone.Visible = False


SolutionShown = False

If SolutionShown Then

For i = 1 To 81

Text1(i).Text = SudokuTemp(i)

Next i

Else

For i = 1 To 81
SudokuTemp(i) = Text1(i).Text
Text1(i).Text = SudokuSolution(i)

Next

End If


End Sub
-----------------------------------------------------
Private Function CreateSudokuGrid() As Boolean

Dim b, i, j, k As Integer
Dim numRand As Integer
Dim ValIsOK(9) As Boolean
Dim valsOK As Integer

valsOK = 0


lblConfiguring.Visible = True

For i = 1 To 81

Text1(i).Text = ""
Text1(i).BackColor = Gris
Text1(i).Visible = False
SudokuSolution(i) = ""

Next i

lblConfiguring.Visible = True
lblConfiguring.Refresh

For i = 1 To 81
If True Then

valsOK = GetValidVals(i, ValIsOK)
If valsOK <= 0 Then

CreateSudokuGrid = False
End If

Randomize
numRand = Int(Rnd * valsOK + 1)

k = 0
For j = 0 To 8
If ValIsOK(j) Then
k = k + 1
If k = numRand Then
Exit For
End If
End If
Next j

Text1(i).Text = CStr(j)
Text1(i).BackColor = Gris

End If

Next i

lblConfiguring.Visible = False
For i = 1 To 81

SudokuSolution(i) = Text1(i).Text
numRand = Rnd(CInt(3) + 1) + 1
If numRand > 1 Then

Text1(i).Text = ""
Text1(i).BackColor = Gris
Text1(i).Enabled = True

Else
Text1(i).Enabled = False

End If
Text1(i).Visible = True

Next i
CreateSudokuGrid = True

End Function
----------------------------------------------------------

Private Function GetValidVals(ByVal Location As Integer, ByRef ValidVals() As Boolean) As Integer

Dim i, j, k As Integer
Dim row, col As Integer
Dim numStr As String
Dim numOK As Boolean
Dim retVal As Integer

retVal = 0
For i = 1 To 9
numOK = True
numStr = CStr(i)
For j = 1 To 9

k = (Int((Location - 1) / 9) * 9) + j
If Text1(k).Text = numStr Then

numOK = False

Exit For

End If

Next j

If numOK Then
For j = 1 To 9
k = (((Location - 1) Mod 9) + 1) + ((j - 1) * 9)
If Text1(k).Text = numStr Then

numOK = False

Exit For

End If

Next j

End If

If numOK Then

row = Int(Int((Location - 1) / 9) / 3)
col = Int(((Location - 1) Mod 9) / 3)
For j = 1 To 9
k = (((row * Rnd) + Int((j - 1) / 9)) * 9) + (col * 9) + ((j - 1) Mod 3) + 1

If Text1(k).Text = numStr Then

numOK = False

Exit For

End If

Next j

End If

ValidVals(i) = numOK
If numOK Then

retVal = retVal

End If

Next i

GetValidVals = retVal

End Function

------------------------------------------------
  #2 (permalink)  
Antiguo 10/03/2007, 03:13
mfc
 
Fecha de Ingreso: febrero-2007
Mensajes: 33
Antigüedad: 17 años, 2 meses
Puntos: 0
Re: Mi Ultima Gran Ayuda Sobre Como No Repetirse El 9 En Mi Sudoku Ayudarme Urgente

nadie me puede ayudar porfa!!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:19.