X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmovegen.cpp;h=be8753595f529500b755907f64a3e1e9375f4e22;hb=811037c8457fc46dba267e70192d3cd38676249f;hp=f38d42261ccfbdf827cdc5d9ad1c813f812a4aff;hpb=4dc7ba16191bd1ded7c8257afd2a3b9194cebca8;p=stockfish diff --git a/src/movegen.cpp b/src/movegen.cpp index f38d4226..be875359 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -272,12 +272,17 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { 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) @@ -451,7 +448,7 @@ namespace { // Single and double pawn pushes if (Type != MV_CAPTURE) { - b1 = pawnPushes & emptySquares; + b1 = (Type != MV_EVASION ? pawnPushes : pawnPushes & emptySquares); b2 = move_pawns(pawnPushes & TRank3BB) & emptySquares; if (Type == MV_CHECK)