Beispiel #1
0
        /// <summary>
        /// Generates the move.
        /// Adds check verification to move generation,
        /// returns null if its own king will be in check.
        /// </summary>
        /// <param name="board">The board</param>
        /// <param name="from">The starting square</param>
        /// <param name="to">The ending square</param>
        /// <returns></returns>
        internal override Move GenerateMove(Board board, int from, int to)
        {
            Move move = base.GenerateMove(board, from, to);

            if (move != null)
            {
                // verify for king in check
                move.Make(board);
                bool result = !board.WhiteKingInCheck();
                move.TakeBack(board);
                return(result ? move : null);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates the move.
        /// Adds check verification to move generation,
        /// returns null if its own king will be in check.
        /// </summary>
        /// <param name="board">The board</param>
        /// <param name="from">The starting square</param>
        /// <param name="to">The ending square</param>
        /// <returns></returns>
        internal override Move GenerateMove(Board board, int from, int to)
        {
            Move move = base.GenerateMove(board, from, to);

            if (move != null)
            {
                move.IncrementMoves();// the number of moves is incremented after Black moves

                // verify for king in check
                move.Make(board);
                bool result = !board.BlackKingInCheck();
                move.TakeBack(board);
                return(result ? move : null);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Go to the previous board configuration in history.
        /// </summary>
        public void Previous()
        {
            // if the game is not at the begining
            if (!IsFirst)
            {
                Move move = moveHistory[currentBoardIndex - 1];

                // build the event args
                CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

                // raise the GoingBack event
                OnGoingBack(moveEventArgs);

                // if the operation was cancelled
                if (moveEventArgs.Cancel)
                {
                    return;
                }

                // remove the current board hash from the history
                RemoveHistoryHash();

                // take back the move
                move.TakeBack(currentBoard);

                // generate the possible moves
                GenerateMoves();

                // set the status of the game
                SetStatus();

                // decrement the current board index
                currentBoardIndex--;

                // raise the GoneBack event
                OnGoneBack(new MoveEventArgs(move, currentBoardIndex - 1));
            }
        }
        /// <summary>
        /// Takes back the move, it doesn't check if it's a valid move.
        /// </summary>
        /// <param name="board">The board</param>
        internal override void TakeBack(Board board)
        {
            rookMove.TakeBack(board); // take back the rook move first

            base.TakeBack(board);     // take back the king move last to set the before board status
        }