Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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);
         }
     }
 }
Ejemplo n.º 3
0
 InnerFill(set, start, GetNeighbors, GetCost, costs, prevs);