X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmovegen.cpp;h=09bb95ab03d5d94fc200b7af7f27a5122e07ef27;hb=a9782b94e640d3a35b597758ff1d5f0e56465666;hp=297b51ffdeacb7e6d633be647d9e3da3a89ffc49;hpb=45ce92b89c9191f1606d82611620587157956e1b;p=stockfish diff --git a/src/movegen.cpp b/src/movegen.cpp index 297b51ff..09bb95ab 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -217,7 +217,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) while (b) { from = pop_1st_bit(&b); - switch (pos.type_of_piece_on(from)) + switch (type_of_piece(pos.piece_on(from))) { case PAWN: /* Will be generated togheter with pawns direct checks */ break; case KNIGHT: mlist = generate_discovered_checks(pos, mlist, from); break; @@ -267,17 +267,22 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { assert(pos.color_of_piece_on(checksq) == opposite_color(us)); - switch (pos.type_of_piece_on(checksq)) + switch (type_of_piece(pos.piece_on(checksq))) { case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break; case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break; case QUEEN: - // In case of a queen remove also squares attacked in the other direction to - // avoid possible illegal moves when queen and king are on adjacent squares. - if (RookPseudoAttacks[checksq] & (1ULL << ksq)) - sliderAttacks |= RookPseudoAttacks[checksq] | pos.attacks_from(checksq); + // If queen and king are far we can safely remove all the squares attacked + // in the other direction becuase are not reachable by the king anyway. + if (squares_between(ksq, checksq) || (RookPseudoAttacks[checksq] & (1ULL << ksq))) + sliderAttacks |= QueenPseudoAttacks[checksq]; + + // Otherwise, if king and queen are adjacent and on a diagonal line, we need to + // use real rook attacks to check if king is safe to move in the other direction. + // For example: king in B2, queen in A1 a knight in B1, and we can safely move to C1. else sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from(checksq); + default: break; } @@ -304,16 +309,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { } -/// generate computes a complete list of legal -/// or pseudo-legal moves in the current position. -template<> -MoveStack* generate(const Position& pos, MoveStack* mlist) { - - assert(pos.is_ok()); - - return pos.in_check() ? generate(pos, mlist) - : generate(pos, mlist); -} +/// generate computes a complete list of legal moves in the current position template<> MoveStack* generate(const Position& pos, MoveStack* mlist) { @@ -323,7 +319,8 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { MoveStack *last, *cur = mlist; Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); - last = generate(pos, mlist); + last = pos.in_check() ? generate(pos, mlist) + : generate(pos, mlist); // Remove illegal moves from the list while (cur != last)