Exemplo n.º 1
0
        /// <summary>
        /// Return the move in a SAN friendly format
        /// </summary>
        /// <returns>SAN engine-friendly format e.g. e2e4 or d7d8q, etc</returns>
        public override string ToString()
        {
            string result = String.Concat(startSquare.File.ToString(), startSquare.Rank.ToString(),
                                          endSquare.File.ToString(), endSquare.Rank.ToString());

            if (IsPromotion)
            {
                result = String.Concat(result, ChessGame.PieceClassToPromotionChar(promotionClass));
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts a new game if an engine is loaded
        /// </summary>
        private void NewGame(TypeGame typeofgame, string fen, PieceColor playerColor, int engineThinkTimeInMs)
        {
            if (fullPathToChessExe != null)
            {
                chessGame?.StopEngineSelfPlay();

                // Resize the form if needed
                Size gameSize = ChessGame.RequestedSize;
                ClientSize = gameSize;
                textBoxMoveHistory.Location = new Point(ClientSize.Width - ChessBoardView.MoveHistoryWidthInPixels - 25, 75);
                textBoxMoveHistory.Height   = ChessBoardView.BoardSizeInPixels / 2;
                textBoxMoveHistory.Width    = ChessBoardView.MoveHistoryWidthInPixels;
                textBoxMoveHistory.Font     = new Font("Segoe UI", 8);
                textBoxMoveHistory.Text     = String.Empty;

                // Old game is dead to us
                if (chessGame != null)
                {
                    chessGame.OnChessGameSelfPlayGameOver   -= ChessGameSelfPlayGameOverEventHandler;
                    chessGame.OnChessGameNormalPlayGameOver -= ChessGameNormalPlayGameOverEventHandler;
                }
                chessGame?.Dispose();

                // Now we have the engine path, so create an instance of the game class
                ChessEngineProcessLoader loader = new ChessEngineProcessLoader();
                chessGame = new ChessGame(view, fullPathToChessExe, loader, reduceEngineStrength, Thread.CurrentThread.CurrentCulture);
                chessGame.OnChessGameSelfPlayGameOver   += ChessGameSelfPlayGameOverEventHandler;
                chessGame.OnChessGameNormalPlayGameOver += ChessGameNormalPlayGameOverEventHandler;

                if (fen == String.Empty)
                {
                    chessGame.NewGame(typeofgame, playerColor, engineThinkTimeInMs);
                }
                else
                {
                    chessGame.NewPosition(typeofgame, playerColor, fen, engineThinkTimeInMs);
                }

                // Trigger Paint event (draws the initial board)
                Invalidate();
            }
            else
            {
                // No engine loaded, so no new game can be created.  Inform the user
                MessageBox.Show(this, Properties.Resources.ErrorNoEngineLoaded, Properties.Resources.ErrorTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }