Exemplo n.º 1
0
        private List<Node> GetNeighbours(Node current)
        {
            List<Node> neighbours = new List<Node>();

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (x != 0 || y != 0)
                    {
                        Node node = new Node(current.X + x, current.Y + y);
                        neighbours.Add(node);
                    }
                }
            }
            return neighbours;
        }
Exemplo n.º 2
0
 private double Distance(Node one, Node two)
 {
     return Math.Sqrt(Math.Pow(two.X - one.X, 2) + Math.Pow(two.Y - one.Y, 2));
 }
Exemplo n.º 3
0
 private Node[] Path(Node destination, Node start)
 {
     LinkedList<Node> nodes = new LinkedList<Node>();
     Node node = destination;
     while (!start.Equals(destination))
     {
         nodes.AddFirst(new Node(node.X, node.Y));
         if (node.previous == null)
         {
             break;
         }
         node = node.previous;
     }
     return nodes.ToArray();
 }
Exemplo n.º 4
0
 public Astar(Node start, Node finish)
 {
     this.start = start;
     this.finish = finish;
 }
Exemplo n.º 5
0
        private double HeuristicCost(Node start, Node end)
        {
            double dx = start.X - end.X;
            double dy = start.Y - end.Y;

            return Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
        }