From: Fabian Fichter Date: Sat, 17 Jul 2021 19:37:39 +0000 (+0200) Subject: Merge official-stockfish/master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=519266052bc4adda510766864b6f108ce904ce79;p=fairystockfish.git Merge official-stockfish/master No functional change. --- 519266052bc4adda510766864b6f108ce904ce79 diff --cc src/movegen.cpp index 9a13a7a,bb81aea..6013b87 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@@ -315,84 -189,31 +315,85 @@@ namespace static_assert(Type != LEGAL, "Unsupported type in generate_all()"); constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantiations - const Square ksq = pos.square(Us); + const Square ksq = pos.count(Us) ? pos.square(Us) : SQ_NONE; Bitboard target; - if (Type == EVASIONS && more_than_one(pos.checkers() & ~pos.non_sliding_riders())) - goto kingMoves; // Double check, only a king move can save the day - - target = Type == EVASIONS ? between_bb(ksq, lsb(pos.checkers())) - : Type == NON_EVASIONS ? ~pos.pieces( Us) - : Type == CAPTURES ? pos.pieces(~Us) - : ~pos.pieces( ); // QUIETS || QUIET_CHECKS - - if (Type == EVASIONS) + // Skip generating non-king moves when in double check - if (Type != EVASIONS || !more_than_one(pos.checkers())) ++ if (Type != EVASIONS || !more_than_one(pos.checkers() & ~pos.non_sliding_riders())) { - if (pos.checkers() & pos.non_sliding_riders()) - target = ~pos.pieces(Us); - // Leaper attacks can not be blocked - Square checksq = lsb(pos.checkers()); - if (LeaperAttacks[~Us][type_of(pos.piece_on(checksq))][checksq] & pos.square(Us)) - target = pos.checkers(); - } + target = Type == EVASIONS ? between_bb(ksq, lsb(pos.checkers())) + : Type == NON_EVASIONS ? ~pos.pieces( Us) + : Type == CAPTURES ? pos.pieces(~Us) + : ~pos.pieces( ); // QUIETS || QUIET_CHECKS - target &= pos.board_bb(); - - moveList = generate_pawn_moves(pos, moveList, target); - for (PieceType pt : pos.piece_types()) - if (pt != PAWN && pt != KING) - moveList = generate_moves(pos, moveList, pt, target); - // generate drops - if (pos.piece_drops() && Type != CAPTURES && (pos.count_in_hand(Us, ALL_PIECES) > 0 || pos.two_boards())) - for (PieceType pt : pos.piece_types()) - moveList = generate_drops(pos, moveList, pt, target & ~pos.pieces(~Us)); ++ if (Type == EVASIONS) ++ { ++ if (pos.checkers() & pos.non_sliding_riders()) ++ target = ~pos.pieces(Us); ++ // Leaper attacks can not be blocked ++ Square checksq = lsb(pos.checkers()); ++ if (LeaperAttacks[~Us][type_of(pos.piece_on(checksq))][checksq] & pos.square(Us)) ++ target = pos.checkers(); ++ } + - // Castling with non-king piece - if (!pos.count(Us) && Type != CAPTURES && pos.can_castle(Us & ANY_CASTLING)) - { - Square from = pos.castling_king_square(Us); - for(CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } ) - if (!pos.castling_impeded(cr) && pos.can_castle(cr)) - moveList = make_move_and_gating(pos, moveList, Us, from, pos.castling_rook_square(cr)); - } ++ target &= pos.board_bb(); + - // Special moves - if (pos.cambodian_moves() && pos.gates(Us)) - { - if (Type != CAPTURES && Type != EVASIONS && (pos.pieces(Us, KING) & pos.gates(Us))) + moveList = generate_pawn_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); ++ for (PieceType pt : pos.piece_types()) ++ if (pt != PAWN && pt != KING) ++ moveList = generate_moves(pos, moveList, pt, target); ++ // generate drops ++ if (pos.piece_drops() && Type != CAPTURES && (pos.count_in_hand(Us, ALL_PIECES) > 0 || pos.two_boards())) ++ for (PieceType pt : pos.piece_types()) ++ moveList = generate_drops(pos, moveList, pt, target & ~pos.pieces(~Us)); ++ ++ // Castling with non-king piece ++ if (!pos.count(Us) && Type != CAPTURES && pos.can_castle(Us & ANY_CASTLING)) + { - Square from = pos.square(Us); - Bitboard b = PseudoAttacks[WHITE][KNIGHT][from] & rank_bb(rank_of(from + (Us == WHITE ? NORTH : SOUTH))) - & target & ~pos.pieces(); - while (b) - moveList = make_move_and_gating(pos, moveList, Us, from, pop_lsb(b)); ++ Square from = pos.castling_king_square(Us); ++ for(CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } ) ++ if (!pos.castling_impeded(cr) && pos.can_castle(cr)) ++ moveList = make_move_and_gating(pos, moveList, Us, from, pos.castling_rook_square(cr)); + } + - Bitboard b = pos.pieces(Us, FERS) & pos.gates(Us); - while (b) ++ // Special moves ++ if (pos.cambodian_moves() && pos.gates(Us)) + { - Square from = pop_lsb(b); - Square to = from + 2 * (Us == WHITE ? NORTH : SOUTH); - if (is_ok(to) && (target & to)) - moveList = make_move_and_gating(pos, moveList, Us, from, to); ++ if (Type != CAPTURES && Type != EVASIONS && (pos.pieces(Us, KING) & pos.gates(Us))) ++ { ++ Square from = pos.square(Us); ++ Bitboard b = PseudoAttacks[WHITE][KNIGHT][from] & rank_bb(rank_of(from + (Us == WHITE ? NORTH : SOUTH))) ++ & target & ~pos.pieces(); ++ while (b) ++ moveList = make_move_and_gating(pos, moveList, Us, from, pop_lsb(b)); ++ } ++ ++ Bitboard b = pos.pieces(Us, FERS) & pos.gates(Us); ++ while (b) ++ { ++ Square from = pop_lsb(b); ++ Square to = from + 2 * (Us == WHITE ? NORTH : SOUTH); ++ if (is_ok(to) && (target & to)) ++ moveList = make_move_and_gating(pos, moveList, Us, from, to); ++ } + } - } + - // Workaround for passing: Execute a non-move with any piece - if (pos.pass() && !pos.count(Us) && pos.pieces(Us)) - *moveList++ = make(lsb(pos.pieces(Us)), lsb(pos.pieces(Us))); ++ // Workaround for passing: Execute a non-move with any piece ++ if (pos.pass() && !pos.count(Us) && pos.pieces(Us)) ++ *moveList++ = make(lsb(pos.pieces(Us)), lsb(pos.pieces(Us))); + } - if (!Checks || pos.blockers_for_king(~Us) & ksq) - { - Bitboard b = attacks_bb(ksq) & (Type == EVASIONS ? ~pos.pieces(Us) : target); - if (Checks) - b &= ~attacks_bb(pos.square(~Us)); - kingMoves: ++ // King moves + if (pos.count(Us) && (!Checks || pos.blockers_for_king(~Us) & ksq)) + { + Bitboard b = ( (pos.attacks_from(Us, KING, ksq) & pos.pieces()) + | (pos.moves_from(Us, KING, ksq) & ~pos.pieces())) & (Type == EVASIONS ? ~pos.pieces(Us) : target); while (b) - *moveList++ = make_move(ksq, pop_lsb(b)); + moveList = make_move_and_gating(pos, moveList, Us, ksq, pop_lsb(b)); + + // Passing move by king + if (pos.pass()) + *moveList++ = make(ksq, ksq); if ((Type == QUIETS || Type == NON_EVASIONS) && pos.can_castle(Us & ANY_CASTLING)) for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )