static List<CPos> MakeBidiPath(IPathSearch a, IPathSearch b, CPos confluenceNode) { var ca = a.Graph; var cb = b.Graph; var ret = new List<CPos>(); var q = confluenceNode; while (ca[q].PreviousPos != q) { ret.Add(q); q = ca[q].PreviousPos; } ret.Add(q); ret.Reverse(); q = confluenceNode; while (cb[q].PreviousPos != q) { q = cb[q].PreviousPos; ret.Add(q); } CheckSanePath(ret); return ret; }
// Searches from both ends toward each other. This is used to prevent blockings in case we find // units in the middle of the path that prevent us to continue. public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { List<CPos> path = null; while (fromSrc.CanExpand && fromDest.CanExpand) { // make some progress on the first search var p = fromSrc.Expand(); if (fromDest.Graph[p].Status == CellStatus.Closed && fromDest.Graph[p].CostSoFar < int.MaxValue) { path = MakeBidiPath(fromSrc, fromDest, p); break; } // make some progress on the second search var q = fromDest.Expand(); if (fromSrc.Graph[q].Status == CellStatus.Closed && fromSrc.Graph[q].CostSoFar < int.MaxValue) { path = MakeBidiPath(fromSrc, fromDest, q); break; } } fromSrc.Graph.Dispose(); fromDest.Graph.Dispose(); if (path != null) return path; return EmptyPath; }
public IMaybe <IPath> ExistingOrNewlyCalculatedPath(int[] numbers, Func <int[], IMaybe <IPath> > pathForNumbers) { IPathSearch pathSearch = _graphsWithPaths.FirstOrDefault(x => x.Numbers().SequenceEqual(numbers)); // TODO: get rid of "null" value usage if (pathSearch == null) { pathSearch = new PathSearch(numbers, pathForNumbers(numbers)); _graphsWithPaths.Add(pathSearch); } return(pathSearch.FoundPath()); }
// Searches from both ends toward each other. This is used to prevent blockings in case we find // units in the middle of the path that prevent us to continue. public List <CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { List <CPos> path = null; var dbg = world.WorldActor.TraitOrDefault <PathfinderDebugOverlay>(); if (dbg != null && dbg.Visible) { fromSrc.Debug = true; fromDest.Debug = true; } while (fromSrc.CanExpand && fromDest.CanExpand) { // make some progress on the first search var p = fromSrc.Expand(); if (fromDest.Graph[p].Status == CellStatus.Closed && fromDest.Graph[p].CostSoFar < int.MaxValue) { path = MakeBidiPath(fromSrc, fromDest, p); break; } // make some progress on the second search var q = fromDest.Expand(); if (fromSrc.Graph[q].Status == CellStatus.Closed && fromSrc.Graph[q].CostSoFar < int.MaxValue) { path = MakeBidiPath(fromSrc, fromDest, q); break; } } if (dbg != null && dbg.Visible) { dbg.AddLayer(fromSrc.Considered, fromSrc.MaxCost, fromSrc.Owner); dbg.AddLayer(fromDest.Considered, fromDest.MaxCost, fromDest.Owner); } fromSrc.Graph.Dispose(); fromDest.Graph.Dispose(); if (path != null) { return(path); } return(EmptyPath); }
// Searches from both ends toward each other. This is used to prevent blockings in case we find // units in the middle of the path that prevent us to continue. public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { List<CPos> path = null; var dbg = world.WorldActor.TraitOrDefault<PathfinderDebugOverlay>(); if (dbg != null && dbg.Visible) { fromSrc.Debug = true; fromDest.Debug = true; } while (!fromSrc.OpenQueue.Empty && !fromDest.OpenQueue.Empty) { // make some progress on the first search var p = fromSrc.Expand(); if (fromDest.Graph[p].Status == CellStatus.Closed && fromDest.Graph[p].CostSoFar < int.MaxValue) { path = MakeBidiPath(fromSrc, fromDest, p); break; } // make some progress on the second search var q = fromDest.Expand(); if (fromSrc.Graph[q].Status == CellStatus.Closed && fromSrc.Graph[q].CostSoFar < int.MaxValue) { path = MakeBidiPath(fromSrc, fromDest, q); break; } } if (dbg != null && dbg.Visible) { dbg.AddLayer(fromSrc.Considered, fromSrc.MaxCost, fromSrc.Owner); dbg.AddLayer(fromDest.Considered, fromDest.MaxCost, fromDest.Owner); } fromSrc.Graph.Dispose(); fromDest.Graph.Dispose(); if (path != null) return path; return EmptyPath; }
public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { using (new PerfSample("Pathfinder")) { var key = "FindBidiPath" + fromSrc.Id + fromDest.Id; var cachedPath = cacheStorage.Retrieve(key); if (cachedPath != null) return cachedPath; var pb = pathFinder.FindBidiPath(fromSrc, fromDest); cacheStorage.Store(key, pb); return pb; } }
public List<CPos> FindPath(IPathSearch search) { using (new PerfSample("Pathfinder")) { var key = "FindPath" + search.Id; var cachedPath = cacheStorage.Retrieve(key); if (cachedPath != null) return cachedPath; var pb = pathFinder.FindPath(search); cacheStorage.Store(key, pb); return pb; } }
public List <CPos> FindPath(IPathSearch search) { using (new PerfSample("Pathfinder")) { var key = "FindPath" + search.Id; var cachedPath = cacheStorage.Retrieve(key); if (cachedPath != null) { return(cachedPath); } var pb = pathFinder.FindPath(search); cacheStorage.Store(key, pb); return(pb); } }
public List <CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { using (new PerfSample("Pathfinder")) { var key = "FindBidiPath" + fromSrc.Id + fromDest.Id; var cachedPath = cacheStorage.Retrieve(key); if (cachedPath != null) { return(cachedPath); } var pb = pathFinder.FindBidiPath(fromSrc, fromDest); cacheStorage.Store(key, pb); return(pb); } }
public List<CPos> FindPath(IPathSearch search) { List<CPos> path = null; while (search.CanExpand) { var p = search.Expand(); if (search.IsTarget(p)) { path = MakePath(search.Graph, p); break; } } search.Graph.Dispose(); if (path != null) return path; // no path exists return EmptyPath; }
public List <CPos> FindPath(IPathSearch search) { var dbg = world.WorldActor.TraitOrDefault <PathfinderDebugOverlay>(); if (dbg != null && dbg.Visible) { search.Debug = true; } List <CPos> path = null; while (search.CanExpand) { var p = search.Expand(); if (search.IsTarget(p)) { path = MakePath(search.Graph, p); break; } } if (dbg != null && dbg.Visible) { dbg.AddLayer(search.Considered, search.MaxCost, search.Owner); } search.Graph.Dispose(); if (path != null) { return(path); } // no path exists return(EmptyPath); }
public List<CPos> FindPath(IPathSearch search) { using (new PerfSample("Pathfinder")) return pathFinder.FindPath(search); }
public List<CPos> FindPath(IPathSearch search) { var dbg = world.WorldActor.TraitOrDefault<PathfinderDebugOverlay>(); if (dbg != null && dbg.Visible) search.Debug = true; List<CPos> path = null; while (!search.OpenQueue.Empty) { var p = search.Expand(); if (search.IsTarget(p)) { path = MakePath(search.Graph, p); break; } } if (dbg != null && dbg.Visible) dbg.AddLayer(search.Considered, search.MaxCost, search.Owner); search.Graph.Dispose(); if (path != null) return path; // no path exists return EmptyPath; }
public List <CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { using (new PerfSample("Pathfinder")) return(pathFinder.FindBidiPath(fromSrc, fromDest)); }
public List <CPos> FindPath(IPathSearch search) { using (new PerfSample("Pathfinder")) return(pathFinder.FindPath(search)); }
public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest) { using (new PerfSample("Pathfinder")) return pathFinder.FindBidiPath(fromSrc, fromDest); }