Public Class Form1
Dim a(16, 16) As Integer
Dim str1 = ""
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\MData.txt")
Dim lines() = Split(fileContents, vbNewLine)
For i = 0 To 14
Dim ba() = Split(lines(i), ",")
For j = 0 To 14
a(i + 1, j + 1) = ba(j)
Next
Next
For i = 0 To 16
a(0, i) = 2
a(i, 0) = 2
a(16, i) = 2
a(i, 16) = 2
Next
showArray0()
If visit(1, 1) Then
showArray()
Else
MsgBox("NoPath")
End If
End
End Sub
Sub showArray0()
Dim str3 = ""
For i = 1 To 15
For j = 1 To 15
If Not a(i, j) = 2 Then
str3 = str3 & "○"
Else
str3 = str3 & "●"
End If
Next
str3 = str3 & vbNewLine
Next
MsgBox(str3)
End Sub
Sub showArray()
Dim str3 = ""
For i = 1 To 15
For j = 1 To 15
If a(i, j) = 1 Then
str3 = str3 & "○"
Else
str3 = str3 & "●"
End If
Next
str3 = str3 & vbNewLine
Next
MsgBox(str3)
End Sub
Function visit(ByVal i As Integer, ByVal j As Integer) As Boolean
If a(15, 15) = 1 Then Return True
If a(i, j) = 0 Then
a(i, j) = 1
' Call showArray()
If Not a(15, 15) = 1 And Not (visit(i + 1, j) Or visit(i, j + 1) Or visit(i - 1, j) Or visit(i, j - 1)) Then
a(i, j) = 0
End If
End If
Return a(15, 15) = 1
End Function
End Class
沒有留言:
張貼留言