X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=382073a7020dc2a1199cc9e5604b1d8d91c85048;hp=501674d6a283bf734f5d79d2d0e7e904fb1b2bb0;hb=c45818e9f86fea63a6b46d0726cdcfe87516d01b;hpb=2c955f25de9d4c263b6e6d37fef06b378eec49a0 diff --git a/src/position.cpp b/src/position.cpp index 501674d6..382073a7 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -399,12 +399,12 @@ Bitboard Position::attacks_to(Square s) const { /// Position::piece_attacks_square() tests whether the piece on square f /// attacks square t. -bool Position::piece_attacks_square(Square f, Square t) const { +bool Position::piece_attacks_square(Piece p, Square f, Square t) const { assert(square_is_ok(f)); assert(square_is_ok(t)); - switch (piece_on(f)) + switch (p) { case WP: return pawn_attacks_square(WHITE, f, t); case BP: return pawn_attacks_square(BLACK, f, t); @@ -427,24 +427,11 @@ bool Position::move_attacks_square(Move m, Square s) const { assert(move_is_ok(m)); assert(square_is_ok(s)); - bool is_attack; Square f = move_from(m), t = move_to(m); assert(square_is_occupied(f)); - switch (piece_on(f)) - { - case WP: is_attack = pawn_attacks_square(WHITE, t, s); break; - case BP: is_attack = pawn_attacks_square(BLACK, t, s); break; - case WN: case BN: is_attack = piece_attacks_square(t, s); break; - case WB: case BB: is_attack = piece_attacks_square(t, s); break; - case WR: case BR: is_attack = piece_attacks_square(t, s); break; - case WQ: case BQ: is_attack = piece_attacks_square(t, s); break; - case WK: case BK: is_attack = piece_attacks_square(t, s); break; - default: break; - } - - if (is_attack) + if (piece_attacks_square(piece_on(f), t, s)) return true; // Move the piece and scan for X-ray attacks behind it @@ -506,7 +493,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { Square ksq = king_square(us); assert(color_of_piece_on(from) == us); - assert(piece_on(ksq) == king_of_color(us)); + assert(piece_on(ksq) == piece_of_color_and_type(us, KING)); // En passant captures are a tricky special case. Because they are // rather uncommon, we do it simply by testing whether the king is attacked @@ -518,8 +505,8 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const { Bitboard b = occupied_squares(); assert(to == ep_square()); - assert(piece_on(from) == pawn_of_color(us)); - assert(piece_on(capsq) == pawn_of_color(them)); + assert(piece_on(from) == piece_of_color_and_type(us, PAWN)); + assert(piece_on(capsq) == piece_of_color_and_type(them, PAWN)); assert(piece_on(to) == EMPTY); clear_bit(&b, from); @@ -567,7 +554,7 @@ bool Position::move_is_check(Move m, Bitboard dcCandidates) const { Square ksq = king_square(them); assert(color_of_piece_on(from) == us); - assert(piece_on(ksq) == king_of_color(them)); + assert(piece_on(ksq) == piece_of_color_and_type(them, KING)); // Proceed according to the type of the moving piece switch (type_of_piece_on(from)) @@ -953,8 +940,8 @@ void Position::do_castle_move(Move m) { Square rfrom = move_to(m); // HACK: See comment at beginning of function Square kto, rto; - assert(piece_on(kfrom) == king_of_color(us)); - assert(piece_on(rfrom) == rook_of_color(us)); + assert(piece_on(kfrom) == piece_of_color_and_type(us, KING)); + assert(piece_on(rfrom) == piece_of_color_and_type(us, ROOK)); // Find destination squares for king and rook if (rfrom > kfrom) // O-O @@ -1052,7 +1039,7 @@ void Position::do_promotion_move(Move m, UndoInfo &u) { to = move_to(m); assert(relative_rank(us, to) == RANK_8); - assert(piece_on(from) == pawn_of_color(us)); + assert(piece_on(from) == piece_of_color_and_type(us, PAWN)); assert(color_of_piece_on(to) == them || square_is_empty(to)); capture = type_of_piece_on(to); @@ -1149,8 +1136,8 @@ void Position::do_ep_move(Move m) { assert(to == epSquare); assert(relative_rank(us, to) == RANK_6); assert(piece_on(to) == EMPTY); - assert(piece_on(from) == pawn_of_color(us)); - assert(piece_on(capsq) == pawn_of_color(them)); + assert(piece_on(from) == piece_of_color_and_type(us, PAWN)); + assert(piece_on(capsq) == piece_of_color_and_type(them, PAWN)); // Remove captured piece clear_bit(&(byColorBB[them]), capsq); @@ -1327,8 +1314,8 @@ void Position::undo_castle_move(Move m) { rto = relative_square(us, SQ_D1); } - assert(piece_on(kto) == king_of_color(us)); - assert(piece_on(rto) == rook_of_color(us)); + assert(piece_on(kto) == piece_of_color_and_type(us, KING)); + assert(piece_on(rto) == piece_of_color_and_type(us, ROOK)); // Remove pieces from destination squares clear_bit(&(byColorBB[us]), kto); @@ -1465,7 +1452,7 @@ void Position::undo_ep_move(Move m) { assert(to == ep_square()); assert(relative_rank(us, to) == RANK_6); - assert(piece_on(to) == pawn_of_color(us)); + assert(piece_on(to) == piece_of_color_and_type(us, PAWN)); assert(piece_on(from) == EMPTY); assert(piece_on(capsq) == EMPTY);