Esempio n. 1
0
 public PathNode(double gCost, double hCost, int node, PathNode parent)
 {
     Parent = parent;
     this.node = node;
     this.gCost = gCost;
     this.hCost = hCost;
 }
Esempio n. 2
0
 private float Distance(PathNode p1, int p2)
 {
     return Nodes[p1.node].position.Distance(Nodes[p2].position);
 }
Esempio n. 3
0
 private float Distance(PathNode p1, int p2)
 {
     return(Nodes[p1.node].position.Distance(Nodes[p2].position));
 }
Esempio n. 4
0
        private PathNode FindPath(int startNode, int endNode)
        {
            if (startNode == -1 || endNode == -1) return null;
            List<PathNode> open=new List<PathNode>();
            List<PathNode> closed = new List<PathNode>();
            open.Add(new PathNode(0, Nodes[startNode].GetDistance(endNode), startNode, null));


            while (open.Count > 0)
            {
                PathNode q = open.OrderBy(n => n.fCost).First();
                open.Remove(q);
                foreach (int neighbor in Nodes[q.node].Neighbors)
                {
                    if (!Nodes[neighbor].passable)
                        continue;
                    PathNode s=new PathNode(q.gCost+
                        Distance(q, neighbor) * (Nodes[neighbor].position.GetNearestTurret().Distance(Nodes[neighbor].position)<900?20:1)
                        
                        
                        ,Distance(endNode, neighbor), neighbor, q );
                    if (neighbor == endNode)
                    {
                        return s;
                    }
                    PathNode sameNodeOpen = open.FirstOrDefault(el => el.node == neighbor);
                    if (sameNodeOpen != null)
                    {
                        if(sameNodeOpen.fCost<s.fCost) continue;
                    }
                    PathNode sameNodeClosed = closed.FirstOrDefault(el => el.node == neighbor);
                    if (sameNodeClosed != null)
                    {
                        if(sameNodeClosed.fCost<s.fCost) continue;
                    }
                    open.Add(s);
                }
                closed.Add(q);
            }
            return null;

        }