X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.cpp;h=be848cf1a6acb370e1ddf262b4f79762ba187f56;hp=0b46298b9c80f9ca770e88766d4b6d74d20f1fa3;hb=55df3fa2d7631ed67e46f9433aa7f3a71c18e5e7;hpb=1598a3edf851460a62a06493416554e1f7cf719c diff --git a/src/movegen.cpp b/src/movegen.cpp index 0b46298b..be848cf1 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -31,7 +31,7 @@ (*mlist++).move = make_move(to - (d), to); } namespace { - template + template MoveStack* generate_castle(const Position& pos, MoveStack* mlist, Color us) { if (pos.castle_impeded(us, Side) || !pos.can_castle(make_castle_right(us, Side))) @@ -46,16 +46,18 @@ namespace { assert(!pos.in_check()); - for (Square s = kto; s != kfrom; s += (Square)(Side == KING_SIDE ? -1 : 1)) + const int K = Chess960 ? kto > kfrom ? -1 : 1 + : Side == KING_SIDE ? -1 : 1; + + for (Square s = kto; s != kfrom; s += (Square)K) if (pos.attackers_to(s) & enemies) return mlist; // Because we generate only legal castling moves we need to verify that // when moving the castling rook we do not discover some hidden checker. // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1. - if ( pos.is_chess960() - && (pos.attackers_to(kto, pos.pieces() ^ rfrom) & enemies)) - return mlist; + if (Chess960 && (pos.attackers_to(kto, pos.pieces() ^ rfrom) & enemies)) + return mlist; (*mlist++).move = make(kfrom, rfrom); @@ -273,8 +275,16 @@ namespace { if (Type != CAPTURES && Type != EVASIONS && pos.can_castle(us)) { - mlist = generate_castle(pos, mlist, us); - mlist = generate_castle(pos, mlist, us); + if (pos.is_chess960()) + { + mlist = generate_castle(pos, mlist, us); + mlist = generate_castle(pos, mlist, us); + } + else + { + mlist = generate_castle(pos, mlist, us); + mlist = generate_castle(pos, mlist, us); + } } return mlist; @@ -420,11 +430,13 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { MoveStack *end, *cur = mlist; Bitboard pinned = pos.pinned_pieces(); + Square ksq = pos.king_square(pos.side_to_move()); end = pos.in_check() ? generate(pos, mlist) : generate(pos, mlist); while (cur != end) - if (!pos.pl_move_is_legal(cur->move, pinned)) + if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT) + && !pos.pl_move_is_legal(cur->move, pinned)) cur->move = (--end)->move; else cur++;