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; }
private double Distance(Node one, Node two) { return Math.Sqrt(Math.Pow(two.X - one.X, 2) + Math.Pow(two.Y - one.Y, 2)); }
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(); }
public Astar(Node start, Node finish) { this.start = start; this.finish = finish; }
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)); }