- for(s = Min(ksq, c1); s <= Max(ksq, c1); s++)
- if((s != ksq && s != rsq && pos.square_is_occupied(s))
- || pos.square_is_attacked(s, them))
- illegal = true;
- for(s = Min(rsq, d1); s <= Max(rsq, d1); s++)
- if(s != ksq && s != rsq && pos.square_is_occupied(s))
+ if (!illegal)
+ mlist[n++].move = make_castle_move(ksq, rsq);
+ }
+
+ if (pos.can_castle_queenside(us))
+ {
+ Square rsq = pos.initial_qr_square(us);
+ Square c1 = relative_square(us, SQ_C1);
+ Square d1 = relative_square(us, SQ_D1);
+ Square s;
+ bool illegal = false;
+
+ assert(pos.piece_on(rsq) == rook_of_color(us));
+
+ for (s = Min(ksq, c1); s <= Max(ksq, c1); s++)
+ if ( (s != ksq && s != rsq && pos.square_is_occupied(s))
+ || pos.square_is_attacked(s, them))
+ illegal = true;
+
+ for (s = Min(rsq, d1); s <= Max(rsq, d1); s++)
+ if (s != ksq && s != rsq && pos.square_is_occupied(s))
+ illegal = true;
+
+ if ( square_file(rsq) == FILE_B
+ && ( pos.piece_on(relative_square(us, SQ_A1)) == rook_of_color(them)
+ || pos.piece_on(relative_square(us, SQ_A1)) == queen_of_color(them)))