I'm creating a chess engine using bitboards and I have a question about legal move generation. Here is what I came up with so far:
- Check if the king is in check
- If not, then generate all possible moves for all pieces
-Check each king move/en-passant/castling/absolute pin (if they result in check after the move is made, remove from list of legal moves)
-If no legal moves, then stalemate
-If in check, generate king moves, captures of piece giving check, or blocks
-Check each move (if they result in check after the move is made, remove from the list of legal moves)
-If no legal moves, then checkmate
I have 2 questions:
1) Is this an efficient way to generate a list of legal moves, or is there a better way?
2) Right now I plan to see if the white king is in check by seeing if the result of (white_king & black_attacks) is 0 or not. Is there a more efficient way to do this?
Thanks!