Re: Besoin d'aider pour mon pathfinding
J'ai essayer ... san succes j'ai essayer de traduire ton code (honte a moi ^^) sans succes (encore plus honte a moi) voici ce que j'ai obtenu en traduisant ton code
La class principale
Imports D2pReader.MapInformations
Imports D2pReader
Public Class clsAStar
#Region "Declarations"
Dim MAP_WIDTH As Integer
Dim MAP_HEIGHT As Integer
Dim MAPID As Long = 84674062
Dim CELLPOS(560) As Nods
Dim currentMap As Map
Dim finish_search As Boolean
Dim openList As List(Of Nods)
#End Region
#Region "Metode"
Public Function findPath(ByVal startId As Integer, ByVal endId As Integer) As List(Of Integer)
initializeCurrentMap()
Dim loc_1 As Integer = 0
Dim loc_2 As Integer = 0
Dim loc_3 As Integer = 0
Dim loc_4 As Integer = 0
Dim loc_5 As Integer = 0
While (loc_5 < MAP_HEIGHT)
loc_4 = 0
While (loc_4 < MAP_WIDTH)
CELLPOS(loc_3) = New Nods(loc_3, loc_1 + loc_4, loc_2 + loc_4)
loc_3 += 1
loc_4 += 1
End While
loc_1 += 1
loc_4 = 0
While (loc_4 < MAP_WIDTH)
CELLPOS(loc_3) = New Nods(loc_3, loc_1 + loc_4, loc_2 + loc_4)
loc_3 += 1
loc_4 += 1
End While
loc_2 = loc_2 - 1
loc_5 += 1
End While
For i As Integer = 0 To 559
Dim appli As Boolean = False
Dim _currentCell As CellData = currentMap.Cells(i)
If i = startId Then
appli = True
CELLPOS(i).closed = False
CELLPOS(i).started = True
CELLPOS(i).walkable = _currentCell.Mov
End If
If i = endId Then
appli = True
CELLPOS(i).closed = True
CELLPOS(i).started = False
CELLPOS(i).walkable = _currentCell.Mov
End If
If appli = False Then
CELLPOS(i).closed = False
CELLPOS(i).started = False
End If
CELLPOS(i).walkable = _currentCell.Mov
CELLPOS(i).calculH(CELLPOS(endId))
Next
Dim currentNode As Nods = CELLPOS(startId)
While finish_search = False
findNeighboringCell(currentNode, False)
currentNode = openList(0)
currentNode.inClosedList = True
currentNode.inOpenList = False
openList.RemoveAt(0)
End While
Dim currentCell As Nods = CELLPOS(endId)
Dim cells As New List(Of Integer)
While (currentCell.cellid = Not CELLPOS(startId).cellid)
cells.Add(currentCell.cellid)
currentCell = CELLPOS(currentCell.parent)
End While
cells.Add(startId)
Dim chemin As New List(Of Integer)
For reverse As Integer = cells.Count - 1 To -1
reverse -= 2
chemin.Add(cells(reverse))
Next
Return chemin
End Function
Sub initializeCurrentMap()
Dim reader As New MapManager("C:\Program Files (x86)\Dofus2\app\content\maps")
currentMap = reader.GetMap(MAPID)
End Sub
Sub findNeighboringCell(ByVal c_node As Nods, ByVal diagonal As Boolean)
addCell(getCellIdFromPoint(c_node.x(), c_node.y() + 1), c_node)
addCell(getCellIdFromPoint(c_node.x() - 1, c_node.y()), c_node)
addCell(getCellIdFromPoint(c_node.x() + 1, c_node.y()), c_node)
addCell(getCellIdFromPoint(c_node.x(), c_node.y() - 1), c_node)
If diagonal Then
addCell(getCellIdFromPoint(c_node.x() - 1, c_node.y() + 1), c_node)
addCell(getCellIdFromPoint(c_node.x() + 1, c_node.y() + 1), c_node)
addCell(getCellIdFromPoint(c_node.x() + 1, c_node.y() - 1), c_node)
addCell(getCellIdFromPoint(c_node.x() - 1, c_node.y() - 1), c_node)
End If
sortOpenList()
End Sub
Sub addCell(ByVal cell As Integer, ByVal c_node As Nods)
If CELLPOS(cell).walkable = True Then
If CELLPOS(cell).closed = True Then
CELLPOS(cell).parent = c_node.cellid
finish_search = True
End If
If CELLPOS(cell).inOpenList() = False & CELLPOS(cell).inClosedList() = False Then
CELLPOS(cell).parent = c_node.cellid
CELLPOS(cell).inOpenList = True
CELLPOS(cell).g = c_node.g() + 10
CELLPOS(cell).f = CELLPOS(cell).g + CELLPOS(cell).h()
openList.Add(CELLPOS(cell))
End If
End If
End Sub
Function getCellIdFromPoint(ByVal x As Integer, ByVal y As Integer)
Return (x - y) * MAP_WIDTH + y + (x - y) / 2
End Function
Sub sortOpenList()
Dim ok As Boolean = False
While (ok = False)
ok = True
Dim temp As Nods
For i As Integer = 0 To openList.Count - 1
If openList(i).f > openList(i + 1).f Then
temp = openList(i)
openList(i) = openList(i + 1)
openList(i + 1) = temp
ok = False
End If
Next
end while
End Sub
#End Region
End Class
La class node
Public Class Nods
#Region "declarations"
Dim m_x As Integer
Dim m_y As Integer
Dim m_cellid As Integer
Dim m_started As Boolean = False
Dim m_closed As Boolean = False
Dim m_fermer As Boolean = False
Dim m_walkable As Boolean
Dim m_parent As Integer
Dim n_inClosedList As Boolean
Dim n_inOpenList As Boolean
Dim m_h, m_f, m_g As Integer
#End Region
#Region "Fonctions public"
Sub New(ByVal cellid As Integer, ByVal x As Integer, ByVal y As Integer)
m_cellid = cellid
m_x = x
m_y = y
End Sub
Public Sub calculH(ByVal endNode As Nods)
m_h = 10 * (endNode.x - m_x) + (endNode.y - m_y)
End Sub
#End Region
#Region "Propriété"
Property h As Integer
Get
h = m_h
End Get
Set(value As Integer)
m_h = value
End Set
End Property
Property f As Integer
Get
f = m_f
End Get
Set(value As Integer)
m_f = value
End Set
End Property
Property g As Integer
Get
g = m_g
End Get
Set(value As Integer)
m_g = value
End Set
End Property
Property x As Integer
Get
x = m_x
End Get
Set(value As Integer)
m_x = value
End Set
End Property
Property y As Integer
Get
y = m_y
End Get
Set(value As Integer)
m_y = value
End Set
End Property
Property cellid As Integer
Get
cellid = m_cellid
End Get
Set(value As Integer)
m_cellid = value
End Set
End Property
Property started As Boolean
Get
started = m_started
End Get
Set(value As Boolean)
m_started = value
End Set
End Property
Property closed As Boolean
Get
closed = m_closed
End Get
Set(value As Boolean)
m_closed = value
End Set
End Property
Property fermer As Boolean
Get
fermer = m_fermer
End Get
Set(value As Boolean)
m_fermer = value
End Set
End Property
Property walkable As Boolean
Get
walkable = m_walkable
End Get
Set(value As Boolean)
m_walkable = value
End Set
End Property
Property parent As Integer
Get
parent = m_parent
End Get
Set(value As Integer)
m_parent = value
End Set
End Property
Property inClosedList As Boolean
Get
inClosedList = n_inClosedList
End Get
Set(value As Boolean)
n_inClosedList = value
End Set
End Property
Property inOpenList As Boolean
Get
inOpenList = n_inOpenList
End Get
Set(value As Boolean)
n_inOpenList = value
End Set
End Property
#End Region
End Class
pouriez vous me dire ce qui va pas ?