Example #1
0
        /// <summary>
        /// Converts a state based move to a ChessBoard move
        /// </summary>
        /// <param name="stateMove">The move the convert</param>
        /// <param name="playerColor">The color of hte player</param>
        /// <returns>The move corrected to work with ChessBoard</returns>
        public static ChessMove GetGameMove(ChessMove stateMove, ChessColor playerColor)
        {
            if (stateMove == null)
                return null;

            ChessMove gameMove = stateMove.Clone();

            if (playerColor == ChessColor.White)
            {
                gameMove.From.X = Columns - gameMove.From.X - 1;
                gameMove.From.Y = Rows - gameMove.From.Y - 1;
                gameMove.To.X = Columns - gameMove.To.X - 1;
                gameMove.To.Y = Rows - gameMove.To.Y - 1;
            }

            return gameMove;
        }
Example #2
0
        /// <summary>
        /// Validates a move. The framework uses this to validate the opponents move.
        /// </summary>
        /// <param name="currentBoard">The board as it currently is.</param>
        /// <param name="moveToCheck">This is the move that needs to be checked to see if it's valid.</param>
        /// <param name="colorOfPlayerMoving">This is the color of the player who's making the move.</param>
        /// <returns>Returns true if the move was valid</returns>
        public bool?IsValidMove(ChessBoard currentBoard, ChessMove moveToCheck)
        {
            _moveToReturn      = null;
            _isGetNextMoveCall = false;
            _isValidMove       = false;

            if (this.IsHuman)
            {
                // Humans don't check the AI's moves, so just always return true
                return(true);
            }

            _currentBoard = currentBoard.Clone();
            _moveToCheck  = moveToCheck.Clone();
            StartAiInTimedThread(UvsChess.Gui.Preferences.CheckMoveTimeout);
            if ((_moveToReturn != null) && (_moveToReturn.Flag == ChessFlag.AIWentOverTime))
            {
                // The AI Went over time while validating the move. Signal ChessGame of this.
                return(null);
            }

            return(_isValidMove);
        }
Example #3
0
        /// <summary>
        /// Validates a move. The framework uses this to validate the opponents move.
        /// </summary>
        /// <param name="currentBoard">The board as it currently is.</param>
        /// <param name="moveToCheck">This is the move that needs to be checked to see if it's valid.</param>
        /// <param name="colorOfPlayerMoving">This is the color of the player who's making the move.</param>
        /// <returns>Returns true if the move was valid</returns>
        public bool? IsValidMove(ChessBoard currentBoard, ChessMove moveToCheck)
        {
            _moveToReturn = null;
            _isGetNextMoveCall = false;
            _isValidMove = false;

            if (this.IsHuman)
            {
                // Humans don't check the AI's moves, so just always return true
                return true;
            }

            _currentBoard = currentBoard.Clone();
            _moveToCheck = moveToCheck.Clone();
            StartAiInTimedThread(UvsChess.Gui.Preferences.CheckMoveTimeout);
            if ((_moveToReturn != null) && (_moveToReturn.Flag == ChessFlag.AIWentOverTime))
            {
                // The AI Went over time while validating the move. Signal ChessGame of this.
                return null;
            }

            return _isValidMove;
        }