Esempio n. 1
0
        /// <summary>
        /// Processes the go command.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private Task <GameEngineSearchResultCeres> ProcessGo(string command)
        {
            return(Task.Run(() =>
            {
                try
                {
                    SearchLimit searchLimit;

                    // Parse the search limit
                    searchLimit = GetSearchLimit(command);

                    GameEngineSearchResultCeres result = null;
                    if (searchLimit != null)
                    {
                        if (searchLimit.Value > 0)
                        {
                            // Run the actual search
                            result = RunSearch(searchLimit);
                        }
                    }

                    taskSearchCurrentlyExecuting = null;
                    return result;
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Exception in Ceres engine execution:");
                    Console.WriteLine(exc);
                    Console.WriteLine(exc.StackTrace);

                    System.Environment.Exit(3);
                    return null;
                }
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// Actually runs a search with specified limits.
        /// </summary>
        /// <param name="searchLimit"></param>
        /// <returns></returns>
        private GameEngineSearchResultCeres RunSearch(SearchLimit searchLimit)
        {
            DateTime lastInfoUpdate = DateTime.Now;

            int numUpdatesSent = 0;

            MCTSManager.MCTSProgressCallback callback =
                (manager) =>
            {
                curManager = manager;

                DateTime now = DateTime.Now;
                float    timeSinceLastUpdate = (float)(now - lastInfoUpdate).TotalSeconds;

                bool  isFirstUpdate           = numUpdatesSent == 0;
                float UPDATE_INTERVAL_SECONDS = isFirstUpdate ? 0.1f : 0.5f;
                if (curManager != null && timeSinceLastUpdate > UPDATE_INTERVAL_SECONDS && curManager.Root.N > 0)
                {
                    Send(UCIInfoString(curManager));

                    numUpdatesSent++;
                    lastInfoUpdate = now;
                }
            };

            GameEngineCeresInProcess.ProgressCallback callbackPlain = obj => callback((MCTSManager)obj);

            // use this? movesSinceNewGame

            // Search from this position (possibly with tree reuse)
            GameEngineSearchResultCeres result = CeresEngine.Search(curPositionAndMoves, searchLimit, gameMoveHistory, callbackPlain) as GameEngineSearchResultCeres;

            GameMoveStat moveStat = new GameMoveStat(gameMoveHistory.Count,
                                                     curPositionAndMoves.FinalPosition.MiscInfo.SideToMove,
                                                     result.ScoreQ, result.ScoreCentipawns,
                                                     float.NaN, //engine1.CumulativeSearchTimeSeconds,
                                                     curPositionAndMoves.FinalPosition.PieceCount,
                                                     result.MAvg, result.FinalN, result.FinalN - result.StartingN,
                                                     searchLimit,
                                                     (float)result.TimingStats.ElapsedTimeSecs);

            gameMoveHistory.Add(moveStat);

            if (SearchFinishedEvent != null)
            {
                SearchFinishedEvent(result.Search.Manager);
            }

            // Send the final info string (unless this was an instamove).
            Send(UCIInfoString(result.Search.Manager, result.Search.BestMoveRoot));

            // Send the best move
            Send("bestmove " + result.Search.BestMove.MoveStr(MGMoveNotationStyle.LC0Coordinate));
            if (debug)
            {
                Send("info string " + result.Search.BestMoveRoot.BestMoveInfo(false));
            }

            return(result);
        }