Fastest way to generate castling moves in a computer chess engine I am currently developing a Bitboard chess engine using C++. I am in the process of creating the move generator function. I have completed most of it and only the casting part is left.
I have used Magic Bitboards for sliding pieces and precalculated the attacks for other pieces. I am trying to make everything Highly efficient, by avoiding too many if-statements. The part I am stuck at is castling. The most naive method would be to use a few if-statements for checking whether the squares are empty and castling is still available. But this wouldn't be efficient at all.
What would be the fastest method to generate castle-moves?
It's been a long time since I've made any efficiency mods, but this can be reduced to one if statement, but many would be easier to read.
if
!bitboard_occupied  // easy to find by ORing with f1/g1 (or queenside)

!bitboard_attacked | [square e1/f1/g1 (or queenside)  // attacked already known

!bitboard_moved | (h1 (or a1) &amp; e1)

Updating the moved bitboards would be more costly to maintain during each move and undo than the extra if statements in the relatively rare castling routine.