Beispiel #1
0
        /// <summary>
        /// Generates the move.
        /// </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;

            // if it's a castling move
            // CanCastleLong already verifies if the king will
            // end in check so we don't have to verify it again
            if (CanCastleLong(board, from, to))
            {
                move = new CastlingMove(board.Status, Board.E8, Board.C8, new Move(board.Status, Board.A8, Board.D8));

                move.ChangeSideToMove();              // change side to move
                move.MakeBlackLongCastlingUnavail();  // reset castling availability
                move.MakeBlackShortCastlingUnavail(); // reset castling availability
                move.SetEnPassantTarget(null);        // reset en passant target
                move.IncrementPly();                  // increment the ply
                move.IncrementMoves();                // the number of moves is incremented after Black moves

                return(move);
            }

            // if it's a castling move
            // CanCastleShort already verifies if the king will
            // end in check so we don't have to verify it again
            if (CanCastleShort(board, from, to))
            {
                move = new CastlingMove(board.Status, Board.E8, Board.G8, new Move(board.Status, Board.H8, Board.F8));

                move.ChangeSideToMove();              // change side to move
                move.MakeBlackLongCastlingUnavail();  // reset castling availability
                move.MakeBlackShortCastlingUnavail(); // reset castling availability
                move.SetEnPassantTarget(null);        // reset en passant target
                move.IncrementPly();                  // increment the ply
                move.IncrementMoves();                // the number of moves is incremented after Black moves

                return(move);
            }

            // if it's a regular move
            // just reset castling availability
            move = base.GenerateMove(board, from, to);
            if (move != null)
            {
                move.MakeBlackLongCastlingUnavail();
                move.MakeBlackShortCastlingUnavail();

                return(move);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates the move.
        /// </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;

            // if it's a castling move
            // CanCastleLong already verifies if the king will 
            // end in check so we don't have to verify it again
            if (CanCastleLong(board, from, to))
            {
                move = new CastlingMove(board.Status, Board.E1, Board.C1, new Move(board.Status, Board.A1, Board.D1));

                move.ChangeSideToMove();// change side to move 
                move.MakeWhiteLongCastlingUnavail();// reset castling availability
                move.MakeWhiteShortCastlingUnavail();// reset castling availability
                move.SetEnPassantTarget(null);// reset en passant target
                move.IncrementPly();// increment the ply

                return move;
            }

            // if it's a castling move
            // CanCastleShort already verifies if the king will 
            // end in check so we don't have to verify it again
            if (CanCastleShort(board, from, to))
            {
                move = new CastlingMove(board.Status, Board.E1, Board.G1, new Move(board.Status, Board.H1, Board.F1));

                move.ChangeSideToMove();// change side to move 
                move.MakeWhiteLongCastlingUnavail();// reset castling availability
                move.MakeWhiteShortCastlingUnavail();// reset castling availability
                move.SetEnPassantTarget(null);// reset en passant target
                move.IncrementPly();// increment the ply

                return move;
            }

            // if it's a regular move
            // just reset castling availability
            move = base.GenerateMove(board, from, to);
            if (move != null)
            {
                move.MakeWhiteLongCastlingUnavail();
                move.MakeWhiteShortCastlingUnavail();

                return move;
            }
            else
            {
                return null;
            }
        }