public void RunUntil(int timeOut, bool earlyTimeOut) { DateTime lEndTime = DateTime.Now.AddSeconds(timeOut); while (true) { SearchStatus lSearchStatus = GetStatus(); SearchStatusType lSearchStatusType = lSearchStatus.Status; if ((lSearchStatusType == SearchStatusType.Completed) || (lSearchStatusType == SearchStatusType.Stopped)) { return; } // if it very unlike that another result will return in the remaining time, stop researching, so the time can be used later if (earlyTimeOut) { if ((lSearchStatusType == SearchStatusType.Thinking) && (lSearchStatus.BestMoveUpdate.Add(lSearchStatus.BestMoveUpdateTimeLapse).AddSeconds(-1) > lEndTime)) { Console.Error.WriteLine("Early Time Out:"); Console.Error.WriteLine("Saved: " + (lEndTime - DateTime.Now).Seconds.ToString() + " Seconds"); return; } } if (DateTime.Now > lEndTime) { return; } lock (SearchInterface) { Monitor.Wait(SearchInterface, 250); } } }
public void StartThinking() { try { GoThink(); } catch (AbortedSearchException lException) { int lLevels = lException.StackTrace.Length; // dummy status to avoid unused variable warning message } lock (this) { SearchStatus.Timer.Stop(); if (Status == SearchStatusType.Stopping) { Status = SearchStatusType.Stopped; } else { Status = SearchStatusType.Completed; } UpdateStatus(); // and again } NotifyAll(); }
public bool RequestStop() { if (SearchInterface == null) { return(true); } SearchStatusType lStatus = SearchInterface.GetStatus().Status; if ((lStatus == SearchStatusType.Completed) || (lStatus == SearchStatusType.Stopped)) { return(true); } // harmless if already stopped (method does not block) SearchInterface.StopThinking(); return(false); }
public void StopThinking() { lock (this) { // check is search has completed or been stopped if ((Status == SearchStatusType.Completed) || (Status == SearchStatusType.Stopped)) { UpdateStatus(); NotifyAll(); return; } // change status to stopping Status = SearchStatusType.Stopping; // set flag to stop thinking StopThinkingFlag = true; // get another update UpdateStatusFlag = true; } }
public void Initialize(GoBoard goBoard, Color playerToMove, SearchOptions searchOptions, OnCompletion onCompletion) { lock (this) { SearchStatus = new SearchStatus(); SearchStatus.BoardSize = goBoard.BoardSize; Status = SearchStatusType.Thinking; UpdateStatus(); UpdateStatusFlag = true; StopThinkingFlag = false; SearchOptions = searchOptions.Clone(); NodesSearched = NodesEvaluated = 0; CheckSuperKo = searchOptions.CheckSuperKo; OnCompletion = onCompletion; SearchInterface.Initialize(goBoard, SearchOptions); Board = goBoard; PlayerToMove = playerToMove; } }
public void StartThinking() { try { GoThink(); } catch (AbortedSearchException lException) { int lLevels = lException.StackTrace.Length; // dummy status to avoid unused variable warning message } lock (this) { SearchStatus.Timer.Stop(); if (Status == SearchStatusType.Stopping) Status = SearchStatusType.Stopped; else Status = SearchStatusType.Completed; UpdateStatus(); // and again } NotifyAll(); }
/// <summary> /// Search for text in the specified index /// </summary> /// <param name="database">Database id</param> /// <param name="language">Language</param> /// <param name="text">Text to search for</param> /// <returns></returns> public List <SearchResultItem> Search(string database, string language, string text, out SearchStatusType status, string filter = "", int resultListLength = 250) { Searcher searcher = GetSearcher(database, language); if (searcher == null) { // Return empty list status = SearchStatusType.NotIndexed; return(new List <SearchResultItem>()); } status = SearchStatusType.Successful; return(searcher.Search(text, filter, resultListLength)); }