/// <summary> /// Gets the distance between two points /// </summary> internal static float GetTraversalCost(Point location, Point otherLocation) { float deltaX = otherLocation.X - location.X; float deltaY = otherLocation.Y - location.Y; return((float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY)); }
/// <summary> /// Creates a new instance of Node. /// </summary> /// <param name="x">The node's location along the X axis</param> /// <param name="y">The node's location along the Y axis</param> /// <param name="isWalkable">True if the node can be traversed, false if the node is a wall</param> /// <param name="endLocation">The location of the destination node</param> public Node(int x, int y, bool isWalkable, Point endLocation) { this.Location = new Point(x, y); this.State = NodeState.Untested; this.IsWalkable = isWalkable; this.H = GetTraversalCost(this.Location, endLocation); this.G = 0; }
/// <summary> /// Returns the eight locations immediately adjacent (orthogonally and diagonally) to <paramref name="fromLocation"/> /// </summary> /// <param name="fromLocation">The location from which to return all adjacent points</param> /// <returns>The locations as an IEnumerable of Points</returns> private static IEnumerable <Point> GetAdjacentLocations(Point fromLocation) { return(new Point[] { // new Point(fromLocation.X-1, fromLocation.Y-1), new Point(fromLocation.X - 1, fromLocation.Y), // new Point(fromLocation.X-1, fromLocation.Y+1), new Point(fromLocation.X, fromLocation.Y + 1), // new Point(fromLocation.X+1, fromLocation.Y+1), new Point(fromLocation.X + 1, fromLocation.Y), // new Point(fromLocation.X+1, fromLocation.Y-1), new Point(fromLocation.X, fromLocation.Y - 1) }); }
public SearchParameters(Point startLocation, Point endLocation, bool[,] map) { this.StartLocation = startLocation; this.EndLocation = endLocation; this.Map = map; }