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

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