Exemplo n.º 1
0
 public LoadEngine(Game game, MainForm mainForm)
 {
     this.Game           = game;
     this.MainForm       = mainForm;
     this.selectedEngine = this.Game.DefaultEngine;
     InitializeComponent();
 }
Exemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstEngines.Items.Count > 0 && lstEngines.SelectedValue != null)
            {
                string engineFilePath = lstEngines.SelectedValue.ToString();
                int    hashTableSize  = (int)numHashTableSize.Value;

                if (selectedEngine != null)
                {
                    selectedEngine.Close();
                }

                selectedEngine = new UCIEngine(engineFilePath, hashTableSize, this.Game);
                if (engineParameters != null)
                {
                    engineParameters.SetEngineParameters(selectedEngine);
                }

                selectedEngine.UseTablebases = chkUseTablebases.Checked;
                selectedEngine.Load();
                selectedEngine.Close();

                if (selectedBook != null && selectedBook.BookOptions != null && selectedBook.BookOptions.UseBook)
                {
                    selectedBook.SetOptions(selectedBook.BookOptions);
                }
                else
                {
                    selectedBook = null;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemplo n.º 3
0
        private static void LoadUserEngine(Game game, int engineID, int chessTypeID, string bookFile)
        {
            DataSet dataset = SocketClient.GetSetIntruptedGameUserEngine(engineID, UserStatusE.Playing);

            if (dataset != null && dataset.Tables.Count > 0)
            {
                if (dataset.Tables[0] != null && dataset.Tables[0].Rows.Count > 0)
                {
                    App.Model.Db.Engine engine = new App.Model.Db.Engine(Ap.Cxt, dataset.Tables[0].Rows[0]);

                    InfinitySettings.EngineManager.EngineManager objEngineManager = new InfinitySettings.EngineManager.EngineManager();
                    List <InfinitySettings.EngineManager.Engine> lstEngine        = objEngineManager.LoadEngines();
                    InfinitySettings.EngineManager.Engine        eng = lstEngine.Where(x => x.IsActive == true && x.EngineTitle.Replace(".exe", "") == engine.Name).FirstOrDefault();

                    if (eng != null)
                    {
                        UCIEngine selectedEngine = new UCIEngine(eng.FilePath, Ap.EngineOptions.HashTableSize, game);

                        selectedEngine.Load();
                        selectedEngine.Close();

                        Ap.PlayingMode.SelectedEngine = selectedEngine;
                        Ap.PlayingMode.ChessTypeID    = chessTypeID;
                        Ap.PlayingMode.SelectedBook   = new Book(game, bookFile);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void LoadNewEngine()
        {
            if (!IsNewEngineSelected)
            {
                return;
            }

            EngineManager objEngineManager = new EngineManager();

            objEngineManager.SaveDefaultEngine(lstEngines.SelectedValue.ToString());

            int hashTableSize = Convert.ToInt32(cmbHashTableSize.SelectedValue);

            InfinitySettings.Settings.DefaultEngineXml = objEngineManager.LoadDefaultEngine();
            string engineFile = InfinitySettings.Settings.DefaultEngineXml.FilePath;

            selectedEngine = new UCIEngine(engineFile, hashTableSize, this.Game);
            if (engineParameters != null)
            {
                engineParameters.SetEngineParameters(selectedEngine);
            }

            UCIEngine oldEngine = this.Game.DefaultEngine;

            if (oldEngine != null)
            {
                oldEngine.Close();
            }
            selectedEngine.UseTablebases = chkUseTablebases.Checked;
            selectedEngine.Load();
        }
Exemplo n.º 5
0
        public void ChangeMainEngine(UCIEngine engine)
        {
            this.Game.DefaultEngine.Pause();
            this.Game.SwapPlayersIfNeeded();
            if (this.Game.IsDefaultEngine(engine))
            {
                this.Game.DefaultEngine.Resume();
                return;
            }

            this.Game.Clock.Stop();
            this.Game.PreviousPonderMove = "";
            this.Game.DefaultEngine.Close();
            this.Game.DefaultEngine = engine;
            AnalysisUc.ChangeEngine(engine);
            AnalysisUc.TabText = engine.EngineTitle;

            if (this.Game.GameMode == App.Model.GameMode.HumanVsEngine)
            {
                if (this.Game.CurrentPlayer.IsWhite)
                {
                    this.Game.Player2.Engine = this.Game.DefaultEngine;
                }
                else
                {
                    this.Game.Player1.Engine = this.Game.DefaultEngine;
                }

                ChessBoardUc.SetEvents();
                this.Game.GameData.Black1 = this.Game.DefaultEngine.EngineName;
                this.RefreshGameInfo();
            }
        }
Exemplo n.º 6
0
        private void btnDefineBlack_Click(object sender, EventArgs e)
        {
            InviteEngine frmInviteEngine;

            if (uciEngineBlack != null && bookBlack != null)
            {
                frmInviteEngine = new InviteEngine(uciEngineBlack, bookBlack, false, this.Game);
            }
            else
            {
                frmInviteEngine = new InviteEngine(false, this.Game);
            }

            if (frmInviteEngine.ShowDialog() == DialogResult.OK)
            {
                uciEngineBlack = frmInviteEngine.SelectedEngine;
                bookBlack      = frmInviteEngine.SelectedBook;

                Ap.EngineOptions.BlackEngine        = uciEngineBlack.EngineFile;
                Ap.EngineOptions.BlackUseTablebases = uciEngineBlack.UseTablebases;
                Ap.EngineOptions.BlackHashTableSize = uciEngineBlack.HashTableSize;
                Ap.EngineOptions.BlackBook          = "";

                if (bookBlack != null)
                {
                    Ap.EngineOptions.BlackBook = bookBlack.FilePath;
                }

                SetPlayersLabels();
            }
        }
Exemplo n.º 7
0
 private void LoadEngine()
 {
     uciEngine = new UCIEngine(EngineFilePath, Options.DefaultHashTableSize, this.Game);
     uciEngine.OptionReceived += new UCIEngine.OptionReceivedHandler(uciEngine_OptionReceived);
     uciEngine.UciOkReceived  += new EventHandler(uciEngine_UciOkReceived);
     uciEngine.Load();
 }
Exemplo n.º 8
0
        private void InitEngines()
        {
            if (uciEngineWhite == null && File.Exists(Ap.EngineOptions.WhiteEngine))
            {
                uciEngineWhite = new UCIEngine(Ap.EngineOptions.WhiteEngine, Ap.EngineOptions.HashTableSize, this.Game);
                uciEngineWhite.UseTablebases = Ap.EngineOptions.UseTablebases;
                uciEngineWhite.Load();
                uciEngineWhite.Close();
            }
            if (uciEngineBlack == null && File.Exists(Ap.EngineOptions.BlackEngine))
            {
                uciEngineBlack = new UCIEngine(Ap.EngineOptions.BlackEngine, Ap.EngineOptions.HashTableSize, this.Game);
                uciEngineBlack.UseTablebases = Ap.EngineOptions.UseTablebases;
                uciEngineBlack.Load();
                uciEngineBlack.Close();
            }

            if (bookWhite == null && File.Exists(Ap.EngineOptions.WhiteBook))
            {
                bookWhite = new Book(this.Game, Ap.EngineOptions.WhiteBook);
                bookWhite.BookOptions.OptionsType = BookOptionsType.WhiteEngine;
                bookWhite.SetOptions();
            }

            if (bookBlack == null && File.Exists(Ap.EngineOptions.BlackBook))
            {
                bookBlack = new Book(this.Game, Ap.EngineOptions.BlackBook);
                bookBlack.BookOptions.OptionsType = BookOptionsType.BlackEngine;
                bookBlack.SetOptions();
            }
        }
Exemplo n.º 9
0
 private void RunEngineCalculationForGivenTime(UCIEngine e, TimeSpan time)
 {
     e.SendGoInfinite();
     Thread.Sleep(time);
     e.SendStop();
     e.SendIsReady();
 }
Exemplo n.º 10
0
        private void btnDefineWhite_Click(object sender, EventArgs e)
        {
            InviteEngine frmInviteEngine;

            if (uciEngineWhite != null && bookWhite != null)
            {
                frmInviteEngine = new InviteEngine(uciEngineWhite, bookWhite, true, this.Game);
            }
            else
            {
                frmInviteEngine = new InviteEngine(true, this.Game);
            }

            if (frmInviteEngine.ShowDialog() == DialogResult.OK)
            {
                uciEngineWhite = frmInviteEngine.SelectedEngine;
                bookWhite      = frmInviteEngine.SelectedBook;

                Ap.EngineOptions.WhiteEngine        = uciEngineWhite.EngineFile;
                Ap.EngineOptions.WhiteUseTablebases = uciEngineWhite.UseTablebases;
                Ap.EngineOptions.WhiteHashTableSize = uciEngineWhite.HashTableSize;
                Ap.EngineOptions.WhiteBook          = "";

                if (bookWhite != null)
                {
                    Ap.EngineOptions.WhiteBook = bookWhite.FilePath;
                }

                SetPlayersLabels();
            }
        }
Exemplo n.º 11
0
 public void CloseEngine()
 {
     if (this.UciEngine != null)
     {
         this.UciEngine.Close();
         this.UciEngine = null;
     }
 }
Exemplo n.º 12
0
 public void SetEngine(UCIEngine uciEngine)
 {
     if (EngineAnalysis != null)
     {
         EngineAnalysis.UnInit();
     }
     EngineAnalysis = new EngineAnalysis(this.Game, uciEngine);
 }
Exemplo n.º 13
0
        private void AddKibitzer()
        {
            string    engineName    = lstEngines.SelectedValue.ToString();
            int       hashTableSize = Convert.ToInt32(cmbHashTableSize.SelectedValue);
            UCIEngine uciEngine     = new UCIEngine(engineName, hashTableSize, this.Game);

            uciEngine.IsKibitzer    = true;
            uciEngine.NameReceived += new UCIEngine.NameReceivedHandler(uciEngine_NameReceived);
            uciEngine.Load();
        }
 public EngineParametersPopup(UCIEngine engine, Game game)
 {
     InitializeComponent();
     this.Game      = game;
     this.UciEngine = engine;
     if (UciEngine != null)
     {
         this.engineFilePath = UciEngine.EngineFile;
     }
 }
Exemplo n.º 15
0
        private void btnDefineEngine_Click(object sender, EventArgs e)
        {
            InviteEngine frm = new InviteEngine(selectedEngine, selectedBook, true, this.Game);

            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                selectedEngine = frm.SelectedEngine;
                selectedBook   = frm.SelectedBook;
            }
        }
        public void MyTestInitialize()
        {
            var engineFile = new System.IO.FileInfo(_stockfishPath);

            if (!engineFile.Exists)
            {
                throw new System.IO.FileNotFoundException();
            }
            _engine = new UCIEngine(_stockfishPath, true);
        }
Exemplo n.º 17
0
        public void ChangeEngine(UCIEngine uciEngine)
        {
            if (EngineAnalysis == null)
            {
                return;
            }

            this.EngineAnalysis.UciEngine = uciEngine;
            InitEngine();
        }
Exemplo n.º 18
0
        public InviteEngine(UCIEngine uciEngine, Book book, bool isWhite, Game game)
        {
            InitializeComponent();

            this.Game           = game;
            this.selectedEngine = uciEngine;
            this.selectedBook   = book;
            this.isWhite        = isWhite;
            TournamentInfo      = new InfinityChess.TournamentManager.Tournament(this.Game);
        }
Exemplo n.º 19
0
    public void Init(string processFolder, string processName, bool reset = false)
    {
        if (reset)
        {
            Shutdown();
        }

        paused = false;

        UCIEngine.Init(processFolder, processName);
    }
Exemplo n.º 20
0
 public override void _PhysicsProcess(float delta)
 {
     if (!SFXPause && focused && !paused && UCIEngine.HasMove)
     {
         game.Call("make_ai_move", UCIEngine.Move, UCIEngine.Thinking == UCIEngine.ThinkingMode.Hint);
         UCIEngine.AcceptMove();
     }
     if (log.Count > 0)
     {
         var message = log.Dequeue();
         game.Call("send_to_ai_log", message.Str, message.Type);
     }
     base._PhysicsProcess(delta);
 }
Exemplo n.º 21
0
        void uciEngine_NameReceived(object sender, UCIMessageEventArgs e)
        {
            UCIEngine uciEngine = sender as UCIEngine;

            if (uciEngine != null)
            {
                InfinityChess.AnalysisUc analysisUc = new InfinityChess.AnalysisUc(true, this.Game, this.MainForm);
                analysisUc.Init();
                analysisUc.SetEngine(uciEngine);
                analysisUc.NewGame();
                analysisUc.KibitzerGuid = Guid.NewGuid().ToString();
                this.MainForm.KibitzerManager.KibitzersList.Add(analysisUc);
                this.MainForm.AddKibitzerPanel(analysisUc);
                this.MainForm.KibitzerManager.SendMoveToKibitzer(this.Game.CurrentMove);
            }
        }
Exemplo n.º 22
0
 public void Init(UCIEngine engine)
 {
     if (engine != null)
     {
         EngineFilePath = engine.EngineFile;
         if (engine.HasParametersLoaded)
         {
             this.EngineParameterData = engine.Parameters.EngineParameterData.Copy();
             OnParametersLoaded();
         }
         else
         {
             Init(EngineFilePath);
         }
     }
 }
Exemplo n.º 23
0
        public void SetEngineParameters(UCIEngine engine)
        {
            string parameterName  = string.Empty;
            string parameterValue = string.Empty;
            string defaultValue   = string.Empty;

            foreach (DataRow dr in EngineParameterData.Rows)
            {
                parameterName  = dr["Name"].ToString().Trim();
                parameterValue = dr["Value"].ToString().Trim();
                defaultValue   = dr["Default"].ToString().Trim();

                if (parameterValue != defaultValue)
                {
                    engine.SendOption(parameterName, parameterValue);
                }
            }
        }
Exemplo n.º 24
0
        private void PlayingMode_Load(object sender, EventArgs e)
        {
            if (Ap.SelectedRoomID == (int)RoomE.ComputerChess || Ap.SelectedRoomParentID == (int)RoomE.ComputerChess || Ap.SelectedRoomParentID == (int)RoomE.EngineTournaments)
            {
                rbComputer.Enabled      = true;
                rbCentaur.Enabled       = true;
                btnDefineEngine.Enabled = true;
            }

            if (PlayingModeData.Instance.ChessType == ChessTypeE.Engine)
            {
                rbComputer.Checked             = true;
                rbComputer.Enabled             = true;
                chkAutomaticChallenges.Checked = PlayingModeData.Instance.AutometicChallenges;
                chkAutometicAccepts.Checked    = PlayingModeData.Instance.AutometicAccepts;
                chkSendEvaluations.Checked     = PlayingModeData.Instance.SendEvaluations;
                chkSendExpectedMove.Checked    = PlayingModeData.Instance.SendExpectedMoves;
                numericUpDown1.Value           = PlayingModeData.Instance.Time;
            }
            else if (PlayingModeData.Instance.ChessType == ChessTypeE.Centaur)
            {
                rbCentaur.Checked = true;
            }
            else
            {
                rbHuman.Checked = true;
            }
            selectedEngine = Ap.PlayingMode.SelectedEngine;
            selectedBook   = Ap.PlayingMode.SelectedBook;

            if (Ap.IsGameInProgress)
            {
                rbHuman.Enabled             = false;
                rbComputer.Enabled          = false;
                rbCentaur.Enabled           = false;
                btnDefineEngine.Enabled     = false;
                numericUpDown1.Enabled      = false;
                numericUpDown2.Enabled      = false;
                chkSendEvaluations.Enabled  = false;
                chkSendExpectedMove.Enabled = false;
            }
        }
Exemplo n.º 25
0
        //[SetUp]
        public void Setup()
        {
            _startup    = new UCIEngineStartupArgs(Guid.NewGuid(), "mocked engine", "runMockEngine.exe");
            ProcessMock = new Mock <EngineProcess>(new UCIEngineMessageSubscriber(null));
            ProcessMock.Setup(x => x.Start()).Callback(() =>
            {
                IsStarted = true;
            }).Returns(true);

            ProcessMock.Setup(x => x.BeginErrorReadLine()).Callback(SetupErrorReadLine);
            ProcessMock.Setup(x => x.BeginOutputReadLine()).Callback(SetupOutputReadLine);
            ProcessMock.Setup(x => x.SetPriority(It.IsAny <ProcessPriorityClass>())).Callback <ProcessPriorityClass>(SetupSetPriority);
            ProcessMock.Setup(x => x.WaitForExit(It.IsAny <int>())).Returns(true);
            ProcessMock.SetupGet(x => x.ProcessId).Returns(420);

            Eng = new UCIEngine(_startup, Process);
            (ProcessMock.Object.MessageSubscriber as UCIEngineMessageSubscriber).EngineResponseCallback =
                Eng.ResponseReceived;
            Eng.DebugEventExecuted += (s, arg) =>
            {
                Console.WriteLine(arg.DebugText);
            };
            ProcessMock.Setup(s => s.Send(It.IsAny <CommandInfo>())).Callback <CommandInfo>(ci =>
            {
                var txt = ci.CommandText;
                if (txt == "uci")
                {
                    ProcessMock.Object.HandleMessageFromEngine("uciok");
                }
                if (txt == "isready")
                {
                    ProcessMock.Object.HandleMessageFromEngine("readyok");
                }
                if (txt == "quit")
                {
                    Process.Close();
                }
                LastCommand = txt;
            });
            EngineTask = Eng.StartAsync();
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            using (var stockfish = new UCIEngine(enginePath, false))
            {
                Console.WriteLine("Starting Stockfish engine");
                //  Get welcome response
                PrintResponse(stockfish.GetResponse());

                //  Send UCI command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.Uci())}");
                PrintResponse(stockfish.GetResponse());

                //  Send IsReady command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.IsReady())}");
                PrintResponse(stockfish.GetResponse());

                //  Send Position command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.Position(new List<string>() { "e2e4", "e7e5" }))}");

                //  Send Go command
                Console.WriteLine($"-> {stockfish.SendCommand(UCIQuery.Go(5000))}");

                //  Display Stockfish’s thinks
                while (true)
                {
                    var tokens = stockfish.GetResponse();
                    if (tokens.Count > 0)
                    {
                        PrintResponse(tokens);
                        if (tokens[tokens.Count - 1] is BestMove)
                        {
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("End of the demo.");
            Console.Read();
        }
Exemplo n.º 27
0
        public void TestStopDuringCalculationsOfRealEngine()
        {
            var startupArgs = new UCIEngineStartupArgs(Guid.NewGuid(), "StockFish", "stockfish_10_x64.exe");

            using (var engine = new UCIEngine(startupArgs))
            {
                //engine.DebugEventExecuted += (s, o) => { Console.WriteLine(o.ToString()); };
                EngineTask = engine.StartAsync();
                engine.SetOption("Debug Log File", "c:\\temp\\sf.log.txt");
                engine.DebugEventExecuted += (o, d) =>
                {
                    Console.WriteLine($"{d.ToString()}");
                };
                engine.EngineCalculationReceived += (s, o) =>
                {
                    var message = "";
                    if (o.ResponseObject == null)
                    {
                        Debug.WriteLine("****Calc Result Was Null****");
                    }
                    else if (o.ResponseObject.ResponseType == CalculationResponseTypes.BestMove)
                    {
                        var bm = o.ResponseObject as BestMoveResponse;
                        message = ($"Bestmove found: {bm.BestMove}. Pondering: {bm.PonderMove}");
                        engine.SendQuit();
                    }
                    else if (o.ResponseObject.ResponseType == CalculationResponseTypes.PrincipalVariation)
                    {
                        var pv = o.ResponseObject as PrincipalVariationResponse;
                        message = ($"Principal variation {pv.PVOrdinal} found, starting with {pv.Variation[0].SAN}.");
                    }
                    //Console.WriteLine(message);
                };
                engine.SetOption("MultiPV", "3");
                engine.SendPosition("rnbqkbnr/pppppppp/8/8/2P5/8/PP1PPPPP/RNBQKBNR b KQkq - 0 1");
                RunEngineCalculationForGivenTime(engine, TimeSpan.FromSeconds(10));
                EngineTask.Wait();
            }
        }
Exemplo n.º 28
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     selectedEngine = null;
     selectedBook   = null;
     this.Close();
 }
Exemplo n.º 29
0
 public EngineAnalysis(Game game, UCIEngine uciEngine)
 {
     this.Game      = game;
     this.UciEngine = uciEngine;
     AnalysisItems  = new Dictionary <string, string>();
 }
Exemplo n.º 30
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Ap.IsGameInProgress)
            {
                PlayingModeData.Instance.AutometicChallenges = chkAutomaticChallenges.Checked;
                PlayingModeData.Instance.AutometicAccepts    = chkAutometicAccepts.Checked;
                this.Close();
            }
            else
            {
                string      engineName = string.Empty;
                UserStatusE userStatus;
                if (rbHuman.Checked)
                {
                    if (selectedEngine != null)
                    {
                        selectedEngine.Close();
                        selectedEngine = null;
                    }

                    Ap.PlayingMode.ChessTypeID = 1;
                    PlayingModeData.Instance.AutometicChallenges = false;
                    PlayingModeData.Instance.AutometicAccepts    = false;
                    PlayingModeData.Instance.SendEvaluations     = false;
                    PlayingModeData.Instance.SendExpectedMoves   = false;
                    userStatus = UserStatusE.Blank;
                }
                else if (rbComputer.Checked)
                {
                    if (selectedEngine == null)
                    {
                        MessageForm.Show(this, MsgE.InfoUploadEngine);
                        return;
                    }
                    engineName = selectedEngine.EngineName;
                    Ap.PlayingMode.ChessTypeID = 2;
                    PlayingModeData.Instance.AutometicChallenges = chkAutomaticChallenges.Checked;
                    PlayingModeData.Instance.AutometicAccepts    = chkAutometicAccepts.Checked;
                    PlayingModeData.Instance.SendEvaluations     = chkSendEvaluations.Checked;
                    PlayingModeData.Instance.SendExpectedMoves   = chkSendExpectedMove.Checked;
                    PlayingModeData.Instance.Time        = UData.ToInt32(numericUpDown1.Value);
                    PlayingModeData.Instance.GainPerMove = UData.ToInt32(numericUpDown2.Value);
                    Ap.CurrentUser.UserStatusIDE         = userStatus = UserStatusE.Engine;
                    ChatClient.Write(ChatTypeE.OnlineClient, ChatMessageTypeE.Info, ChatTypeE.OnlineClient, "'" + engineName + "' loaded successfully", 0);
                }
                else
                {
                    Ap.PlayingMode.ChessTypeID = 3;
                    PlayingModeData.Instance.AutometicChallenges = false;
                    PlayingModeData.Instance.AutometicAccepts    = false;
                    PlayingModeData.Instance.SendEvaluations     = false;
                    PlayingModeData.Instance.SendExpectedMoves   = false;
                    Ap.CurrentUser.UserStatusIDE = userStatus = UserStatusE.Centaur;
                }

                SocketClient.SetUserEngine(engineName, userStatus);
                PlayingModeData.Instance.Pause       = Ap.CurrentUser.IsPause;
                PlayingModeData.Instance.ChessTypeID = Ap.PlayingMode.ChessTypeID;
                PlayingModeData.Instance.Save();
                Ap.PlayingMode.SelectedEngine = selectedEngine;
                Ap.PlayingMode.SelectedBook   = selectedBook;
                this.Close();
            }
        }