private void GenerateKnightMoves(List <Move> moves, Position position, ulong sourceSquares) { while (Bits.TryPopLsb(ref sourceSquares, out var sourceIx)) { var dstSquares = KnightMoveTable.GetMoves(sourceIx); dstSquares &= ~position.GetOccupied(position.SideToMove); GenerateMoves(moves, MoveType.Normal, PieceType.Knight, sourceIx, dstSquares, position.GetOccupied()); } }
// Note that this doesn't check if a pawn can be taken en passant public bool IsAttacked(int defenderIx, Color defenderColor) { // check in roughly descending order of power // rook and queen var potentialRookCaptures = RookMoveTable.GetMoves(defenderIx, GetOccupied()); if ((potentialRookCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Rook)) > 0) { return(true); } if ((potentialRookCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Queen)) > 0) { return(true); } // bishop and queen var potentialBishopCaptures = BishopMoveTable.GetMoves(defenderIx, GetOccupied()); if ((potentialBishopCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Bishop)) > 0) { return(true); } if ((potentialBishopCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Queen)) > 0) { return(true); } var potentialKnightCaptures = KnightMoveTable.GetMoves(defenderIx); if ((potentialKnightCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Knight)) > 0) { return(true); } var potentialKingCaptures = KingMoveTable.GetMoves(defenderIx); if ((potentialKingCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.King)) > 0) { return(true); } var potentialPawnCaptures = PawnCaptureMoveTable.GetMoves(defenderIx, defenderColor); if ((potentialPawnCaptures & GetPieceBitboard(defenderColor.Other(), PieceType.Pawn)) > 0) { return(true); } // we checked all possible attacks by all possible piece types return(false); }