Saman_12
پنج شنبه 08 خرداد 1393, 02:05 صبح
سلام میدونم تکرارییه و خیلی بحث شده ولی میخوام بدونم مشکل کارم کجاست (فقط چند حالت رو باید برسی کنه نه 92 تا) هنوز قسمت بازگشتیشو ننوشتم :
Private Function GetPossibleMatrix(Optional n As Int32 = 8) As List(Of Int32(,))
Dim matrixlist As New List(Of Int32(,))
Dim matrix(n - 1, n - 1) As Int32
Dim newmatrix(n - 1, n - 1) As Int32
Dim nc As Int32
For fx As Int32 = 0 To n - 1
For fy As Int32 = 0 To n - 1
matrix = SetMatrix(matrix, fx, fy)
nc = 1
For y As Int32 = 0 To n - 1
For x As Int32 = 0 To n - 1
newmatrix = SetMatrix(matrix, x, y)
If Not matrix.Equals(newmatrix) Then
matrix = newmatrix
nc += 1
End If
Next
Next
Console.WriteLine(nc)
matrixlist.Add(matrix.Clone)
Array.Clear(matrix, 0, matrix.Length)
Array.Clear(newmatrix, 0, newmatrix.Length)
Next
Next
Return matrixlist
End Function
Private Function SetMatrix(matrix(,) As Int32, x As Int32, y As Int32) As Int32(,)
Dim newmatrix(,) As Int32 = matrix.Clone
Dim n As Int32 = Math.Sqrt(matrix.Length) - 1
Dim fb, sb As Boolean
Dim fx, fy As Int32
Dim sx, sy As Int32
If newmatrix(x, y) = 0 Then
newmatrix(x, y) = 1
For xy As Int32 = 0 To n
If (x - xy = 0 Or y - xy = 0) And Not fb Then fx = x - xy : fy = y - xy : fb = True
If (x - xy = 0 Or y + xy = n) And Not sb Then sx = x - xy : sy = y + xy : sb = True
Next
For xy As Int32 = 0 To n
If matrix(xy, y) = 1 Then Return matrix
If matrix(x, xy) = 1 Then Return matrix
If xy + fx <= n And xy + fy <= n AndAlso matrix(xy + fx, xy + fy) = 1 Then Return matrix
If xy + sx <= n And sy - xy >= 0 AndAlso matrix(xy + sx, sy - xy) = 1 Then Return matrix
If Not xy = x Then newmatrix(xy, y) = -1
If Not xy = y Then newmatrix(x, xy) = -1
If xy + fx <= n And xy + fy <= n And Not (xy + fx = x Or xy + fy = y) Then newmatrix(xy + fx, xy + fy) = -1
If xy + sx <= n And sy - xy >= 0 And Not (xy + sx = x Or sy - xy = y) Then newmatrix(xy + sx, sy - xy) = -1
Next
End If
Return newmatrix
End Function
ولی کانتر nc بجای 8 میشه 65!!
به نظر شما مشکلش کجاست؟ (احتمالا از بنیاد خرابه!)
اینم کل برنامه :
Private Function GetPossibleMatrix(Optional n As Int32 = 8) As List(Of Int32(,))
Dim matrixlist As New List(Of Int32(,))
Dim matrix(n - 1, n - 1) As Int32
Dim newmatrix(n - 1, n - 1) As Int32
Dim nc As Int32
For fx As Int32 = 0 To n - 1
For fy As Int32 = 0 To n - 1
matrix = SetMatrix(matrix, fx, fy)
nc = 1
For y As Int32 = 0 To n - 1
For x As Int32 = 0 To n - 1
newmatrix = SetMatrix(matrix, x, y)
If Not matrix.Equals(newmatrix) Then
matrix = newmatrix
nc += 1
End If
Next
Next
Console.WriteLine(nc)
matrixlist.Add(matrix.Clone)
Array.Clear(matrix, 0, matrix.Length)
Array.Clear(newmatrix, 0, newmatrix.Length)
Next
Next
Return matrixlist
End Function
Private Function SetMatrix(matrix(,) As Int32, x As Int32, y As Int32) As Int32(,)
Dim newmatrix(,) As Int32 = matrix.Clone
Dim n As Int32 = Math.Sqrt(matrix.Length) - 1
Dim fb, sb As Boolean
Dim fx, fy As Int32
Dim sx, sy As Int32
If newmatrix(x, y) = 0 Then
newmatrix(x, y) = 1
For xy As Int32 = 0 To n
If (x - xy = 0 Or y - xy = 0) And Not fb Then fx = x - xy : fy = y - xy : fb = True
If (x - xy = 0 Or y + xy = n) And Not sb Then sx = x - xy : sy = y + xy : sb = True
Next
For xy As Int32 = 0 To n
If matrix(xy, y) = 1 Then Return matrix
If matrix(x, xy) = 1 Then Return matrix
If xy + fx <= n And xy + fy <= n AndAlso matrix(xy + fx, xy + fy) = 1 Then Return matrix
If xy + sx <= n And sy - xy >= 0 AndAlso matrix(xy + sx, sy - xy) = 1 Then Return matrix
If Not xy = x Then newmatrix(xy, y) = -1
If Not xy = y Then newmatrix(x, xy) = -1
If xy + fx <= n And xy + fy <= n And Not (xy + fx = x Or xy + fy = y) Then newmatrix(xy + fx, xy + fy) = -1
If xy + sx <= n And sy - xy >= 0 And Not (xy + sx = x Or sy - xy = y) Then newmatrix(xy + sx, sy - xy) = -1
Next
End If
Return newmatrix
End Function
ولی کانتر nc بجای 8 میشه 65!!
به نظر شما مشکلش کجاست؟ (احتمالا از بنیاد خرابه!)
اینم کل برنامه :