// Castling
{
if (color == WHITE && !CBoard_square_isAttack(self, e1, BLACK)) {
if (color == WHITE) {
int index = Piece_index(&Pieces[WHITE][KING]);
if (self->castle & WK && !bit_get(occupancy, f1) &&
!bit_get(occupancy, g1)) {
MoveList_add(moves, Move_encode(e1, g1, index, 0, 0, 0, 0, 1));
if (self->castle & WK) {
if (!bit_get(occupancy, f1) && !bit_get(occupancy, g1))
if (!CBoard_square_isAttack(self, e1, BLACK) &&
!CBoard_square_isAttack(self, f1, BLACK))
MoveList_add(moves, Move_encode(e1, g1, index, 0, 0, 0, 0, 1));
}
if (self->castle & WQ && !bit_get(occupancy, b1) &&
!bit_get(occupancy, c1) && !bit_get(occupancy, d1)) {
MoveList_add(moves, Move_encode(e1, c1, index, 0, 0, 0, 0, 1));
if (self->castle & WQ) {
if (!bit_get(occupancy, d1) && !bit_get(occupancy, c1) &&
!bit_get(occupancy, b1))
if (!CBoard_square_isAttack(self, e1, BLACK) &&
!CBoard_square_isAttack(self, d1, BLACK))
MoveList_add(moves, Move_encode(e1, c1, index, 0, 0, 0, 0, 1));
}
}
if (color == BLACK && !CBoard_square_isAttack(self, e8, WHITE)) {
} else {
int index = Piece_index(&Pieces[BLACK][KING]);
if (self->castle & BK && !bit_get(occupancy, f8) &&
!bit_get(occupancy, g8)) {
MoveList_add(moves, Move_encode(e8, g8, index, 0, 0, 0, 0, 1));
if (self->castle & BK) {
if (!bit_get(occupancy, f8) && !bit_get(occupancy, g8))
if (!CBoard_square_isAttack(self, e8, WHITE) &&
!CBoard_square_isAttack(self, f8, WHITE))
MoveList_add(moves, Move_encode(e8, g8, index, 0, 0, 0, 0, 1));
}
if (self->castle & BQ && !bit_get(occupancy, b8) &&
!bit_get(occupancy, c8) && !bit_get(occupancy, d8)) {
MoveList_add(moves, Move_encode(e8, c8, index, 0, 0, 0, 0, 1));
if (self->castle & BQ) {
if (!bit_get(occupancy, d8) && !bit_get(occupancy, c8) &&
!bit_get(occupancy, b8))
if (!CBoard_square_isAttack(self, e8, WHITE) &&
!CBoard_square_isAttack(self, d8, WHITE))
MoveList_add(moves, Move_encode(e8, c8, index, 0, 0, 0, 0, 1));
}
}
}