帮看看该怎样改
Public Board(7, 7) As IntegerPublic HTry1 As Variant
Public HTry2 As Variant
Type Stack
i As Integer
j As Integer
director As Integer
End Type
Public sta(63) As Stack
Public top As Integer
Sub main()
HTry1 = Array(-2, -1, 1, 2, 2, 1, -1, -2)
HTry2 = Array(1, 2, 2, 1, -1, -2, -2, -1)
top = -1
Dim i As Integer
Dim j As Integer
For i = 0 To 7
For j = 0 To 7
Board(i, j) = 0
Next j
Next i
Form1.Show
End Sub
Sub Display(m As Integer)
Form1.Image1(m).Picture = LoadPicture("C:\Users\Administrator.WIN-AI135UU378T\Desktop\桌面管理库\horse.jpg")
End Sub
Sub black(m As Integer)
Form1.Image1(m).Picture = LoadPicture("C:\Users\Administrator.WIN-AI135UU378T\Desktop\桌面管理库\black.jpg")
End Sub
Sub white(m As Integer)
Form1.Image1(m).Picture = LoadPicture("C:\Users\Administrator.WIN-AI135UU378T\Desktop\桌面管理库\white.jpg")
End Sub
Sub InitLocation(xi As Integer, yj As Integer)
Dim x As Integer
Dim y As Integer
top = top + 1
sta(top).i = xi
sta(top).j = yj
sta(top).director = -1
Board(xi, yi) = top + 1
x = sta(top).i
y = sta(top).j
Call TryPath(x, y)
End Sub
Sub TryPath(i As Integer, j As Integer)
Dim find%, director%, number%, min%
Dim i1%, j1%, h%, k%, s%
Dim a%(7), b1%(7), b2%(7), d%(7)
While top > -1
For h = 0 To 7
number = 0
i = sta(top).i + HTry1(h)
j = sta(top).j + HTry1(h)
b1(h) = i
b2(h) = j
If Board(i, j) = 0 And i >= 0 And i < 8 And j >= 0 And j < 8 Then '越界了
For k = 0 To 7
i1 = b1(h) + HTry1(k)
j1 = b2(h) + HTry2(k)
If Board(i1, j1) = 0 And i1 >= 0 And i1 < 8 And j1 >= 0 And j1 < 8 Then '越界了
number = number + 1
End If
Next k
a(h) = number
End If
Next h
For h = 0 To 7
min = 9
For k = 0 To 7
If min > a(k) Then
min = a(k)
d(h) = k
s = k
End If
Next k
a(s) = 9
Next h
director = sta(top).director
If top >= 63 Then DoEvents
find = 0
For h = director + 1 To 7
i = sta(top).i + HTry1(d(h))
j = sta(top).j + HTry2(d(h))
If Board(i, j) = 0 And i >= 0 And i < 8 And j >= 0 And j < 8 Then '越界了
find = 1
Exit For
End If
Next h
If find = 1 Then
sta(top).director = director
top = top + 1
sta(top).i = i
sta(top).j = j
Call Display(i * 8 + j)
sta(top).director = -1
Board(i, j) = top + 1
Else
Board(sta(top).i, sta(top).j) = 0
If sta(top).i Mod 2 = 0 And sta(top).j Mod 2 = 0 Then
Call white(sta(top).i * 8 + sta(top).j)
ElseIf sta(top).i Mod 2 = 0 And sta(top).j Mod 2 <> 0 Then
Call black(sta(top).i * 8 + sta(top).j)
ElseIf sta(top).i Mod 2 <> 0 And sta(top).j Mod 2 = 0 Then
Call black(sta(top).i * 8 + sta(top).j)
ElseIf sta(top).i Mod 2 <> 0 And sta(top).j Mod 2 <> 0 Then
Call white(sta(top).i * 8 + sta(top).j)
End If
top = top - 1
End If
Wend
End Sub