Beispiel #1
0
        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);
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
 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);
 }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
0
 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);
             }
         }
     }
 }
Beispiel #6
0
        public static bool Reachable(this IDijkstraMap dijkstra, Point end)
        {
            DijkstraTile dTile = dijkstra[end.X, end.Y];

            return(dTile.Previous != null);
        }
Beispiel #7
0
 public static double GetCost(this IDijkstraMap dijkstra, Point end)
 {
     return(dijkstra[end.X, end.Y].Distance);
 }
Beispiel #8
0
 public static IEnumerable <Point> FindPath(this IDijkstraMap dijkstra, Point end)
 {
     return(FindPathInternal(dijkstra, end).Reverse());
 }