/// <summary> /// Moves the the given piece in the bitboards. May want to consider moving all of /// the movePiece logic into the ChessPosition.removePiece function. This routine /// basically mimics the ChessBitboard.removePiece and ChessBitboard.addPiece so maybe /// simply call those routines to to simplify the logic. Currenty only being done /// for a small optimization gain. /// </summary> /// <param name="piece">Piece we are deleting, note that the ChessPostion /// class ignores the color of the piece as basically it is color blind.</param> /// <param name="square"></param> /// <param name="Pieces">Current bitboards to update.</param> public void movePiece(Chess.Pieces piece, BitboardSquare from, BitboardSquare to) { // Move the piece. removePiece(piece, from.getSquareMask()); addPiece(piece, to.getSquareMask()); // Remove any prevoious Enpasant. Enpasant = 0x00; // See if this move puts a pawn in danger of Enpasant if (piece == Chess.Pieces.BPAWN || piece == Chess.Pieces.WPAWN) { if (isPotentialEnpasant(from.getSquareMask(), to.getSquareMask())) { // Set square of pawn susceptible to enpasant attack. Enpasant = to.getSquareMask(); } } Board = (Board & (~from.getSquareMask())) | to.getSquareMask(); // Update attacker rotated boards: Bitboard maskFrom = from.getA8H1Mask(); // getBitSquare(coFrom.A8H1Square); Bitboard maskTo = to.getA8H1Mask(); //getBitSquare(coTo.A8H1Square); RotatedA8H1 = (RotatedA8H1 & (~maskFrom)) | maskTo; maskFrom = from.getA1H8Mask(); //getBitSquare(coFrom.A1H8Square); maskTo = to.getA1H8Mask(); //getBitSquare(coTo.A1H8Square); RotatedA1H8 = (RotatedA1H8 & (~maskFrom)) | maskTo; maskFrom = from.getR90Mask(); //getBitSquare(coFrom.R90Square); maskTo = to.getR90Mask(); //getBitSquare(coTo.R90Square); RotatedR90 = (RotatedR90 & (~maskFrom)) | maskTo; }
/// <summary> /// Adds the given piece to the bitboards. May want to consider moving all of /// the addPiece logic into the ChessPosition.removePiece function. /// </summary> /// <param name="piece">Piece we are deleting, note that the ChessPostion /// class ignores the color of the piece as basically it is color blind.</param> /// <param name="Pieces">Current bitboards to update.</param> public void addPiece(Chess.Pieces piece, BitboardSquare to) { // Add the piece to the piece board. addPiece(piece, to.getSquareMask()); // Update main board. Board = Board | to.getSquareMask(); // Update rotated boards: Bitboard maskTo = to.getA8H1Mask(); // getBitSquare(coTo.A8H1Square); RotatedA8H1 = RotatedA8H1 | maskTo; maskTo = to.getA1H8Mask(); // getBitSquare(coTo.A1H8Square); RotatedA1H8 = RotatedA1H8 | maskTo; maskTo = to.getR90Mask(); // getBitSquare(coTo.R90Square); RotatedR90 = RotatedR90 | maskTo; }
/// <summary> /// Removes the given piece from the bitboards. May want to consider moving all of /// the removePiece logic into the ChessPosition.removePiece function. /// </summary> /// <param name="piece">Piece we are deleting, note that the ChessPostion /// class ignores the color of the piece as basically it is color blind.</param> /// <param name="square"></param> /// <param name="Pieces"></param> public void removePiece(Chess.Pieces piece, BitboardSquare square) { // Get the squares. // BitboardSquare bbSquare = new BitboardSquare(square); Bitboard mask = square.getSquareMask(); // getBitSquare(bbSquare.Square); removePiece(piece, mask); Board = Board & ~mask; // Update rotated boards: mask = square.getA8H1Mask(); // getBitSquare(bbSquare.A8H1Square); RotatedA8H1 = RotatedA8H1 & ~mask; mask = square.getA1H8Mask(); // getBitSquare(bbSquare.A1H8Square); RotatedA1H8 = RotatedA1H8 & ~mask; mask = square.getR90Mask(); // getBitSquare(bbSquare.R90Square); RotatedR90 = RotatedR90 & ~mask; }