예제 #1
0
 /// <summary>
 /// Continues the search started by <see cref="StartSearch"/> until either the next result is found or no result exists.
 /// </summary>
 /// <returns>A <see cref="SearchResult"/> indicating the result of the search.</returns>
 public SearchResult ContinueSearch()
 {
     if (!_searchStarted)
     {
         return(null);
     }
     // as long as nodes exist in the open list
     while (_openList.Any())
     {
         // take the first one and expand it
         var node = _openList[0];
         _openList.Remove(node);
         _closedList.Add(node);
         // check for final node
         if (_searchProblem.IsFinalState(node.State))
         {
             return(new SearchResult(node));
         }
         // iterate through transitions
         foreach (var transition in _searchProblem.GetTransitions(node.State))
         {
             // transition brings us to state on the closed list --> no need to investigate this anymore
             if (_closedList.Any(n => n.State == transition.NewState))
             {
                 continue;
             }
             // create child node
             var newNode = CreateNodeFromTransition(node, transition);
             InsertNodeIntoOpenList(newNode);
         }
         SortOpenList();
     }
     return(new SearchResult(null));
 }