예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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;
            }
        }
예제 #6
0
        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;
            }
        }
예제 #7
0
        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();
        }
예제 #8
0
        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;
            }
        }
예제 #9
0
        /// <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));
        }