public static Point FindStart(this IDijkstraMap dijkstra, Point end) { DijkstraTile dTile = dijkstra[end.X, end.Y]; while (dTile.Previous != null) { dTile = dTile.Previous; } return(dTile.Tile); }
private static IEnumerable <Point> FindPathInternal(IDijkstraMap dijkstra, Point end) { DijkstraTile dTile = dijkstra[end.X, end.Y]; while (dTile.Previous != null) { yield return(dTile.Tile); dTile = dTile.Previous; } }
public static Point?FindNextUnblockedMove(this IDijkstraMap dijkstra, IEnumerable <Point> nextPoints, Func <Point, bool> blocked) { nextPoints = nextPoints.OrderBy(p => dijkstra.GetCost(p)); foreach (var next in nextPoints) { if (!blocked(next)) { return(next); } } return(null); }
public static IEnumerable <Point> FindNextMoves(this IDijkstraMap dijkstra, Point start, DijkstraNeighbors neighbors) { double minDist = dijkstra.GetCost(start); foreach (var neighbor in neighbors(start)) { double dist = dijkstra.GetCost(neighbor); if (dist < minDist) { yield return(neighbor); } } }
public static IEnumerable <Point> FindEnds(this IDijkstraMap dijkstra, Func <Point, bool> predicate) { for (int x = 0; x < dijkstra.Width; x++) { for (int y = 0; y < dijkstra.Height; y++) { var dTile = dijkstra[x, y]; if (!double.IsInfinity(dTile.Distance) && predicate(dTile.Tile)) { yield return(dTile.Tile); } } } }
public static bool Reachable(this IDijkstraMap dijkstra, Point end) { DijkstraTile dTile = dijkstra[end.X, end.Y]; return(dTile.Previous != null); }
public static double GetCost(this IDijkstraMap dijkstra, Point end) { return(dijkstra[end.X, end.Y].Distance); }
public static IEnumerable <Point> FindPath(this IDijkstraMap dijkstra, Point end) { return(FindPathInternal(dijkstra, end).Reverse()); }