+/// Position::move_attacks_square() tests whether a move from the current
+/// position attacks a given square. Only attacks by the moving piece are
+/// considered; the function does not handle X-ray attacks.
+
+bool Position::move_attacks_square(Move m, Square s) const {
+
+ assert(move_is_ok(m));
+ assert(square_is_ok(s));
+
+ Square f = move_from(m), t = move_to(m);
+
+ assert(square_is_occupied(f));
+
+ switch (piece_on(f))
+ {
+ case WP: return pawn_attacks_square(WHITE, t, s);
+ case BP: return pawn_attacks_square(BLACK, t, s);
+ case WN: case BN: return piece_attacks_square<KNIGHT>(t, s);
+ case WB: case BB: return piece_attacks_square<BISHOP>(t, s);
+ case WR: case BR: return piece_attacks_square<ROOK>(t, s);
+ case WQ: case BQ: return piece_attacks_square<QUEEN>(t, s);
+ case WK: case BK: return piece_attacks_square<KING>(t, s);
+ default: assert(false);
+ }