原帖由 xliz 于 2005-10-19 17:22 发表
怎么这程序的可读性这么差~~~呵呵……说笑~~
那个。。。。个人问题。。。。
关于自动解题的那段代码。。。。
E文不好,所以变量名字,想到什么写什么,跳转也是,
再加上用中文的输入法要切来切去,麻烦,所以懒得写注释。
关于解题的代码。。。
Private Sub Command3_Click()
Dim ZL(15, 15) As Byte
Dim ZLG(15, 15) As Byte
Dim ZLE(15, 15) As Byte
Dim Z(1 To 255) As Byte
Dim zlx As Integer, zly As Integer
Dim f As Integer, f1 As Integer, f2 As Integer
Dim a As Byte, b As Byte
Dim at As Integer
Dim x As Integer, y As Integer
Dim t As Integer
Dim c As String
Dim m As Integer
If FS > 40 Then m = MsgBox("当前迷题的步数过多," & vbCrLf & "运算会花费很多时间" & vbCrLf & "是否进行运算", vbYesNo, "步数过多")
If m = 7 Then Exit Sub
Timer1.Enabled = True
tme = 0
Label5.Caption = ""
List1.Enabled = False
Command3.Enabled = False
If Check1.Value = 1 Then Form2.SetFocus
Open Fileaddress For Binary As #1
Form2.Label1.Caption = ""
b = 1
x = SX
y = SY
ZLG(x, y) = 1
GetData:
Get #1, AR + at, a
If a <> 255 Then
If a = 7 Then ZLG(zlx, zly) = 3
If a = 2 Or a = 3 Or a = 4 Or a = 8 Then
MsgBox "发现无法解决的块,无法解题", vbOKOnly, "警告"
Text1.Text = "无法解题"
Timer1.Enabled = False
Label5.Caption = "总计用时" & tme & "秒,共用步数" & b & "步"
List1.Enabled = True
Command3.Enabled = True
Close #1
Exit Sub
End If
ZL(zlx, zly) = a
zlx = zlx + 1
End If
If a = 255 Then
Get #1, AR + at + 1, a
If a = 255 Then
For f = 1 To LX - 2
If ZLG(f, SY) <> 5 Then
If ZL(f, SY) <> ZL(SX, SY) Then ZLG(f, SY) = 3
End If
If ZLG(f, EY) <> 5 Then
If ZL(f, EY) <> ZL(EX, EY) Then ZLG(f, EY) = 3
End If
Next f
GoTo NF
End If
zly = zly + 1
zlx = 0
End If
at = at + 1
GoTo GetData
NF:
Z(b) = Z(b) + 1
If Check1.Value = 1 Then
Form2.Label1.Caption = ""
For f = 1 To FS - 1
Form2.Label1.Caption = Form2.Label1.Caption & Z(f)
Next f
End If
DoEvents
If b > 2 Then
If Z(b - 1) = 1 And Z(b) = 3 Then GoTo NF
If Z(b - 1) = 2 And Z(b) = 4 Then GoTo NF
If Z(b - 1) = 3 And Z(b) = 1 Then GoTo NF
If Z(b - 1) = 4 And Z(b) = 2 Then GoTo NF
End If
If Z(b) <= 4 Then
Select Case Z(b)
Case 1
y = y - 1
If y < 0 Then y = y + 1: GoTo NF
If ZLG(x, y) <> 0 Then y = y + 1: GoTo NF
Case 2
x = x + 1
If x > (LX - 1) Then x = x - 1: GoTo NF
If ZLG(x, y) <> 0 Then x = x - 1: GoTo NF
Case 3
y = y + 1
If y > (LY - 1) Then y = y - 1: GoTo NF
If ZLG(x, y) <> 0 Then y = y - 1: GoTo NF
Case 4
x = x - 1
If x < 0 Then x = x + 1: GoTo NF
If ZLG(x, y) <> 0 Then x = x + 1: GoTo NF
End Select
Else
TB:
For f = b To FS - 1
Z(f) = 0
Next f
b = b - 1
ZLG(x, y) = 0
For f = 1 To LX - 1
If ZLG(f, y) = 1 Then GoTo TB2
Next f
For f = 1 To LX - 1
If ZLG(f, y) = 2 Then ZLG(f, y) = 0
Next f
TB2:
If b = 0 Then
Text1.Text = "无解"
Timer1.Enabled = False
Label5.Caption = "总计用时" & tme \ 2 & "秒,共用步数" & b & "步"
List1.Enabled = True
Command3.Enabled = True
Close #1
Exit Sub
End If
Select Case Z(b)
Case 1
y = y + 1
Case 2
x = x - 1
Case 3
y = y - 1
Case 4
x = x + 1
End Select
GoTo NF
End If
b = b + 1
If (FS - b) < (Abs(x - EX) + Abs(y - EY)) Then GoTo TB
If b > FS Then
GoTo TB
End If
ZLG(x, y) = 1
If Check1.Value = 1 Then
Form2.Label2.Caption = ""
For f = 0 To LY - 1
For f1 = 0 To LX - 1
Form2.Label2.Caption = Form2.Label2.Caption & ZLG(f1, f) & " "
Next f1
Form2.Label2.Caption = Form2.Label2.Caption & vbCrLf
Next f
End If
If y > 0 And y < LY - 1 And x > 0 And x < LX - 1 Then
For f = 1 To LX - 2
If ZLG(f, y) = 2 Then Exit For
If ZLG(f, y) = 0 Then
If ZL(f, y) <> ZL(x, y) Then ZLG(f, y) = 2
End If
Next f
End If
If x = EX And y = EY Then GoTo TF
GoTo NF
TF:
For f1 = 1 To LY - 2
t = 0
For f = 1 To LX - 2
If ZLG(f, f1) = 1 Then
ZLE(f, f1) = (ZL(f, f1) Xor 1) + 1
Else
ZLE(f, f1) = (ZL(f, f1) Xor 0) + 1
End If
t = t + ZLE(f, f1)
Next f
If t <> LX - 2 And t <> (LX - 2) * 2 Then
ZLG(x, y) = 0
Z(b) = 0
b = b - 1
Select Case Z(b)
Case 1
y = y + 1
Case 2
x = x - 1
Case 3
y = y - 1
Case 4
x = x + 1
End Select
GoTo NF
End If
Next f1
Text1.Text = ""
For f2 = 1 To b - 1
Select Case Z(f2)
Case 1
c = "↑"
Case 2
c = "→"
Case 3
c = "↓"
Case 4
c = "←"
End Select
Text1.Text = Text1.Text & sl(CStr(f2)) & " " & c & vbCrLf
Next f2
Timer1.Enabled = False
Label5.Caption = "总计用时" & tme \ 2 & "秒,共用步数" & b & "步"
List1.Enabled = True
Command3.Enabled = True
Close #1
End Sub
什么时候有空,再从头开始写一个。。。。
[ 本帖最后由 DOT-X 于 2005-10-19 20:04 编辑 ] |