Berikut Source Codenya :
Public Class Form1
Dim N As Integer
Dim arrKuda(0, 0), p, x, y, noStep As Integer
Dim arrH() As Integer = {0, 1, 2, 2, 1, -1, -2, -2, -1}
Dim arrV() As Integer = {0, -2, -1, 1, 2, 2, 1, -1, -2}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ReDim arrKuda(CInt(TextBox1.Text) + 4, (CInt(TextBox1.Text) + 4))
For i = 1 To CInt(TextBox1.Text) + 4
For j = 1 To CInt(TextBox1.Text) + 4
If i < 3 Or i > CInt(TextBox1.Text) + 2 Or j < 3 Or j > CInt(TextBox1.Text) + 2 Then
arrKuda(i, j) = 99
Else
arrKuda(i, j) = 0
End If
Next
Next
x = CInt(TextBox2.Text) + 2
y = CInt(TextBox3.Text) + 2
noStep = 1
arrKuda(y, x) = noStep
p = 1
Do While p <= 8
If arrKuda(y + arrV(p), x + arrH(p)) = 0 Then
y += arrV(p)
x += arrH(p)
noStep += 1
arrKuda(y, x) = noStep
p = 1
Else
p += 1
End If
Loop
For i = 3 To CInt(TextBox1.Text) + 2
For j = 3 To CInt(TextBox1.Text) + 2
Dim a As New Label
a.Text = arrKuda(i, j) & vbTab
a.Width = 35
a.Height = 35
a.Left = ((j – 2) – 1) * 38 + 170
a.Top = ((i – 2) – 1) * 38 + 200
Me.Controls.Add(a)
Next
Next
End Sub
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
N = CInt(TextBox1.Text)
If N < 3 Then
TextBox1.Focus()
End If
End Sub
Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
If Not IsNumeric(TextBox2.Text) Then
TextBox2.Focus()
End If
If Not CInt(TextBox2.Text) >= 1 And CInt(TextBox2.Text) <= N Then
TextBox2.Focus()
End If
End Sub
Private Sub TextBox3_Leave(sender As Object, e As EventArgs) Handles TextBox3.Leave
If Not IsNumeric(TextBox3.Text) Then
TextBox3.Focus()
End If
End Sub
End Class
Berikut screenshotnya :
Di bawah ini adalah gambar tampilan awal permainan tersebut.
Saya menggunakan 3 buah textbox sebagai inputan user Dan 1 button untuk play

Di bawah ini adalah gambar hasil dari permainan knight tour

NB : Hasil permainan tersebut menggunakan label create on the fly sehingga lebih cepat pembuatannya dan praktis.
Sekian postingan dari saya,semoga postingan ini berguna bagi sobat bloggers yang ingin tau tentang knight tour.
Untuk Videonya silakan klik link di bawah ini :
.:Terima kasih Selamat Mencoba:.
4 komentar:
Makasih gan atas informasinya
Informasi tersebut sangat bermanfaat sekali bagi saya.
Video nya juga cukup membantu saya dalam mengerti cara kerja knight tour
Tnx Source Codenya, cuman kalau bisa agar admin blog mengubah tampilan blog agar lebih mudah untuk di comment secara lansung tanpa harus dibawah ke page lain
Posting Komentar