X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.cpp;h=5b462c66879e42a06d42018dffda75ba2bc17231;hp=ef9a2727a5ac49f94b279652e222b5ee6c40a085;hb=1d1b7df7c6b3496d1a3fe926cadf25d91e1558f6;hpb=c9dcda6ac488c0058ebd567e1f52e30b8cd0db20 diff --git a/src/movegen.cpp b/src/movegen.cpp index ef9a2727..5b462c66 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -31,25 +31,27 @@ (mlist++)->move = make_move(to - (d), to); } namespace { - template - ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us) { + template + ExtMove* generate_castling(const Position& pos, ExtMove* mlist, Color us, const CheckInfo* ci) { - if (pos.castling_impeded(us, Side) || !pos.can_castle(make_castling_flag(us, Side))) + static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO); + + if (pos.castling_impeded(Cr) || !pos.can_castle(Cr)) return mlist; // After castling, the rook and king final positions are the same in Chess960 // as they would be in standard chess. Square kfrom = pos.king_square(us); - Square rfrom = pos.castling_rook_square(us, Side); - Square kto = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1); + Square rfrom = pos.castling_rook_square(Cr); + Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1); Bitboard enemies = pos.pieces(~us); assert(!pos.checkers()); - const int K = Chess960 ? kto > kfrom ? -1 : 1 - : Side == KING_SIDE ? -1 : 1; + const Square K = Chess960 ? kto > kfrom ? DELTA_W : DELTA_E + : KingSide ? DELTA_W : DELTA_E; - for (Square s = kto; s != kfrom; s += (Square)K) + for (Square s = kto; s != kfrom; s += K) if (pos.attackers_to(s) & enemies) return mlist; @@ -59,10 +61,12 @@ namespace { if (Chess960 && (attacks_bb(kto, pos.pieces() ^ rfrom) & pos.pieces(~us, ROOK, QUEEN))) return mlist; - (mlist++)->move = make(kfrom, rfrom); + Move m = make(kfrom, rfrom); + + if (Checks && !pos.gives_check(m, *ci)) + return mlist; - if (Checks && !pos.gives_check((mlist - 1)->move, CheckInfo(pos))) - --mlist; + (mlist++)->move = m; return mlist; } @@ -260,13 +264,13 @@ namespace { { if (pos.is_chess960()) { - mlist = generate_castling< KING_SIDE, Checks, true>(pos, mlist, Us); - mlist = generate_castling(pos, mlist, Us); + mlist = generate_castling::right, Checks, true>(pos, mlist, Us, ci); + mlist = generate_castling::right, Checks, true>(pos, mlist, Us, ci); } else { - mlist = generate_castling< KING_SIDE, Checks, false>(pos, mlist, Us); - mlist = generate_castling(pos, mlist, Us); + mlist = generate_castling::right, Checks, false>(pos, mlist, Us, ci); + mlist = generate_castling::right, Checks, false>(pos, mlist, Us, ci); } }