Example #1
0
        private void ResetGame()
        {
            try
            {
                croprect = Rectangle.Empty;
                mouseDown = false;
                isGetXEnabled = false;
                isGetYEnabled = false;
                //selectedChessEntity = null;
                desktop = IntPtr.Zero;
                chessDrawingRowIndex = -1;
                chessDrawingColumnIndex = -1;
                chessDrawingNextRowIndex = -1;
                chessDrawingNextColumnIndex = -1;
                IsComputingNextMove = false;
                nextMove = "-";
                masterTemplate = null;
                _engineDepth = "16";

                //castling reset
                ImageProcessingManager.KingCastleWhite = true;
                ImageProcessingManager.QueenCastleWhite = true;
                ImageProcessingManager.KingCastleBlack = true;
                ImageProcessingManager.QueenCastleBlack = true;

                rbtnBothWhiteCastling.Checked = true;
                rbtnWhiteKingCastling.Checked = false;
                rbtnWhiteQueenCastling.Checked = false;

                rbtnBothBlackCastling.Checked = true;
                rbtnBlackKingCastling.Checked = false;
                rbtnBlackQueenCastling.Checked = false;

                if (IsEngineRunning())
                {
                    //CurrentEngineSettings = new EngineConfigurationSettings();

                    //Engine = UCI.GetEngine();
                    //Engine.BestMovFound += engine_BestMovFound;
                    //Engine.InitEngine(Constants.STOCKFISHENGINE, string.Empty, Engine.OutputDataReceivedProc);
                    Engine.EngineCommand(UCI.kStopEngine);
                    Engine.EngineCommand(UCI.kResetEngine);
                }
                else
                {
                    Engine = UCI.GetEngine();
                    Engine.BestMovFound += engine_BestMovFound;
                    LoadEngineSettings();
                    Engine.InitEngine(Constants.STOCKFISHENGINE, string.Empty, Engine.OutputDataReceivedProc);
                    ApplyEngineSettings();
                    Engine.EngineCommand(UCI.kStopEngine);
                    Engine.EngineCommand(UCI.kResetEngine);
                }
            }
            catch (Exception exception)
            {
                LogHelper.logger.Error("ResetGame: " + exception.Message);
                LogHelper.logger.Error("ResetGame: " + exception.StackTrace);
                MessageBox.Show("An error occurred. Please restart bot", "Chessbot", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void btnLoadTemplate_Click(object sender, EventArgs e)
        {
            try
            {
                LogHelper.logger.Error("Testing error log");

                //LogHelper.logger.Info("btnLoadTemplate_Click called...");
                TemplateEntity selectedEntity = allLoadedTemplates[cmbTemplates.SelectedIndex];
                if (selectedEntity != null)
                {
                    //Console.WriteLine("Reading template " + selectedEntity.TemplateName);
                    masterTemplate = ImageProcessingManager.ReadTemplate(selectedEntity.TemplateFileName);
                    tbIntensity.Value = masterTemplate.Intensity;
                    txtIntensity.Text = tbIntensity.Value.ToString();
                    pbScreen.Image = masterTemplate.CurrentTemplateImage;
                    //MessageBox.Show("Template successfully loaded..", "Chess Master", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMessage.Text = "Template loaded successfully";
                    //Console.WriteLine("Reading template DONE!");
                    LoadUserTemplateSettings();
                }
            }
            catch (Exception exception)
            {
                LogHelper.logger.Error("btnLoadTemplate_Click: " + exception.Message);
                LogHelper.logger.Error("btnLoadTemplate_Click: " + exception.StackTrace);
                MessageBox.Show("An error occurred. Please restart bot", "Chessbot", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //LogHelper.logger.Info("btnLoadTemplate_Click finished...");
        }
 public static bool SaveTemplate(Image masterTemplateImage, string templateFileName, List<ChessPiece> masterTemplate, int intensity)
 {
     //LogHelper.logger.Info("SaveTemplate called...");
     bool result = true;
     try
     {
         using (System.IO.Stream stream = File.Open(templateFileName, FileMode.Create))
         {
             BinaryFormatter bin = new BinaryFormatter();
             //bin.Serialize(stream, masterTemplate);
             ChessTemplate template = new ChessTemplate();
             template.ChessConfiguration = masterTemplate;
             template.CurrentTemplateImage = masterTemplateImage;
             template.Intensity = intensity;
             bin.Serialize(stream, template);
         }
     }
     catch (Exception exception)
     {
         result = false;
         LogHelper.logger.Error("GetNextBestMove: " + exception.Message);
         LogHelper.logger.Error("GetNextBestMove: " + exception.StackTrace);
         MessageBox.Show("An error occurred. Please restart bot", "Chessbot", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     //LogHelper.logger.Info("SaveTemplate finished...");
     return result;
 }