示例#1
0
        /// <summary>
        /// Create a new ChessGame object
        /// </summary>
        /// <param name="engineView">IChessBoardView to use</param>
        /// <param name="fullPathToEngine">Full path the chess engine exe</param>
        /// <param name="engineLoader">object to load engine given path</param>
        /// <param name="reduceEngineStrength">true to make the engine weaker</param>
        /// <param name="cultureInfo">CultureInfo for main form</param>
        public ChessGame(IChessBoardView engineView, string fullPathToEngine,
                         IChessEngineProcessLoader engineLoader, bool reduceEngineStrength, CultureInfo cultureInfo)
        {
            // Save the view
            view = engineView;

            // Save culture for this thread
            currentCultureInfo = cultureInfo;
            Thread.CurrentThread.CurrentCulture   = currentCultureInfo;
            Thread.CurrentThread.CurrentUICulture = currentCultureInfo;

            ThinkingLocalized = Properties.Resources.Thinking;

            // Create legal move list
            legalMoves    = new List <BoardSquare>();
            selectedPiece = null;

            // Create the board, the view, and the engine
            // Create new UCI engine object
            engine = new UCIChessEngine(engineLoader);

            // Subscribe to events from the engine (commands and verbose)
            engine.OnChessEngineResponseReceived      += ChessEngineResponseReceivedEventHandler;
            engine.OnChessEngineVerboseOutputReceived += ChessEngineVerboseOutputReceivedEventHandler;

            // This will launch the process
            engine.LoadEngine(fullPathToEngine);

            // Start UCI
            engine.InitializeUciProtocol();

            // Initialize the chess engine with optional parameters
            // Note this is engine dependent and this version only works with stockfish (to my knowledge)
            // Other UCI engines use different options, several a combination of UCI_LimitStrength and UCI_ELO
            // Eventually this will need to be handled in some options dialog that will either
            // be customizable per engine, or provide a standard way to select things like play strength and time
            if (reduceEngineStrength)
            {
                string exeName = Path.GetFileName(fullPathToEngine);
                exeName = exeName.ToLower();
                string gimpedElo = String.Empty;

                //No Options listed (when tested at console)
                //===================
                //SOS 5 Arena
                //Anmon 5.75
                //Hermann28_32
                //Ruffian 105

                if (exeName.StartsWith("stockfish_8"))
                {
                    UciSetOptionCommand command = new UciSetOptionCommand("Skill Level", "0");
                    command.Execute(engine);
                }
                else if (exeName.StartsWith("rybkav2.3.2a"))
                {
                    gimpedElo = "1200";
                }
                else if (exeName.StartsWith("spike1.4"))
                {
                    gimpedElo = "1300";
                }
                //MadChess
                //option name UCI_LimitStrength type check default false
                //option name UCI_Elo type spin default 400 min 400 max 2200
                // Removed because it seems to take forever to return once this is
                // set with the engine.  The same behavior at the console, so
                // ignore it here

                if (gimpedElo != String.Empty)
                {
                    UciSetOptionCommand reduceEloCommand = new UciSetOptionCommand("UCI_LimitStrength", "true");
                    reduceEloCommand.Execute(engine);

                    UciSetOptionCommand setEloRating = new UciSetOptionCommand("UCI_Elo", gimpedElo);
                    setEloRating.Execute(engine);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Sets a given option name with a value (if provided)
        /// </summary>
        /// <param name="optionName">engine dependent option name</param>
        /// <param name="optionValue">option dependent value</param>
        public void SetOption(string optionName, string optionValue = null)
        {
            UciSetOptionCommand command = new UciSetOptionCommand(optionName, optionValue);

            command.Execute(this);
        }