public LoadEngine(Game game, MainForm mainForm) { this.Game = game; this.MainForm = mainForm; this.selectedEngine = this.Game.DefaultEngine; InitializeComponent(); }
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(); } }
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); } } } }
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(); }
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(); } }
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(); } }
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(); }
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(); } }
private void RunEngineCalculationForGivenTime(UCIEngine e, TimeSpan time) { e.SendGoInfinite(); Thread.Sleep(time); e.SendStop(); e.SendIsReady(); }
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(); } }
public void CloseEngine() { if (this.UciEngine != null) { this.UciEngine.Close(); this.UciEngine = null; } }
public void SetEngine(UCIEngine uciEngine) { if (EngineAnalysis != null) { EngineAnalysis.UnInit(); } EngineAnalysis = new EngineAnalysis(this.Game, uciEngine); }
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; } }
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); }
public void ChangeEngine(UCIEngine uciEngine) { if (EngineAnalysis == null) { return; } this.EngineAnalysis.UciEngine = uciEngine; InitEngine(); }
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); }
public void Init(string processFolder, string processName, bool reset = false) { if (reset) { Shutdown(); } paused = false; UCIEngine.Init(processFolder, processName); }
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); }
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); } }
public void Init(UCIEngine engine) { if (engine != null) { EngineFilePath = engine.EngineFile; if (engine.HasParametersLoaded) { this.EngineParameterData = engine.Parameters.EngineParameterData.Copy(); OnParametersLoaded(); } else { Init(EngineFilePath); } } }
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); } } }
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; } }
//[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(); }
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(); }
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(); } }
private void btnCancel_Click(object sender, EventArgs e) { selectedEngine = null; selectedBook = null; this.Close(); }
public EngineAnalysis(Game game, UCIEngine uciEngine) { this.Game = game; this.UciEngine = uciEngine; AnalysisItems = new Dictionary <string, string>(); }
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(); } }