Example #1
0
        /// <summary>
        /// Parses a specification of search time in UCI format into an equivalent SearchLimit.
        /// Returns null if parsing failed.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private SearchLimit GetSearchLimit(string command)
        {
            bool weAreWhite           = curPositionAndMoves.FinalPosition.MiscInfo.SideToMove == SideType.White;
            UCIGoCommandParsed goInfo = new UCIGoCommandParsed(command, weAreWhite);

            if (!goInfo.IsValid)
            {
                return(null);
            }

            if (goInfo.Nodes.HasValue)
            {
                return(SearchLimit.NodesPerMove(goInfo.Nodes.Value));
            }
            else if (goInfo.MoveTime.HasValue)
            {
                return(SearchLimit.SecondsPerMove(goInfo.MoveTime.Value / 1000.0f));
            }
            else if (goInfo.Infinite)
            {
                // TODO: determine a reasonable maximum value based on memory in computer
                return(SearchLimit.NodesPerMove(MCTSNodeStore.MAX_NODES));
            }
            else if (goInfo.TimeOurs.HasValue)
            {
                float increment = 0;
                if (goInfo.IncrementOurs.HasValue)
                {
                    increment = goInfo.IncrementOurs.Value / 1000.0f;
                }

                int?movesToGo = null;
                if (goInfo.MovesToGo.HasValue)
                {
                    movesToGo = goInfo.MovesToGo.Value;
                }

                return(SearchLimit.SecondsForAllMoves(goInfo.TimeOurs.Value / 1000.0f, increment, movesToGo, true));
            }
            else
            {
                Console.WriteLine($"Unsupported time control in UCI go command {command}");
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Parses a specification of search time in UCI format into an equivalent SearchLimit.
        /// Returns null if parsing failed.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        private SearchLimit GetSearchLimit(string command)
        {
            SearchLimit        searchLimit;
            bool               weAreWhite = curPositionAndMoves.FinalPosition.MiscInfo.SideToMove == SideType.White;
            UCIGoCommandParsed goInfo     = new UCIGoCommandParsed(command, weAreWhite);

            if (!goInfo.IsValid)
            {
                return(null);
            }

            if (goInfo.Nodes.HasValue)
            {
                searchLimit = SearchLimit.NodesPerMove(goInfo.Nodes.Value);
            }
            else if (goInfo.MoveTime.HasValue)
            {
                searchLimit = SearchLimit.SecondsPerMove(goInfo.MoveTime.Value / 1000.0f);
            }
            else if (goInfo.Infinite)
            {
                searchLimit = SearchLimit.NodesPerMove(MCTSNodeStore.MAX_NODES);
            }
            else if (goInfo.TimeOurs.HasValue)
            {
                float increment = 0;
                if (goInfo.IncrementOurs.HasValue)
                {
                    increment = goInfo.IncrementOurs.Value / 1000.0f;
                }

                int?movesToGo = null;
                if (goInfo.MovesToGo.HasValue)
                {
                    movesToGo = goInfo.MovesToGo.Value;
                }

                searchLimit = SearchLimit.SecondsForAllMoves(goInfo.TimeOurs.Value / 1000.0f, increment, movesToGo, true);
            }
            else if (goInfo.NodesOurs.HasValue)
            {
                float increment = 0;
                if (goInfo.IncrementOurs.HasValue)
                {
                    increment = goInfo.IncrementOurs.Value;
                }

                int?movesToGo = null;
                if (goInfo.MovesToGo.HasValue)
                {
                    movesToGo = goInfo.MovesToGo.Value;
                }

                searchLimit = SearchLimit.NodesForAllMoves(goInfo.NodesOurs.Value, (int)increment, movesToGo, true);
            }
            else
            {
                UCIWriteLine($"Unsupported time control in UCI go command {command}");
                return(null);
            }

            // Add on possible search moves restriction.
            return(searchLimit with {
                SearchMoves = goInfo.SearchMoves
            });
        }