public AStar(IEnumerable <IntVector3> initialLocations, IAStarTarget target) { this.MaxNodeCount = 200000; this.CancellationToken = CancellationToken.None; m_target = target; m_nodeMap = new Dictionary <IntVector3, AStarNode>(); m_openList = new BinaryHeap <AStarNode>(); foreach (var p in initialLocations) { ushort g = 0; ushort h = m_target.GetHeuristic(p); var node = new AStarNode(p, null); node.G = g; node.H = h; m_openList.Add(node); m_nodeMap.Add(p, node); } }
public AStar(IEnumerable<IntVector3> initialLocations, IAStarTarget target) { this.MaxNodeCount = 200000; this.CancellationToken = CancellationToken.None; m_target = target; m_nodeMap = new Dictionary<IntVector3, AStarNode>(); m_openList = new BinaryHeap<AStarNode>(); foreach (var p in initialLocations) { ushort g = 0; ushort h = m_target.GetHeuristic(p); var node = new AStarNode(p, null); node.G = g; node.H = h; m_openList.Add(node); m_nodeMap.Add(p, node); } }
void CheckNeighbors(AStarNode parent) { foreach (var dir in m_target.GetValidDirs(parent.Loc)) { IntVector3 childLoc = parent.Loc + dir; AStarNode child; m_nodeMap.TryGetValue(childLoc, out child); //if (child != null && child.Closed) // continue; ushort g = (ushort)(parent.G + m_target.GetCostBetween(parent.Loc, childLoc)); ushort h = m_target.GetHeuristic(childLoc); if (child == null) { child = new AStarNode(childLoc, parent); child.G = g; child.H = h; m_openList.Add(child); m_nodeMap.Add(childLoc, child); } else if (child.G > g) { child.Parent = parent; child.G = g; if (child.Closed == false) { m_openList.NodeUpdated(child); } else // Closed == true { UpdateParents(child); } } } }