internal AStarResult(IDictionary<IntPoint3, AStarNode> nodes, AStarNode lastNode, AStarStatus status) { if (nodes == null) throw new ArgumentNullException(); this.Nodes = nodes; this.LastNode = lastNode; this.Status = status; }
public AStarNode(IntPoint3 l, AStarNode parent) { Loc = l; Parent = parent; }
void UpdateParents(AStarNode parent) { //Debug.Print("updating closed node {0}", parent.Loc); Stack<AStarNode> queue = new Stack<AStarNode>(); UpdateNodes(parent, queue); while (queue.Count > 0) { parent = queue.Pop(); UpdateNodes(parent, queue); } }
void UpdateNodes(AStarNode parent, Stack<AStarNode> queue) { foreach (var dir in m_environment.GetValidDirs(parent.Loc)) { IntPoint3 childLoc = parent.Loc + new IntVector3(dir); AStarNode child; m_nodeMap.TryGetValue(childLoc, out child); if (child == null) continue; ushort g = (ushort)(parent.G + CostBetweenNodes(parent.Loc, childLoc) + m_environment.GetTileWeight(childLoc)); if (g < child.G) { //Debug.Print("closed node {0} updated 1", childLoc); child.Parent = parent; child.G = g; queue.Push(child); } } }
void CheckNeighbors(AStarNode parent) { foreach (var dir in m_environment.GetValidDirs(parent.Loc)) { IntPoint3 childLoc = parent.Loc + new IntVector3(dir); AStarNode child; m_nodeMap.TryGetValue(childLoc, out child); //if (child != null && child.Closed) // continue; ushort g = (ushort)(parent.G + CostBetweenNodes(parent.Loc, childLoc) + m_environment.GetTileWeight(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; //Debug.Print("{0} update", child.Loc); if (child.Closed == false) m_openList.NodeUpdated(child); else // Closed == true UpdateParents(child); } } }
void AddInitialNodes() { var nodeMap = m_nodeMap; var openList = m_openList; IEnumerable<IntPoint3> nodeList; nodeList = m_srcPositioning.ToDirections().Select(d => m_src + d); foreach (var p in nodeList.Where(p => m_environment.CanEnter(p))) { ushort g = 0; ushort h = m_target.GetHeuristic(p); var node = new AStarNode(p, null); node.G = g; node.H = h; openList.Add(node); nodeMap.Add(p, node); } }