Depth First Search with Visual Basic
Depth First Search (DFS) is a kind of tracking method implemented in artificial intelligence. The goal is to finding a way out from some deviate paths. There are various examples solved with this method such Labyrinth. Labyrinth – as we all know – is a brain game that playing a rule getting an exit door by entering a confusing tracks map.
For couples years ago (2001?), I was excited with this theory. And finally realized to did it by made an application with the rule of Labyrinth. But, first, I’d like to tell you a little about DFS. The DFS tracking process begin from the root node and continued to the next level node below as sequentially.
As the picture shown above, the real path solved with DFS method are A-B-D-E-C. In a short, the core processes explained by the following priorities direction formulas: left, down, right and up. Let’s see the core code written on Visual Basic 6 below:
For couples years ago (2001?), I was excited with this theory. And finally realized to did it by made an application with the rule of Labyrinth. But, first, I’d like to tell you a little about DFS. The DFS tracking process begin from the root node and continued to the next level node below as sequentially.
As the picture shown above, the real path solved with DFS method are A-B-D-E-C. In a short, the core processes explained by the following priorities direction formulas: left, down, right and up. Let’s see the core code written on Visual Basic 6 below:
Public Sub cekMap()And this is my application run-time pictures:
lpKeyName = Str(dum_pos)
baca = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, temp, Len(temp), lpFileName)
lpString = Trim(temp)
nilai = Val(lpString)
End Sub
Public Sub analisa_1() 'OTAK ANALISA DEPTH FIRST SEARCH
kiri = False
bawah = False
kanan = False
atas = False
'cek kiri
dum_pos = posisi
dum_pos = dum_pos - 1
cekMap
If berikutnya_adalah_jalan Then
kiri = True
ElseIf berikutnya_adalah_pintu_keluar Then
X = MsgBox("Aha, jalan keluar ditemukan", vbInformation, "Perhatian")
End If
'cek bawah
dum_pos = posisi
dum_pos = dum_pos + 20
cekMap
If berikutnya_adalah_jalan Then
bawah = True
ElseIf berikutnya_adalah_pintu_keluar Then
X = MsgBox("Aha, jalan keluar ditemukan", vbInformation, "Perhatian")
End If
'cek kanan
dum_pos = posisi
dum_pos = dum_pos + 1
cekMap
If berikutnya_adalah_jalan Then
kanan = True
ElseIf berikutnya_adalah_pintu_keluar Then
X = MsgBox("Aha, jalan keluar ditemukan", vbInformation, "Perhatian")
End If
'cek atas
dum_pos = posisi
dum_pos = dum_pos - 20
cekMap
If berikutnya_adalah_jalan Then
atas = True
ElseIf berikutnya_adalah_pintu_keluar Then
X = MsgBox("Aha, jalan keluar ditemukan", vbInformation, "Perhatian")
End If
End Sub
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Anonymous said,
Monday, March 17, 2008 5:40:00 PM
hai..hanya untuk bertanya..boleh tak..depth first search algo di applykan dlm javascript dan bolehkah format yang digunakan berserta database bukan hanya text file..thanks
Eko Wahyudiharto said,
Tuesday, March 18, 2008 9:16:00 AM
@Anonymous : Saya pikir, boleh-boleh saja.
hello said,
Friday, June 26, 2009 8:28:00 PM
bagaimana sich caranya pake dfs untuk tic tac toe, ..thanks
Eko Wahyudiharto said,
Saturday, June 27, 2009 4:53:00 AM
Pada dasarnya, polanya hampir sama hanya saja lebih agak sedikit rumit. Banyak artikel & referensi sudah tersedia dari internet. Btw, this link is a good start.