I don't have too much knowledge about bitboards and bit operations and I got some examples of bitboard chess engines from Github. And I like to know if anyone can help me with a problem.
How can I identify the exact piece that is attacking the king?
I got an example in the isKingInCheck function from position.js that just identifies when the king is attacked (even identifies if the piece is pawn, or bishop, etc.), but I need to know exactly the piece (position) that is attacking the king.
I believe that would be possible creating a generic attack mask function, like the function below. The problem is that I don't know how I get each piece (and its position during the game) individually from the pre-made bitboards, declared in the position.js file.
Chess.Position.makePawnAttackMask = function(color, pawns) {
var white = (color === Chess.PieceColor.WHITE);
var attacks1 = pawns.dup().and_not(Chess.Bitboard.FILES[0]).shiftLeft(white ? 7 : -9);
var attacks2 = pawns.dup().and_not(Chess.Bitboard.FILES[Chess.LAST_FILE]).shiftLeft(white ? 9 : -7);
return attacks1.or(attacks2);
};
Anyone know how can I achieve this?