1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Public Class Pathfinding
Public movepath As New List(Of UInteger)
Public Cells As New List(Of CellInfo)
Public cellactuel As UInteger
Public cellarrivée As UInteger
Public IsPath As Boolean = False
Public CanMove As Boolean = True
Public Sub FindPath(ByVal listcellopen As List(Of UInteger), ByVal actuell As UInteger, ByVal arrive As UInteger)
'--Variables--
cellactuel = actuell
cellarrivée = arrive
movepath.Add(cellactuel)
'--Vérification--
If cellactuel = cellarrivée Then
Exit Sub
End If
'--Cellules--
For i = 0 To 559
Dim obstacle As Boolean = False
If listcellopen.Contains(i) Then
obstacle = False
Else
obstacle = True
End If
Cells.Add(New CellInfo(i, obstacle))
Next
'--FindPath--
While Not cellactuel = cellarrivée
'--Variables--
Dim casewalk As New List(Of Integer)
Dim x = Cells(cellactuel).X
Dim y = Cells(cellactuel).Y
'--Calcul H--
For i = 0 To 559
Cells(i).Calcul_H(Cells(cellarrivée).X, Cells(cellarrivée).Y)
Next
'--Calcul algo--
For i = 0 To Cells.Count - 1
If Cells(i).X = x And Cells(i).Y = y + 1 And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x And Cells(i).Y = y - 1 And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x - 1 And Cells(i).Y = y And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x + 1 And Cells(i).Y = y And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x + 1 And Cells(i).Y = y + 1 And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x - 1 And Cells(i).Y = y - 1 And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x - 1 And Cells(i).Y = y + 1 And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
If Cells(i).X = x + 1 And Cells(i).Y = y - 1 And Cells(i).obstacle = False Then
casewalk.Add(i)
End If
Next
'Une fois qu'on a nos 8 case ainsi que leur cout F rien de plus simple que le comparer
Dim H As Integer = 99999
Dim index As Integer
For i = 0 To casewalk.Count - 1
'F est inférieur il devient la meilleur case
If h > Cells(casewalk(i)).H Then
H = Cells(casewalk(i)).H
index = casewalk(i)
End If
Next
'On a la cell avec le cout F le plus bas :P
movepath.Add(index)
cellactuel = index
Cells(index).obstacle = True
End While
End Sub
End Class |
Partager