示例#1
0
 private bool DFS(Node node)
 {
     node.Handler();
     if (node == goal)
     {
         return(true);
     }
     visited.Add(node);
     foreach (var child in node.Children.Where(x => !visited.Contains(x)))
     {
         if (DFS(child))
         {
             path.AddFirst(child);
             return(true);
         }
     }
     return(false);
 }
 private bool DFS(Node node)
 {
     node.Handler();
     if (node == goal)
     {
         return true;
     }
     visited.Add(node);
     foreach (var child in node.Children.Where(x => !visited.Contains(x)))
     {
         if (DFS(child))
         {
             path.AddFirst(child);
             return true;
         }
     }
     return false;
 }
示例#3
0
 private bool DLS(Node node, int limit)
 {
     node.Handler();
     if (node == goal)
     {
         return(true);
     }
     if (limit == 0)
     {
         limitWasReached = false;
         return(false);
     }
     visited.Add(node);
     foreach (var child in node.Children.Where(x => !visited.Contains(x)))
     {
         if (DLS(child, limit - 1))
         {
             path.AddFirst(child);
             return(true);
         }
     }
     return(false);
 }
 private bool DLS(Node node, int limit)
 {
     node.Handler();
     if (node == goal)
     {
         return true;
     }
     if (limit == 0)
     {
         limitWasReached = false;
         return false;
     }
     visited.Add(node);
     foreach (var child in node.Children.Where(x => !visited.Contains(x)))
     {
         if (DLS(child, limit - 1))
         {
             path.AddFirst(child);
             return true;
         }
     }
     return false;
 }