Exemplo n.º 1
0
        private void Debug(string p)
        {
            if (String.IsNullOrWhiteSpace(p))
            {
                Engine.SetDebug(false);
            }

            p = p.ToLower();
            Engine.SetDebug(UciUtils.ParseBool(p));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a struct containing the UciToEngine or UciToGui command and the argument string that follows it
        /// </summary>
        /// <typeparam name="T">Must be either UciToEngine or UciToGui</typeparam>
        /// <param name="command"></param>
        /// <returns></returns>
        private static Tuple <T?, string> GetCommand <T>(string command) where T : struct, IConvertible
        {
            Nullable <T> engineCommand;
            string       values = null;

            if (String.IsNullOrWhiteSpace(command))
            {
                return(null);
            }

            var parts = command.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length == 0)
            {
                return(null);
            }

            // search through the tokens, looking for a valid UCI command string
            engineCommand = null;
            int i = 0;

            while (i < parts.Length)
            {
                if (typeof(T) == typeof(UciToEngine))
                {
                    engineCommand = (Nullable <T>)(object) UciUtils.GetEnum <UciToEngine>(parts[i]);
                }
                else if (typeof(T) == typeof(UciToGui))
                {
                    engineCommand = (Nullable <T>)(object) UciUtils.GetEnum <UciToGui>(parts[i]);
                }
                else
                {
                    throw new Exception("Wrong argument type");
                }

                if (engineCommand != null)
                {
                    var indexOfCommand = command.IndexOf(parts[i]);
                    values = command.Substring(indexOfCommand + parts[i].Length).Trim();
                    break;
                }

                i++;
            }

            return(new Tuple <T?, string>(engineCommand, values));
        }