Time for action – beginning the implementation of A*
Add a new module called
PathFinder
to the Robot Rampage project.Add declarations to the
PathFinder
module:#Region "Declarations" Private Enum NodeStatus Open Closed End Enum Private statusTracker As Dictionary(Of Vector2, NodeStatus) = New Dictionary(Of Vector2, NodeStatus)() Private Const CostStraight As Integer = 10 Private Const CostDiagonal As Integer = 15 Private openList As List(Of PathNode) = New List(Of PathNode)() Private costTracker As Dictionary(Of Vector2, Single) = New Dictionary(Of Vector2, Single)() #End Region
Add the
addNodeToOpenList()
method to thePathFinder
module:#Region "Helper Methods" Private Sub addNodeToOpenList(node As PathNode) Dim index As Integer = 0 Dim cost As Single = node.TotalCost Do While (openList.Count() > index) AndAlso (cost < openList(index).TotalCost) index += 1 Loop openList.Insert(index, node) costTracker(node.GridLocation) ...