private bool BreadthFirst(List <Position> end, List <Position> visited, IEnumerable <Position> excludedPoints, GetNeighbors getNeighbors) { List <Position> nodes = getNeighbors(visited.Last()); // Examine adjacent nodes for end goal if (nodes.Intersect(end).Any()) { return(true); } // in breadth-first, recursion needs to come after visiting adjacent nodes foreach (var node in nodes.Where(node => !excludedPoints.Contains(node) && !visited.Contains(node))) { visited.Add(node); if (BreadthFirst(end, visited, excludedPoints, getNeighbors)) { return(true); } } return(false); }
private void InitializeGrid() { gridPath = new Grid <PathTile <T> >(grid.Width, grid.Height); neighborsCallback = GetNeighborsCallback(gridPath); for (var x = 0; x < gridPath.Width; x++) { for (var y = 0; y < gridPath.Height; y++) { gridPath.Set(new PathTile <T>(grid, x, y), x, y); } } }
InnerFill(set, start, GetNeighbors, GetCost, costs, prevs);